ECMA-262 in Lean

ECMA-262, the ECMAScript language specification, as a Lean 4 specification

ECMA-262 in Lean

The specification's algorithms, tables, early errors and grammars are generated from its own source, spec.html. What the text assumes of its values and leaves to the host is stated as laws, each quoting the sentence it reads. One implementation, the engine, is proved to implement this specification, and runs test262.

TC39 #117 (November 2026): Executing spec.html — slide deck, diff-size table across all 14 ECMA-262 agenda proposals, and live browser spec-debugger demos.

Read first

The specification, set for reading

Generated from the Lean sources: each declaration with its documentation first, each law with its clause and the sentence it reads, the Lean beside.

Run it

Results

Three things to know first

  1. The Lean is generated where the English is algorithmic. Every algorithm step, table and early-error rule in lean/Ecma/Gen is produced from spec.html by a generator, never edited by hand. The generator checks that it prints each one back as the HTML's text; the Lean printer (scripts/bijection.py) checks the same from the Lean side.
  2. Where the English is not algorithmic, the Lean quotes it. What the text assumes (that mathematical values behave as the reals, that Numbers are IEEE 754 binary64) and what it leaves to the host (time, job scheduling, locale) is a law, and each law's documentation quotes the sentence it reads. A script checks every quotation against the pinned spec.html.
  3. The claim is precise and has limits. The engine is proved to implement the specification. The proof relies on Lean's 3 standard axioms alone (55 equations on the generated program are checked at run time before shortcuts run); the parser's laws are owed; the debugger is outside the claim. What is proved lists all of it.

Revisions

This site is built from one commit of the repository, 27e76ff, with the specification at tc39/ecma262 b1eaed82f and the tests at tc39/test262 2e58f87d8. The engine runs as ecma-run; the step debugger, ecma-dbg, runs in the browser as WebAssembly. In its latest recorded run of test262 (at 2e58f87d8, 2026-11-19), 42,967 of the 43,521 tests run pass (in either of its two passes, the second with larger limits); test262 lists every other.