ECMA-262 formalized in SpecTec, with an execution engine proved in Lean 4
ECMA-262 in Lean
The specification's algorithms, grammars, early errors and tables are formalized in SpecTec (spec/spectec/) in a verified bijection with spec.html. What the prose assumes of its values and leaves to the host is stated as SpecTec syntax, relation and laws declarations, each law quoting the sentence it reads. Downstream, SpecTec compiles to Lean 4, where one concrete engine is proved to implement the specification and runs test262.
- 36SpecTec modules of algorithms, grammars, tables & early errors (55,936 lines, bijective with
spec.html) - 72SpecTec laws of the host, in 10 topics
- 148SpecTec laws of the model (116 core, 12 of Numbers, 9 of Data Blocks, 7 of Unicode, and 4 of Parse Node parents) plus 7 of parsing, covers & Parse Nodes
- 57documented specification decisions: 54 defects of the text and 3 proposed normative changes
Read first
How it works
From
spec.htmlto SpecTec and downstream to Lean: structured declarations, prose relations & laws, bidirectional bijections, and one clause followed end to end.Applying a proposal
A TC39 proposal applied in a branch: 1,042 lines written by hand, 0 files of hand-written Lean changed.
Spec issues & errata
All 57 specification defects, non-literal SpecTec readings, and proposed changes (54 long-form write-ups, upstream TC39 tracking, and 52 runnable examples).
What is proved
What it is to implement the specification, the engine's and parser's theorems verbatim, and what is proved, trusted and outside the claim.
The specification, set for reading
Generated from the SpecTec prose modules (spec/spectec/prose/) and their transitive closure: every object and law cites its governing ECMA-262 clause, every law quotes the sentence it reads, and every referenced identifier is clickable (with auxiliary definitions folded until clicked).
The model and its laws
The sorts of the specification as SpecTec carriers, values and operations, and the laws a model obeys.
The host and its laws
What the specification leaves to the host, and the 72 SpecTec laws it requires, by topic.
The memory model (§29)
Candidate executions, happens-before, sequentially consistent memory order, valid executions (19 quoted laws), and races.
The parser's laws
Parse Nodes, §5.1 grammar derivations, §12 lexical scanning & ASI, and cover laws in SpecTec. All proved of the engine.
Implements
What it is for a downstream implementation to conform to the specification, with the observable state and §5.2 notation types.
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 results
TC39's conformance suite on
ecma-run: 42,985 of 43,521 tests pass (42,856 in the 60 s default pass, rising to 42,985 under the 600 s--gcpass; 0 failures, 0 stops).
Three things to know first
- SpecTec and
spec.htmlform a verified bijection. Every algorithm, equation, early-error rule, table and grammar production lives inspec/spectec/(def @sec-…,grammar,early_error,syntax,field,enum).lean/SpecTec/Html(spectec-html) splicesspec/spectec/back intospec.htmlwith zero byte diffs via explicit presentation and patch tables inspec/html/;spectec roundtripchecks SpecTec's own formatting; andecma-print(lean/Tools/SpecPrint) prints SpecTec back from downstream Lean and checks it byte for byte. - Where the English is prose, SpecTec states
syntax,relationandlaws— quotingspec.html. What the text assumes (that mathematical values form an ordered field, that Numbers are IEEE 754 binary64) and what it leaves to the host (time, job scheduling, locale, §29 memory) is written inspec/spectec/prose/*.spectec, and every law quotes the governing sentence ofspec.html(scripts/law_quotes.py). - The downstream Lean claim is precise and has limits.
lean/SpecTec(spectec) compiles SpecTec to Lean 4, where the concrete engine and its parser are proved against the specification relying on Lean's 3 standard axioms alone (0native_decidepins; 71 shortcut and parser-table checks verified at run time). Every stated SpecTec law is proved; the debugger loop is outside the claim; What is proved lists all of it.
Revisions
This site is built from one commit of the repository, acc6d4a, 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-27), 42,985 of the 43,521 tests run pass (including the 600 s --gc pass); test262 results gives the breakdown by directory.