ECMA-262 in Lean

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.

Read first

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).

Run it

Results

Three things to know first

  1. SpecTec and spec.html form a verified bijection. Every algorithm, equation, early-error rule, table and grammar production lives in spec/spectec/ (def @sec-…, grammar, early_error, syntax, field, enum). lean/SpecTec/Html (spectec-html) splices spec/spectec/ back into spec.html with zero byte diffs via explicit presentation and patch tables in spec/html/; spectec roundtrip checks SpecTec's own formatting; and ecma-print (lean/Tools/SpecPrint) prints SpecTec back from downstream Lean and checks it byte for byte.
  2. Where the English is prose, SpecTec states syntax, relation and laws — quoting spec.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 in spec/spectec/prose/*.spectec, and every law quotes the governing sentence of spec.html (scripts/law_quotes.py).
  3. 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 (0 native_decide pins; 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.