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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Adobe. JSEclipse, http://labs.adobe.com/technologies/jseclipse/
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)
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)
Boyd, N., et al.: Rhino: JavaScript for Java, http://www.mozilla.org/rhino/
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)
Cartwright, R., Fagan, M.: Soft typing. In: Proc. ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 1991 (June 1991)
Childs, B.: JavaScript development toolkit (JSDT) features (July 2008), http://live.eclipse.org/node/569
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)
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)
Dolby, J.: Using static analysis for IDE’s for dynamic languages, 2005. In: The Eclipse Languages Symposium (2005)
ECMA. ECMAScript Language Specification, 3rd edn. ECMA-262
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)
Fink, S., Dolby, J.: WALA – The T.J. Watson Libraries for Analysis, http://wala.sourceforge.net/
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)
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)
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)
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)
Apple Inc. Squirrelfish bytecodes, http://webkit.org/specs/squirrelfish-3bytecode.html
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)
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)
Kam, J.B., Ullman, J.D.: Monotone data flow analysis frameworks. Acta Informatica 7, 305–317 (1977)
Kromann-Larsen, R., Simonsen, R.: Statisk analyse af JavaScript: Indledende arbejde. Master’s thesis, Department of Computer Science, University of Aarhus (2007) (in Danish)
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)
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)
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
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)
Nyström, S.-O.: A soft-typing system for Erlang. In: Proc. 2nd ACM SIGPLAN Erlang Workshop, ERLANG 2003, pp. 56–71 (2003)
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)
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)
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)
Wright, A.K., Cartwright, R.: A practical soft type system for Scheme. ACM Transactions on Programming Languages and Systems 19(1), 87–152 (1997)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2009 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Jensen, S.H., Møller, A., Thiemann, P. (2009). Type Analysis for JavaScript. In: Palsberg, J., Su, Z. (eds) Static Analysis. SAS 2009. Lecture Notes in Computer Science, vol 5673. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-03237-0_17
Download citation
DOI: https://doi.org/10.1007/978-3-642-03237-0_17
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-03236-3
Online ISBN: 978-3-642-03237-0
eBook Packages: Computer ScienceComputer Science (R0)