Type Analysis for JavaScript

  • Simon Holm Jensen
  • Anders Møller
  • Peter Thiemann
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5673)

Abstract

JavaScript is the main scripting language for Web browsers, and it is essential to modern Web applications. Programmers have started using it for writing complex applications, but there is still little tool support available during development.

We present a static program analysis infrastructure that can infer detailed and sound type information for JavaScript programs using abstract interpretation. The analysis is designed to support the full language as defined in the ECMAScript standard, including its peculiar object model and all built-in functions. The analysis results can be used to detect common programming errors – or rather, prove their absence, and for producing type information for program comprehension.

Preliminary experiments conducted on real-life JavaScript code indicate that the approach is promising regarding analysis precision on small and medium size programs, which constitute the majority of JavaScript applications. With potential for further improvement, we propose the analysis as a foundation for building tools that can aid JavaScript programmers.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
  2. 2.
    Anderson, C., Giannini, P., Drossopoulou, S.: Towards type inference for JavaScript. In: Black, A.P. (ed.) ECOOP 2005. LNCS, vol. 3586, pp. 428–452. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  3. 3.
    Balakrishnan, G., Reps, T.W.: Recency-abstraction for heap-allocated storage. In: Yi, K. (ed.) SAS 2006. LNCS, vol. 4134, pp. 221–239. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  4. 4.
    Boyd, N., et al.: Rhino: JavaScript for Java, http://www.mozilla.org/rhino/
  5. 5.
    Bush, W.R., Pincus, J.D., Sielaff, D.J.: A static analyzer for finding dynamic programming errors. Software: Practice and Experience 30(7), 775–802 (2000)MATHGoogle Scholar
  6. 6.
    Cartwright, R., Fagan, M.: Soft typing. In: Proc. ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 1991 (June 1991)Google Scholar
  7. 7.
    Childs, B.: JavaScript development toolkit (JSDT) features (July 2008), http://live.eclipse.org/node/569
  8. 8.
    Christensen, A.S., Møller, A., Schwartzbach, M.I.: Precise analysis of string expressions. In: Cousot, R. (ed.) SAS 2003. LNCS, vol. 2694, pp. 1–18. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  9. 9.
    Cousot, P., Cousot, R.: Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In: Proc. 4th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1977, pp. 238–252 (1977)Google Scholar
  10. 10.
    Dolby, J.: Using static analysis for IDE’s for dynamic languages, 2005. In: The Eclipse Languages Symposium (2005)Google Scholar
  11. 11.
    ECMA. ECMAScript Language Specification, 3rd edn. ECMA-262Google Scholar
  12. 12.
    Engler, D.R., Chelf, B., Chou, A., Hallem, S.: Checking system rules using system-specific, programmer-written compiler extensions. In: 4th Symposium on Operating System Design and Implementation, OSDI 2000, USENIX (October 2000)Google Scholar
  13. 13.
    Fink, S., Dolby, J.: WALA – The T.J. Watson Libraries for Analysis, http://wala.sourceforge.net/
  14. 14.
    Flanagan, C., Flatt, M., Krishnamurthi, S., Weirich, S., Felleisen, M.: Catching bugs in the web of program invariants. In: Proc. ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 1996, pp. 23–32 (1996)Google Scholar
  15. 15.
    Furr, M., (David) An, J-h., Foster, J.S., Hicks, M.: Static type inference for Ruby. In: Proc. 24th Annual ACM Symposium on Applied Computing, SAC 2009, Object Oriented Programming Languages and Systems Track (March 2009)Google Scholar
  16. 16.
    Graver, J.O., Johnson, R.E.: A type system for Smalltalk. In: Proc. 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1990, pp. 136–150 (1990)Google Scholar
  17. 17.
    Heidegger, P., Thiemann, P.: Recency types for dynamically-typed object-based languages. In: Proc. International Workshops on Foundations of Object-Oriented Languages, FOOL 2009 (January 2009)Google Scholar
  18. 18.
    Apple Inc. Squirrelfish bytecodes, http://webkit.org/specs/squirrelfish-3bytecode.html
  19. 19.
    Jagannathan, S., Thiemann, P., Weeks, S., Wright, A.: Single and loving it: Must-alias analysis for higher-order languages. In: Proc. 25th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1998, pp. 329–341 (1998)Google Scholar
  20. 20.
    Jang, D., Choe, K.-M.: Points-to analysis for JavaScript. In: Proc. 24th Annual ACM Symposium on Applied Computing, SAC 2009, Programming Language Track (March 2009)Google Scholar
  21. 21.
    Kam, J.B., Ullman, J.D.: Monotone data flow analysis frameworks. Acta Informatica 7, 305–317 (1977)MathSciNetCrossRefMATHGoogle Scholar
  22. 22.
    Kromann-Larsen, R., Simonsen, R.: Statisk analyse af JavaScript: Indledende arbejde. Master’s thesis, Department of Computer Science, University of Aarhus (2007) (in Danish)Google Scholar
  23. 23.
    Lindahl, T., Sagonas, K.: Practical type inference based on success typings. In: Proc. 8th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, PPDP 2006, pp. 167–178 (2006)Google Scholar
  24. 24.
    Marlow, S., Wadler, P.: A practical subtyping system for Erlang. In: Proc. 2nd ACM SIGPLAN International Conference on Functional Programming, ICFP 1997, pp. 136–149 (1997)Google Scholar
  25. 25.
    Sun Microsystems and Netscape Inc. Netscape and Sun announce Javascript(TM), the open, cross-platform object scripting language for enterprise networks and the internet (1995), http://sunsite.nus.sg/hotjava/pr951204-03.html
  26. 26.
    Might, M., Shivers, O.: Improving flow analyses via ΓCFA: abstract garbage collection and counting. In: Proc. 11th ACM SIGPLAN International Conference on Functional Programming, ICFP 2006 (2006)Google Scholar
  27. 27.
    Nyström, S.-O.: A soft-typing system for Erlang. In: Proc. 2nd ACM SIGPLAN Erlang Workshop, ERLANG 2003, pp. 56–71 (2003)Google Scholar
  28. 28.
    Sagiv, S., Reps, T.W., Wilhelm, R.: Parametric shape analysis via 3-valued logic. ACM Transactions on Programming Languages and Systems 24(3), 217–298 (2002)CrossRefGoogle Scholar
  29. 29.
    Sharir, M., Pnueli, A.: Two approaches to interprocedural dataflow analysis. In: Program Flow Analysis: Theory and Applications, pp. 189–233. Prentice-Hall, Englewood Cliffs (1981)Google Scholar
  30. 30.
    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)CrossRefGoogle Scholar
  31. 31.
    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

Copyright information

© Springer-Verlag Berlin Heidelberg 2009

Authors and Affiliations

  • Simon Holm Jensen
    • 1
  • Anders Møller
    • 1
  • Peter Thiemann
    • 2
  1. 1.Aarhus UniversityDenmark
  2. 2.Universität FreiburgGermany

Personalised recommendations