Towards a Type System for Analyzing JavaScript Programs

  • Peter Thiemann
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3444)


JavaScript is a popular language for client-side web scripting. It has a dubious reputation among programmers for two reasons. First, many JavaScript programs are written against a rapidly evolving API whose implementations are sometimes contradictory and idiosyncratic. Second, the language is only weakly typed and comes virtually without development tools.

The present work is a first attempt to address the second point. It does so by defining a type system that tracks the possible traits of an object and flags suspicious type conversions. Because JavaScript is a classless, object-based language with first-class functions, the type system must include singleton types, subtyping, and first class record labels. The type system covers a representative subset of the language and there is a type soundness proof with respect to an operational semantics.


dynamic type systems program analysis objects functions 


  1. 1.
    Abadi, M., Cardelli, L.: A Theory of Objects. Springer, Heidelberg (1996)zbMATHGoogle Scholar
  2. 2.
    Armstrong, J., Virding, R., Williams, M.: Concurrent Programming in Erlang. Prentice-Hall, NY (1993)zbMATHGoogle Scholar
  3. 3.
    Cartwright, R., Fagan, M.: Soft typing. In: Proc. Conference on Programming Language Design and Implementation 1991, Toronto, Canada, June 1991, pp. 278–292. ACM Press, New York (1991)CrossRefGoogle Scholar
  4. 4.
    ECMAScript Language Specification. ECMA International, ECMA-262, 3rd edn. (December 1999),
  5. 5.
    Gaster, B.R., Jones, M.P.: A polymorphic type system for extensible records and variants. Technical Report NOTTCS-TR-96-3, Dept. of Computer Science, University of Nottingham (November 1996)Google Scholar
  6. 6.
    Henglein, F.: Dynamic typing: Syntax and proof theory. Science of Computer Programming 22, 197–230 (1994)zbMATHCrossRefMathSciNetGoogle Scholar
  7. 7.
    Henglein, F., Rehof, J.: Safe polymorphic type inference for a dynamically typed language: Translating Scheme to ML. In: Jones, S.P. (ed.) Proc. Functional Programming Languages and Computer Architecture 1995, La Jolla, CA, June 1995. ACM Press, New York (1995)Google Scholar
  8. 8.
    Marlow, S., Wadler, P.: A practical subtyping system for erlang. In: Proceedings of the second ACM SIGPLAN international conference on Functional programming, pp. 136–149. ACM Press, New York (1997)CrossRefGoogle Scholar
  9. 9.
    Nishimura, S.: Static typing for dynamic messages. In: Cardelli, L. (ed.) Proc. 25th Annual ACM Symposium on Principles of Programming Languages, San Diego, CA, USA, January 1998, pp. 266–278. ACM Press, New York (1998)CrossRefGoogle Scholar
  10. 10.
    Nyström, S.-O.: A soft-typing system for erlang. In: Proceedings of the 2003 ACM SIGPLAN workshop on Erlang, pp. 56–71. ACM Press, New York (2003)CrossRefGoogle Scholar
  11. 11.
    The Mozilla Organization. Rhino: JavaScript for Java (September 2004),
  12. 12.
    Pessaux, F., Leroy, X.: Type-based analysis of uncaught exceptions. In: Proceedings of the 26th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pp. 276–290. ACM Press, New York (1999)CrossRefGoogle Scholar
  13. 13.
    Rémy, D.: Type inference for records in a natural extension of ML. In: Gunter, C.A., Mitchell, J.C. (eds.) Theoretical Aspects of Object-Oriented Programming: Types, Semantics, and Language Design. The MIT Press, Cambridge (1994)Google Scholar
  14. 14.
    Ungar, D., Smith, R.B.: SELF: The power of simplicity. Lisp and Symbolic Computation 4(3), 187–206 (1991)CrossRefGoogle Scholar
  15. 15.
    Wright, A.K., Cartwright, R.: A practical soft type system for Scheme. ACM Transactions on Programming Languages and Systems 19(1), 87–152 (1997)CrossRefGoogle Scholar
  16. 16.
    Yi, K.: An abstract interpretation for estimating uncaught exceptions in standard ML programs. Science of Computer Programming 31(1), 147–173 (1998)zbMATHCrossRefMathSciNetGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2005

Authors and Affiliations

  • Peter Thiemann
    • 1
  1. 1.Universität Freiburg 

Personalised recommendations