Repository navigation
Description
Parent: #934 (robustness: deep structures crash instead of throwing RangeError)
Related: #938, whose review found these; that fix covers only recursion that follows source nesting
Confirmed by execution
Each program builds a deep runtime structure iteratively (no deep source, no deep JS call stack), then performs one operation. Run with test262 --eval built at b895723 (ReleaseFast), and with node v24.4.1 as the oracle:
| operation | zig-js | node |
|---|---|---|
a.flat(Infinity) where a contains itself |
SIGSEGV | RangeError: Maximum call stack size exceeded |
b.flat(Infinity) on a 300,000-deep array |
SIGSEGV | RangeError |
c.flat(Infinity) on a 50-deep array (control) |
1 |
1 |
Object.getPrototypeOf(p), p a chain of 200,000 trap-less Proxy objects |
SIGSEGV | RangeError |
Object.isExtensible(p), same chain |
SIGSEGV | RangeError |
Object.defineProperty(p, 'x', {value: 1}), same chain |
SIGSEGV | RangeError |
Object.prototype.toString.call(p), chain of 200,000 proxies over an array |
SIGSEGV | RangeError |
f(), f bound 100,000 times |
SIGSEGV | 7 (node runs it, at 300,000 links too) |
({}) instanceof g, g bound 100,000 times |
SIGSEGV | RangeError |
The whole operation runs under one native built-in call (or one instanceof), so stackGuard runs at most once, before the recursion starts. #938 guards recursion over source nesting; none of these involve deep source.
Recursion sites (from code reading; the table above is what was executed)
- Array.prototype.flat:
flattenInto(src/interpreter.zig:19624) <->flattenIntoLen(19636), once per nested array level. Neither is a tail call, because each keeps temp roots under adefer.depthis a Number, soInfinity - 1never stops a self-referential array. - Proxy forwarding without a trap:
proxyGetProto(15031),proxyIsExtensible(15055),proxyPreventExt(15074) andproxySetProto(15097) recurse once per proxy link. So do builtins.zigapplyDescriptor(1771, via [[DefineOwnProperty]]) and the [[GetOwnProperty]] forwarding. - IsArray over proxies:
objectToStringIsArray(23667) recurses per link. It runs from Object.prototype.toString, ArraySpeciesCreate, concat's IsConcatSpreadable, JSON.stringify's replacer check and flat.Array.isArray(builtins.zigisArrayValue) is already iterative. - Bound functions: [[Call]]/[[Construct]] follow
boundFunctiontargets recursively throughcallValueWithThisAtSite/constructNTAtSite.instanceofgoes throughordinaryHasInstance(21935) ->instanceOf(21892) per bound link without crossing a call boundary.
Direction
- Where the spec algorithm is recursive but the chain has no user-observable step between links (a trap-less proxy, a bound function, IsArray), a loop with a hop count can replace the recursion. A bound call then works as it does in node, and a proxy chain throws once the count exceeds what the stack could hold.
- Where user code can run between levels (flat reads elements, which can hit getters), keep the recursion but check the stack with
Interpreter.checkNesting(Crash: tree-walker recursion without a JS call escapes stackGuard on deeply nested source #938), so it throws the same catchable RangeError.
A regression case should build each structure iteratively in one process per shape. Several of them crash, and a crash in one would hide the rest.
Activity
glennmichael123 commentedon Sep 18, 2026
Fixed in f2b655d.
Reproduced first, on the post-#938 engine (81b49b1, ReleaseFast) — every shape in the table above still crashed, so #938's source-nesting guard does not reach them. Each structure was built iteratively in its own process, with
/usr/bin/time -lfor peak RSS.Fix, chosen per site by what the spec makes observable between two links:
flatreads elements, which can run a getter, so FlattenIntoArray stays recursive and is charged to the Crash: tree-walker recursion without a JS call escapes stackGuard on deeply nested source #938 stack floor.depthis a Number, soInfinity - 1never terminates on a self-referential array.proxyDepthnow checks the stack floor as well as the call depth — covering [[GetPrototypeOf]], [[IsExtensible]], [[PreventExtensions]], [[SetPrototypeOf]] and the rest — plusapplyDescriptorin builtins.zig, which re-enters itself for a trap-less [[DefineOwnProperty]].instanceofstill repeats the observable @@hasInstance lookup per hop.Before → after (
test262 --eval, ReleaseFast, node v24.4.1 as oracle):a.flat(Infinity),acontains itselfb.flat(Infinity), 300,000 deepc.flat(Infinity), 50 deep (control)111Object.getPrototypeOf(p), 200,000 proxiesObject.isExtensible(p)Object.defineProperty(p, 'x', …)Object.prototype.toString.call(p)f(), 200,000 binds77({}) instanceof g, 200,000 bindsfalsefalseis what OrdinaryHasInstance defines once the chain is walked to its innermost target and{}'s prototype chain is checked; node reports RangeError because V8 recurses per link.Pre-fix crash thresholds, for sizing the regression case: bound chains between 32,000 and 64,000 links,
flatbetween 30,000 and 60,000 levels, proxy chains above 60,000.No conformance change. test/built-ins/Proxy 311, Function 509, Array 3,081, Object 3,411, Reflect 153, JSON 165, test/language/expressions 11,038, test/annexB 1,086 — all 0 fail and identical before and after. VM-witness: Function 509 agree, Proxy 311 agree, expressions 11,025 agree with the same 13 pre-existing divergences, all identical. Flips 0 cases. Focused suites: runtime 14 (new 15-check case covering every shape plus controls for bound argument order, the innermost bound
this, and newTarget in both directions), vm 4, jit 393, frontend 26, concurrency 4.Found while reproducing this: a bound chain stores a quadratic amount of name text — 16,000 binds cost 755 MB against node's 48 MB — filed as #942. The regression case resets each bound function's configurable
nameso it measures frames, not names.glennmichael123 commentedon Sep 18, 2026
Landed in f2b655d with the evidence above.
fix(proxy): forward trap-less calls in a loop and read callability fr…