Skip to content

Keep the cycle guard on Array#join, Array#toString and Array#toLocaleString - #559

Merged
dylan-conway merged 1 commit into
mainfrom
robobun/5e56f4e3/array-join-cycle-guard
Sep 4, 2026
Merged

dylan-conway merged 1 commit into
mainfrom
robobun/5e56f4e3/array-join-cycle-guard

Conversation

@robobun

@robobun robobun commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fix

  • Restore StringRecursionChecker under USE(BUN_JSC_ADDITIONS) for the array conversions only: arrayProtoFuncJoin, arrayProtoFuncToLocaleString, JSArray::fastToString, and the DFG ArrayJoin operations (arrayJoinWithStringSeparator), which had no guard before the removal either.
  • Error#toString and RegExp#toString keep the upstream behaviour. V8 has no guard there either.
  • The guard still performs the isSafeToRecurseSoft check, so the stack overflow path that upstream added to fastToString is kept.
  • Verified: JSTests/stress/string-conversion-recursion.js is rewritten for the array behaviour. The same file (with noInline stubbed) passes under Node v26 unchanged, so the expectations match V8.

Background

  • StringRecursionChecker is an RAII object. It records the receiver in vm.stringRecursionCheckVisitedObjects for the duration of one conversion. A nested conversion of a receiver that is already recorded returns the empty string instead of recursing.
  • The DFG ArrayJoin node (26b192b) calls fastArrayJoin directly from DFGOperations.cpp, so the guard in arrayProtoFuncJoin does not cover optimized code. This change adds the guard on that path too.

…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.
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

Preview Builds

Commit Release Date
98fae718 autobuild-preview-pr-559-98fae718 2026-09-03 22:29:14 UTC

@robobun

robobun commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

Verified through oven-sh/bun#41300, which pins the preview build autobuild-preview-pr-559-98fae718. The regression test there fails on 1.4.1 and passes with this build.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

let nested = [1];
nested.push(nested, 2);

for (let i = 0; i < 20000; ++i) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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…

@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Essentials

Run ID: 0f4692b6-63f1-4b90-8299-1d8ccc480868

📥 Commits

Reviewing files that changed from the base of the PR and between 2e0532b and 98fae71.

📒 Files selected for processing (8)
  • JSTests/stress/string-conversion-recursion.js
  • Source/JavaScriptCore/Sources.txt
  • Source/JavaScriptCore/dfg/DFGOperations.cpp
  • Source/JavaScriptCore/runtime/ArrayPrototype.cpp
  • Source/JavaScriptCore/runtime/JSArray.cpp
  • Source/JavaScriptCore/runtime/StringRecursionChecker.cpp
  • Source/JavaScriptCore/runtime/StringRecursionChecker.h
  • Source/JavaScriptCore/runtime/VM.h

Included review availability: Your plan provides up to 5 included reviews per hour; 1 remains after this review.


Walkthrough

Changes

The 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

Layer / File(s) Summary
Recursion tracking state
Source/JavaScriptCore/runtime/VM.h, Source/JavaScriptCore/runtime/StringRecursionChecker.*, Source/JavaScriptCore/Sources.txt
VM stores recursion state. StringRecursionChecker tracks visited objects and produces empty-string early values for repeated objects.
Array conversion integration
Source/JavaScriptCore/runtime/ArrayPrototype.cpp, Source/JavaScriptCore/runtime/JSArray.cpp, Source/JavaScriptCore/dfg/DFGOperations.cpp
Array conversion paths invoke StringRecursionChecker and return its early value when recursion is detected.
Recursion behavior coverage
JSTests/stress/string-conversion-recursion.js
The stress test covers cyclic arrays, generic array-like receivers, shared subtrees, exception cleanup, stack recovery, and optimized conversion paths.

Merge Risk: ⚪ Minimal · up to 98fae

No unresolved merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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… Add the bug title and Bugzilla URL, include “Reviewed by NOBODY (OOPS!).” or the applicable review status, and list the changed files with their relevant functions or classes using the required template structure.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: retaining cycle guards for Array#join, Array#toString, and Array#toLocaleString. It is concise and relevant.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI

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 path_filters to narrow the review scope.


Comment @coderabbitai help to get the list of available commands.

@dylan-conway
dylan-conway merged commit 6119947 into main Sep 4, 2026
48 checks passed
dylan-conway added a commit to oven-sh/bun that referenced this pull request Sep 4, 2026
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
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Sep 4, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants