TeJaS: Retrofitting Type Systems for JavaScript

Benjamin S. Lerner, Joe Gibbs Politz, Arjun Guha, and Shriram Krishnamurthi
Dynamic Languages Symposium (DLS), 2013

JavaScript programs vary widely in functionality, complexity, and use, and analyses of these programs must accommodate such variations. Type-based analyses are typically the simplest such analyses, but due to the language’s subtle idioms and many application-specific needs—such as ensuring general-purpose type correctness, security properties, or proper library usage–we have found that a single type system does not suffice for all purposes. However, these varied uses still share many reusable common elements.

In this paper we present TeJaS, a framework for building type systems for JavaScript. TeJaS has been engineered modularly to encourage experimentation. Its initial type environment is reified, to admit easy modeling of the various execution contexts of JavaScript programs, and its type language and typing rules are extensible, to enable variations of the type system to be constructed easily.

The paper presents the base TeJaS type system, which performs traditional type- checking for JavaScript. Because JavaScript demands complex types, we explain several design decisions to improve user ergonomics. We then describe TeJaS’s modular structure, and illustrate it by reconstructing the essence of a very different type system for JavaScript. Systems built from TeJaS have been applied to several real-world, third-party JavaScript programs.

PDF

  @inproceedings{lerner:tejas
    author = "Benjamin~S. Lerner and Joe Gibbs Politz and Arjun Guha and
              Shriram Krishnamurthi",
    title = "{TeJaS}: Retrofitting Type Systems for {JavaScript}",
    year = 2013,
    booktitle = "Dynamic Languages Symposium (DLS)"
  }