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.
- 169generated modules of algorithms, tables and early errors (48,079 lines)
- 72laws of the host, in 10 topics
- 116laws of the model's values (including 12 of Numbers and 9 of Data Blocks), 7 of Unicode, and 4 of Parse Node parents
- 38errata: 36 defects of the text and 2 proposed normative changes, 29 of them switchable in the specification when a program runs
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
How it works
From spec.html and the overlay of readings to the Lean specification: the data, the machine, the model and the host, the errata, and one clause followed end to end.
What is proved
What it is to implement the specification, the engine's theorems verbatim, and what is proved, trusted, owed and outside the claim.
Errata
The 38 places where the text is read in more than one way: the sentences, the readings, the default, and a program for 29 of them, run when the site was built.
Applying a proposal
A TC39 proposal applied in a branch: 228 lines written by hand, 0 files of hand-written Lean changed.
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.
The model and its laws
The sorts of the specification as carriers and operations, and the laws a model obeys.
The host and its laws
What the specification leaves to the host, and the 72 laws it requires, by topic.
Implements
What it is to implement the specification, in full, with the definitions of a run.
The parser's laws
What a parse must be. Stated, and owed: not yet proved of the engine.
Run it
The debugger
A JavaScript program run by the specification's machine, paused at its steps: the spec stack beside the JS stack, the step's text, its slots and the store. In a browser with 64-bit WebAssembly.
Examples
Programs that each open in the debugger with their breakpoints set, from a property get to the errata read as written.
Results
test262
One run of the conformance suite on the engine: 42,967 of 43,521 tests pass in one of its two passes. Every test that does not pass, by cause; what is not run, and why.
Three things to know first
- The Lean is generated where the English is algorithmic. Every algorithm step, table and early-error rule in
lean/Ecma/Genis 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. - 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.
- 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.