SJS: A Type System for JavaScript with Fixed Object Layout

  • Wontae Choi
  • Satish Chandra
  • George Necula
  • Koushik Sen
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 9291)


We propose a static type system for a significant subset of JavaScript, dubbed SJS, with the goal of ensuring that objects have a statically known layout at the allocation time, which in turn can enable an ahead-of-time (AOT) compiler to generate efficient code.The main technical challenge we address is to ensure fixed object layout, while supporting popular language features such as objects with prototype inheritance, structural subtyping, and method updates, with the additional constraint that SJS programs can run on any available standard JavaScript engine, with no deviation from JavaScript’s standard operational semantics. The core difficulty arises from the way standard JavaScript semantics implements object attribute update with prototype-based inheritance. To our knowledge, combining a fixed object layout property with prototype inheritance and subtyping has not been achieved previously.


Type System Object Type Owned Attribute Method Invocation Inheritance Mechanism 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.



The work of the first author is supported in part by a research internship at Samsung Research America. The work of the last author is supported in part by Samsung Research America. This research is partially supported by NSF grants CCF-1018730, CCF-1017810, CCF-1409872, and CCF-1423645. The authors thank Colin S. Gordon, Frank Tip, Manu Sridharan, and the anonymous reviewers for their comments and suggestions.


  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
    Abadi, M., Cardelli, L.: A Theory of Objects, 1st edn. Springer, New York (1996)CrossRefGoogle Scholar
  6. 6.
    Ancona, D., Ancona, M., Cuni, A., Matsakis, N.D.: RPython: a step towards reconciling dynamically and statically typed oo languages. In: DSL 2007 (2007)Google Scholar
  7. 7.
    Anderson, C., Giannini, P., Drossopoulou, S.: Towards type inference for javascript. In: Gao, X.-X. (ed.) ECOOP 2005. LNCS, vol. 3586, pp. 428–452. Springer, Heidelberg (2005) CrossRefGoogle Scholar
  8. 8.
    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) CrossRefGoogle Scholar
  9. 9.
    Bracha, G., Griswold, D.: Strongtalk: typechecking smalltalk in a production environment. In: OOPSLA 1993 (1993)Google Scholar
  10. 10.
    Chambers, C., Group, T.C.: The Cecil language - specification and rationale (2004)Google Scholar
  11. 11.
    Chambers, C., Ungar, D.: Customization: optimizing compiler technology for SELF, a dynamically-typed object-oriented programming language. In: PLDI 1989 (1989)Google Scholar
  12. 12.
    Choi, P.W., Chandra, S., Necula, G., Sen, K.: SJS: a typed subset of JavaScript with fixed object layout. Technical report UCB/EECS-2015-13, EECS Department, University of California, Berkeley, April 2015Google Scholar
  13. 13.
    Chugh, R., Herman, D., Jhala, R.: Dependent types for JavaScript. In: OOPSLA 2012 (2012)Google Scholar
  14. 14.
    Fisher, K., Honsell, F., Mitchell, J.C.: A lambda calculus of objects and method specialization. Nord. J. Comput. 1(1), 3–37 (1994)MathSciNetGoogle Scholar
  15. 15.
    Furr, M., An, J.H.D., Foster, J.S., Hicks, M.: Static type inference for ruby. In: SAC 2009 (2009)Google Scholar
  16. 16.
    Gong, L., Pradel, M., Sen, K.: JITProf: pinpointing JIT-unfriendly JavaScript code. In: ESEC/FSE 2015 (2015)Google Scholar
  17. 17.
    Heidegger, P., Thiemann, P.: Recency types for analyzing scripting languages. In: D’Hondt, T. (ed.) ECOOP 2010. LNCS, vol. 6183, pp. 200–224. Springer, Heidelberg (2010) CrossRefGoogle Scholar
  18. 18.
    Lerner, B.S., Politz, J.G., Guha, A., Krishnamurthi, S.: TeJaS: retrofitting type systems for JavaScript. In: DLS 2013 (2013)Google Scholar
  19. 19.
    Politz, J.G., Guha, A., Krishnamurthi, S.: Semantics and types for objects with first-class member names. In: FOOL 2012 (2012)Google Scholar
  20. 20.
    Rastogi, A., Chaudhuri, A., Hosmer, B.: The ins and outs of gradual type inference. In: POPL 2012 (2012)Google Scholar
  21. 21.
    Rastogi, A., Swamy, N., Fournet, C., Bierman, G., Vekris, P.: Safe and efficient gradual typing for TypeScript. Technical report MSR-TR-2014-99, July 2014Google Scholar
  22. 22.
    Swamy, N., Fournet, C., Rastogi, A., Bhargavan, K., Chen, J., Strub, P.Y., Bierman, G.: Gradual typing embedded securely in JavaScript. In: POPL 2014 (2014)Google Scholar
  23. 23.
    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
  24. 24.
    Tobin-Hochstadt, S., Felleisen, M.: The design and implementation of typed Scheme. In: POPL 2008 (2008)Google Scholar
  25. 25.
    Tobin-Hochstadt, S., Felleisen, M.: Logical types for untyped languages. In: ICFP 2010 (2010)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2015

Authors and Affiliations

  • Wontae Choi
    • 1
  • Satish Chandra
    • 2
  • George Necula
    • 1
  • Koushik Sen
    • 1
  1. 1.University of CaliforniaBerkeleyUSA
  2. 2.Samsung Research AmericaMountain ViewUSA

Personalised recommendations