Skip to main content

Towards Type Inference for JavaScript

  • Conference paper
ECOOP 2005 - Object-Oriented Programming (ECOOP 2005)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 3586))

Included in the following conference series:

Abstract

Object-oriented scripting languages like Javascript and Python are popular partly because of their dynamic features. These include the runtime modification of objects and classes through addition of fields or updating of methods. These features make static typing difficult and so usually dynamic typing is used. Consequently, errors such as access to non-existent members are not detected until runtime.

We first develop a formalism for an object based language, JS0 with features from Javascript, including dynamic addition of fields and updating of methods. We give an operational semantics and static type system for JS0using structural types. Our types allow objects to evolve in a controlled manner by classifying members as definite or potential.

We define a type inference algorithm for JS0 that is sound with respect to the type system. If the type inference algorithm succeeds, then the program is typeable. Therefore, programmers can benefit from the safety offered by the type system, without the need to write explicitly types in their programs.

Work partly supported by EU within the FET – Global Computing initiative, project DART IST-2001-33477,MURST Cofin’02 project McTati, and MIUR Prin’04 project EOS.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 84.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 109.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Abadi, M., Cardelli, L.: A Theory of Objects. Springer, New York (1996)

    MATH  Google Scholar 

  2. Agesen, O.: The Cartesian Product Algorithm: Simple and Precise Type Inference of Parametric Polymorphism. In: Olthoff, W. (ed.) ECOOP 1995. LNCS, vol. 952, pp. 2–26. Springer, Heidelberg (1995)

    Google Scholar 

  3. Agesen, O., Palsberg, J., Schwartzbach, M.I.: Type inference of SELF: Analysis of objects with dynamic and multiple inheritance. Softw., Pract. Exper. 25(9), 975–995 (1995)

    Article  Google Scholar 

  4. Amadio, R.M., Cardelli, L.: Subtyping recursive types. ACM Transactions on Programming Languages and Systems 15(4), 575–631 (1993)

    Article  Google Scholar 

  5. Anderson, C., Barbanera, F., Dezani-Ciancaglini, M., Drossopoulou, S.: Can addresses be types (a case study: objects with delegation). In: WOOD 2003. ENTCS, vol. 82. Elsevier, Amsterdam (2003)

    Google Scholar 

  6. Anderson, C., Giannini, P.: Type checking for javascript. In: WOOD 2004. WOOD of ENTCS. Elsevier, Amsterdam (2004), http://www.binarylord.com/work/js0wood.pdf

    Google Scholar 

  7. Bono, V., Fisher, K.: An Imperative, First-Order Calculus with Object Extension. In: Jul, E. (ed.) ECOOP 1998. LNCS, vol. 1445, pp. 462–497. Springer, Heidelberg (1998)

    Chapter  Google Scholar 

  8. Bruce, K., Schuett, A., van Gent, R.: PolyTOIL: A type-safe polymorphic object-oriented language. In: Olthoff, W. (ed.) ECOOP 1995. LNCS, vol. 952, pp. 27–51. Springer, Heidelberg (1995)

    Google Scholar 

  9. Damiani, F., Giannini, P.: Alias types for environment aware computations. In: WOOD 2003. ENTCS, vol. 82. Elsevier, Amsterdam (2003)

    Google Scholar 

  10. Eifrig, J., Smith, S.F., Trifonov, V.: Sound polymorphic type inference for objects. In: Proc. Object-Oriented Programming Systems, Languages, and Applications (OOPSLA 1995), pp. 169–184. ACM Press, New York (1995)

    Chapter  Google Scholar 

  11. Le Hors, A., et al.: Document Object Model (DOM) Level 3 Core Specification. Technical report (1998), http://www.w3.org/TR/2003/CR-DOM-Level-3-Core-20031107

  12. Agesen, O., et al.: The SELF 4.0 Programmer’s Reference Manual (1995), http://research.sun.com/self/

  13. Fisher, K.: Type Systems for Object-Oriented Programming Languages. PhD thesis, Stanford University, Available as Stanford Computer Science Technical Report number STAN-CS-TR-98-1602 (1996)

    Google Scholar 

  14. Fisher, K., Honsell, F., Mitchell, J.C.: A Lambda Calculus of Objects and Method Specialization. Nordic Journal of Computing 1(1), 3–37 (1994); A preliminary version appeared In: Proc. of IEEE Symp. LICS 1993 (1993)

    MATH  MathSciNet  Google Scholar 

  15. Flanagan, D.: JavaScript - The Definitive Guide. O’Reilly, Sebastopol (1998)

    Google Scholar 

  16. : ECMAScript Language Specification. ECMA International. ECMA-262, 3rd edn. (december 1999), http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

  17. Morrisett, G., Walker, D., Crary, K., Glew, N.: From system f to typed assembly language. ACM Trans. Program. Lang. Syst. 21(3), 527–568 (1999)

    Article  Google Scholar 

  18. Oxhoj, N., Palsberg, J., Schwartzbach, M.I.: Making type inference practical. In: Lehrmann Madsen, O. (ed.) ECOOP 1992. LNCS, vol. 615, pp. 329–349. Springer, Heidelberg (1992)

    Chapter  Google Scholar 

  19. Hill, W., Olthoff, W., Canning, P., Cook, W., Mitchell, J.C.: F-bounded polymorphism for object-oriented programming. In: Proc. Conf. on Functional Programming Languages and Computer Architecture, pp. 273–280. ACM Press, New York (1989)

    Google Scholar 

  20. Palsberg, J.: Efficient inference of object types. Inf. Comput. 123(2), 198–209 (1995)

    Article  MATH  MathSciNet  Google Scholar 

  21. Palsberg, J., Schwartzbach, M.I.: Object-oriented type inference. In: Meyrowitz, N. (ed.) Proceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA), vol. 26. ACM Press, New York (1991)

    Google Scholar 

  22. Palsberg, J., Zhao, T.: Type inference for record concatenation and subtyping. Inf. Comput. 189(1), 54–86 (2004)

    Article  MATH  MathSciNet  Google Scholar 

  23. Salib, M.: Static Type Inference (for Python) with Starkiller (2004), http://www.python.org/pycon/dc2004/papers/1/paper.pdf

  24. Thiemann, P.: Towards a type system for analyzing javascript programs. In: Sagiv, M. (ed.) ESOP 2005. LNCS, vol. 3444, pp. 408–422. Springer, Heidelberg (2005)

    Chapter  Google Scholar 

  25. Wang, T., Smith, S.F.: Precise constraint-based type inference for java. In: Knudsen, J.L. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 99–117. Springer, Heidelberg (2001)

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2005 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Anderson, C., Giannini, P., Drossopoulou, S. (2005). Towards Type Inference for JavaScript. In: Black, A.P. (eds) ECOOP 2005 - Object-Oriented Programming. ECOOP 2005. Lecture Notes in Computer Science, vol 3586. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11531142_19

Download citation

  • DOI: https://doi.org/10.1007/11531142_19

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-27992-1

  • Online ISBN: 978-3-540-31725-8

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics