Repository navigation
Keep the cycle guard on Array#join, Array#toString and Array#toLocaleString - #559
Conversation
…String
Upstream removed StringRecursionChecker (318399@main). Since then a
cyclic array throws a RangeError when it is converted to a string:
const a = []; a.push(1, a, 2);
a.join("-"); // RangeError: Maximum call stack size exceeded
V8 and SpiderMonkey return the empty string for an array that is
already being joined, so Node prints "1--2". Code that runs under Node
depends on that. three.js r170 hashes arrays that contain themselves
and breaks under the new behaviour.
This restores StringRecursionChecker for the array conversions only,
under USE(BUN_JSC_ADDITIONS): Array#join, Array#toLocaleString,
JSArray::fastToString, and the DFG ArrayJoin operations, which did not
have the guard before. Error#toString and RegExp#toString keep the
upstream behaviour, which is also what V8 does.
Preview Builds
|
|
Verified through oven-sh/bun#41300, which pins the preview build |
| let nested = [1]; | ||
| nested.push(nested, 2); | ||
|
|
||
| for (let i = 0; i < 20000; ++i) { |
There was a problem hiding this comment.
🟡 nit (optional) (pre-existing, extended by this diff): the warm-up loop hardcodes 20000 iterations; JSTests/README.md (imported by JSTests/CLAUDE.md) requires stress tests to use testLoopCount so the harness can size the loop per configuration and keep every run under 200ms. Fix: replace 20000 with testLoopCount for the tier-up loop.
Extended reasoning...
JSTests/CLAUDE.md points to JSTests/README.md, whose rule 2 states new/updated stress tests must use testLoopCount (set by the jsc CLI per configuration) rather than a fixed iteration count, and rule 1 caps every configuration at 200ms. This rewrite keeps the pre-existing for (let i = 0; i < 20000; ++i) and adds a fourth call (joinDefault) inside it, so the loop now does 80000 assertions in configurations where fewer would suffice (e.g. no-JIT) and may still under-iterate in eager tier-up configs. Using testLoopCount lets the runner pick the right count and keeps the test compliant with the required conventions.
Verification: nit (pre-existing, extended by this diff): /home/claude/webkit/JSTests/stress/string-conversion-recursion.js:208 reads for (let i = 0; i < 20000; ++i). /home/claude/webkit/JSTests/CLAUDE.md imports /home/claude/webkit/JSTests/README.md, whose "Adding Tests" section rule 2 states: "Use testLoopCount or wasmTestLoopCount to control how many iterations a test runs. The jsc CLI sets these…
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 5 included reviews per hour; 1 remains after this review. WalkthroughChangesThe PR adds Bun-specific recursion tracking for array string conversion. It updates array conversion paths and expands stress tests for cyclic conversion, cleanup, recovery, and optimization behavior. String recursion guard
Merge Risk: ⚪ Minimal · up to No unresolved merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, fix, scope, implementation, and verification. It does not follow the repository template because it omits a Bugzilla URL, the required review line, and the listed changed paths and functions.
Warning Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use Comment |
Updates `WEBKIT_VERSION` from `40e43a82a755` to `6119947592b6`. Picks up: - oven-sh/WebKit#554 — [JSC] Startup: size the atom table for a bun VM, read cgroup limits once, hand the structure arena over as zeroed - oven-sh/WebKit#559 — Keep the cycle guard on Array#join, Array#toString and Array#toLocaleString
oven-sh/WebKit#559 keeps the cycle guard on the array conversions, so a cyclic join matches V8 and Node again. Takes the tests from #41300. Co-authored-by: robobun <[email protected]>
Problem
RangeError: Maximum call stack size exceededfromjoin,toString,toLocaleString, template literals,String(a), and0 ^ a. Bun 1.3.14 returned"1,,2"for[1, a, 2]. Reported in ToNumber on a self-referential array throws RangeError (Node returns 0) bun#41198 (three.js r170 hashes arrays that contain themselves and works under Node).StringRecursionCheckeron purpose in https://commits.webkit.org/318399@main (f2f2c2d). The guard is not in the spec. V8 and SpiderMonkey keep an equivalent guard, so Node and Firefox return the empty string for an array that is already being joined.Fix
StringRecursionCheckerunderUSE(BUN_JSC_ADDITIONS)for the array conversions only:arrayProtoFuncJoin,arrayProtoFuncToLocaleString,JSArray::fastToString, and the DFGArrayJoinoperations (arrayJoinWithStringSeparator), which had no guard before the removal either.Error#toStringandRegExp#toStringkeep the upstream behaviour. V8 has no guard there either.isSafeToRecurseSoftcheck, so the stack overflow path that upstream added tofastToStringis kept.JSTests/stress/string-conversion-recursion.jsis rewritten for the array behaviour. The same file (withnoInlinestubbed) passes under Node v26 unchanged, so the expectations match V8.Background
StringRecursionCheckeris an RAII object. It records the receiver invm.stringRecursionCheckVisitedObjectsfor the duration of one conversion. A nested conversion of a receiver that is already recorded returns the empty string instead of recursing.ArrayJoinnode (26b192b) callsfastArrayJoindirectly fromDFGOperations.cpp, so the guard inarrayProtoFuncJoindoes not cover optimized code. This change adds the guard on that path too.