Built-ins that throw: a complete, tested map of the ECMAScript built-ins, and unhandled-failure where the failing condition can arise #117
Loading…
Reference in a new issue
No description provided.
Delete branch "ecmascript-builtins"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Based on
fail-closed-integration, which ismainplus the open PRs #109 to #114 merged together. Once those are in, I'll rebase this ontomainand retarget it. It is independent of #115 and #116.For Node's built-ins and the browser's APIs the project has complete maps: every callable, classified by how it fails, with a test that makes each failing one fail. For the language's own built-ins there was a short hand-written list. So these passed
tscstrict,safe-ts checkand oxlint, and threw at run time:What changes
A map of the ECMAScript built-ins (
crates/safe_ts_core/ecmascript/ecmascript-api.json): 1,110 callables taken from TypeScript's lib files, in the same format and categories as the Node and browser maps. 290 can throw. A test makes every one of the 290 fail on the running Node and checks the error's class. The hand list is gone; the checker reads the map.unhandled-failurereports a built-in when the failing condition can arise, with the condition and what to write in the message:reducewithout an initial value on a list not known to have an element;toISOStringand its relatives on a date made from text, also one step away (new Date(Date.parse(text)), or a project function that returns such a date).n.toFixed(2)cannot fail,n.toFixed(digits)can./and%by a divisor that may be0n,**with an exponent that may be negative.A literal that cannot fail is no longer reported, which fixes
BigInt(1). A literal the checker can read and knows is wrong is:toFixed(101), a time zone that doesn't exist.The rule was narrowed by what a real project showed
The first version added about 260 findings on an adopter's project. The implementer read about 125 of them and none was a real way to throw: typed-array sizes computed from dimensions, dates from the clock,
DataViewcursors checked in helpers. Those kinds are mapped and documented but not reported:typedArray.set;Datethat arrives as a parameter or field;DataViewkept in a field, or over a buffer whose length the function reads;After narrowing, the adopter gains 4 findings where the built-in is called (8 with their callers), compared finding by finding against the base, and nothing is removed:
reducewithout an initial value, twice: once on a constant list the checker can't see the length of, once in a test;Array(size)withsizea parameter;repeat(max)in a test helper.All four are in range today for reasons the checker can't see, and all four follow the stated rule. The whole-program pass time is unchanged (860 ms before, 849 ms after).
How it was checked
test:std(386, including the map's own test),typecheck, the docs examples,test:vite, the docs site build and the soundness corpus pass.BigInt(text),repeatof parsed text,with(at, ...), a date through a helper function in three forms). Eighteen functions that cannot fail stay clean.Not done
Date.parse(text)used as a number is the wrong-value half and belongs to the sentinel-values change.safe-ts coveragedoes not list this map yet.Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review and acceptance tests) in Claude Code.