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.
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Abadi, M., Cardelli, L.: A Theory of Objects. Springer, New York (1996)
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)
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)
Amadio, R.M., Cardelli, L.: Subtyping recursive types. ACM Transactions on Programming Languages and Systems 15(4), 575–631 (1993)
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)
Anderson, C., Giannini, P.: Type checking for javascript. In: WOOD 2004. WOOD of ENTCS. Elsevier, Amsterdam (2004), http://www.binarylord.com/work/js0wood.pdf
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)
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)
Damiani, F., Giannini, P.: Alias types for environment aware computations. In: WOOD 2003. ENTCS, vol. 82. Elsevier, Amsterdam (2003)
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)
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
Agesen, O., et al.: The SELF 4.0 Programmer’s Reference Manual (1995), http://research.sun.com/self/
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)
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)
Flanagan, D.: JavaScript - The Definitive Guide. O’Reilly, Sebastopol (1998)
: ECMAScript Language Specification. ECMA International. ECMA-262, 3rd edn. (december 1999), http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
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)
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)
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)
Palsberg, J.: Efficient inference of object types. Inf. Comput. 123(2), 198–209 (1995)
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)
Palsberg, J., Zhao, T.: Type inference for record concatenation and subtyping. Inf. Comput. 189(1), 54–86 (2004)
Salib, M.: Static Type Inference (for Python) with Starkiller (2004), http://www.python.org/pycon/dc2004/papers/1/paper.pdf
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)
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)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)