Experiments with Strengthening JavaScript

JavaScript has many “interesting” features that make development difficult at scale: sloppy semantics can get in the way of reliable programming, testing and maintenance, and in the way of predictable performance – the latter problem, ironically, getting harder the smarter VMs become. With the advent of the new ECMAScript 6 standard this year, JavaScript sees many significant improvements: classes, modules, lexical scoping, iterators, and the like can replace less well-behaved alternatives. Yet various flaws of the language cannot be corrected without “breaking the web”.

The V8 team has started exploring ways to mitigate these problems. First, taking ECMAScript 6 as a foundation, we are implementing strong mode, a new language mode that provides a stronger semantics purely by subsetting JavaScript, removing brittle behaviours and costly performance cliffs. Strong mode is supposed to both make development easier and codify a reliable “contract” for predictable performance in contemporary VMs. Second, taking established JS type systems (TypeScript, Closure Compiler, Flow) as a basis, we are designing SoundScript, a sound type system for JavaScript that we intend to implement directly in the VM. Besides obvious advantages over offline type checking — interactive development, type-based optimisations, the ability to afford runtime checks for soundness — we also face additional challenges: in particular, type checking must be efficient, and it must be compatible with standard implementation techniques such as lazy compilation. That imposes significant design constraints on the type system.