Skip to content

Add regression test for iterator and spread TypeError source locations - #32442

Closed
robobun wants to merge 1 commit into
mainfrom
farm/0838e1fb/fix-21134-forof-error-location
Closed

Add regression test for iterator and spread TypeError source locations#32442
robobun wants to merge 1 commit into
mainfrom
farm/0838e1fb/fix-21134-forof-error-location

Conversation

@robobun

@robobun robobun commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes #21134

Repro

const a = undefined;

console.log("here");
for (const b of a) {
  console.log("here2");
}

Bun 1.4.0 and earlier report the previous statement:

3 | console.log("here");
            ^
TypeError: undefined is not an object (evaluating 'console.log("here")')
      at test.js:3:9

Bun built from current main reports the for-of:

4 | for (const b of a) {
               ^
TypeError: undefined is not an object (evaluating 'b of void 0')
      at test.js:4:12

Cause

When the subject of for-of, for-await-of, array destructuring, yield*, or an array spread emits no expression info of its own (a literal such as null or undefined, including the literal Bun's transpiler produces by inlining const a = undefined), JavaScriptCore's bytecode generator emitted the [Symbol.iterator] get_by_id (and OpSpread) without a preceding emitExpressionInfo. Those ops inherited the previous statement's expression range, so the TypeError pointed at the wrong line and the evaluating '...' text quoted the previous statement.

Where the fix landed

The JavaScriptCore fix (emit expression info from the enclosing node before the [Symbol.iterator] get and before OpSpread) landed upstream in WebKit/WebKit#67762, and main already contains it through the WebKit upgrade in #33133 (WEBKIT_VERSION is c9ad5813fd23, whose tree has the new emitExpressionInfo calls at all of these sites). oven-sh/WebKit#255, the same change on the fork, was closed as superseded by the upstream patch.

This PR is therefore the Bun regression coverage only: test/regression/issue/21134.test.ts, covering all five constructs plus the original const-inlining repro. It changes no source and no longer touches WEBKIT_VERSION.

Verification

On this branch:

  • bun bd test test/regression/issue/21134.test.ts: 6 pass.
  • USE_SYSTEM_BUN=1 bun test test/regression/issue/21134.test.ts (released 1.4.0, which predates the WebKit upgrade): 6 fail.

Since current main already contains the JavaScriptCore fix, the test passes on main without any Bun source change from this PR; the failing state it guards is any Bun built before the c9ad5813fd23 WebKit pin.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR updates the WEBKIT_VERSION constant in the build dependency script from a commit SHA to a temporary autobuild-preview-pr-255-e08efa3c preview tag, and adds a new regression test file for issue #21134 that validates correct error source-location reporting when iterating, destructuring, or spreading null/undefined values.

Changes

WebKit Pin Update and Issue #21134 Regression Test

Layer / File(s) Summary
WebKit version pin
scripts/build/deps/webkit.ts
WEBKIT_VERSION is changed from cd821fecca0d39c8bac874c283d956868c7f0de0 to autobuild-preview-pr-255-e08efa3c, with updated comments noting the temporary preview pin and expected revert path.
Regression test helpers and suite
test/regression/issue/21134.test.ts
Adds run(code) and errorInfo(code) helpers that spawn bunExe() and collect stdout/stderr/exit code. A concurrent describe block covers for-of, for-await-of, array destructuring, yield*, and array spread against null/undefined, asserting that e.line correctly identifies the offending statement and not a preceding sentinel. A final test reproduces the original const undefined inlining scenario and asserts the error location and exit code 1.

Possibly related PRs

  • oven-sh/bun#31169: Updates the same WEBKIT_VERSION constant in scripts/build/deps/webkit.ts to a different WebKit autobuild reference.
  • oven-sh/bun#31649: Also updates WEBKIT_VERSION to an autobuild-preview-pr-… style tag, the same pattern used in this PR.
  • oven-sh/bun#32414: Updates the same WEBKIT_VERSION pin in scripts/build/deps/webkit.ts.

Suggested reviewers

  • Jarred-Sumner
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is mostly complete but misses the WebKit version-pin change and incorrectly says WEBKIT_VERSION is untouched. Add a concise What does this PR do? summary covering both the preview WebKit pin and the regression test, then keep the verification section.
✅ 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 matches the main change: adding a regression test for TypeError source locations in iterator and spread cases.

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

@robobun

robobun commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 1:03 AM PT - Jul 1st, 2026

@robobun, your commit 842047e has 2 failures in Build #67463 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 32442

That installs a local version of the PR into your bun-32442 executable, so you can run:

bun-32442 --bun

Comment thread test/regression/issue/21134.test.ts
Comment thread test/regression/issue/21134.test.ts Outdated

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the nits — test looks good now. Deferring to a human since this bumps WEBKIT_VERSION (and to a temporary preview pin that still needs swapping to a main autobuild SHA before merge).

Extended reasoning...

Overview

This PR changes two files:

  • scripts/build/deps/webkit.ts: bumps WEBKIT_VERSION from 09f04cd5a4... to autobuild-preview-pr-255-38cbbb3e, a temporary preview build of oven-sh/WebKit#255. The comment in the file (and the PR description) explicitly says this must be swapped to a main autobuild SHA before merging.
  • test/regression/issue/21134.test.ts: new regression test covering error-location attribution for for-of, for-await-of, array destructuring, yield*, and array spread over null/undefined.

The actual fix lives in JavaScriptCore (oven-sh/WebKit#255), not in this repo.

Prior review

I left two nits on the previous revision; both are now resolved:

  • describe.concurrent — applied in 9856b98.
  • Call/construct spread coverage — author explained those OpSpread paths are defensive-only and not observable (callee resolution already emits expression info), so a test would pass on unpatched builds and gate nothing. Reasonable.

No new issues found in the current revision.

Security risks

None. The bun-side diff is a version-pin string change plus a read-only test that spawns bun -e subprocesses. No auth, crypto, network, or filesystem-write surface.

Level of scrutiny

High — needs human review. While the bun-side diff is small and the test is well-constructed, WEBKIT_VERSION controls which JavaScriptCore build the entire runtime links against. Any WebKit bump can affect correctness/perf across the whole engine and warrants a maintainer's sign-off, independent of how targeted the upstream patch is. Additionally, the pin is currently a PR preview build, not a merged main SHA — the author flagged this themselves as needing a swap before merge, so the PR is not in its final mergeable state yet.

Other factors

  • Test quality is good: uses eval to bypass Bun's transpiler for the JSC-specific cases, plus one end-to-end case for the original const-inlining repro; handles the debug-build performIteration builtin frame for spread; uses describe.concurrent per repo convention.
  • CI build #63008 is referenced but I can't verify its status here; a human should confirm it's green across platforms given this is a JSC bump.

@robobun
robobun force-pushed the farm/0838e1fb/fix-21134-forof-error-location branch from 9856b98 to 80fb408 Compare June 17, 2026 06:29
@robobun

robobun commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (which bumped WEBKIT_VERSION to cd821fecca via #32437). oven-sh/WebKit#255 has been rebased onto that same commit; the new preview tag is autobuild-preview-pr-255-e08efa3c. CI here will 404 on the WebKit download until that preview build publishes (~1h).

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test file looks good and prior nits are resolved, but I'm deferring to a human since the actual fix lives in oven-sh/WebKit#255 (not reviewable from this repo) and WEBKIT_VERSION is still pinned to a preview tag that the description says must be swapped to a main autobuild SHA before merging.

Extended reasoning...

Overview

This PR has two parts: (1) a one-line change to scripts/build/deps/webkit.ts that re-pins WEBKIT_VERSION from a main autobuild SHA to autobuild-preview-pr-255-e08efa3c, a preview build of the not-yet-merged oven-sh/WebKit#255; and (2) a new regression test test/regression/issue/21134.test.ts covering error-location attribution for for-of, for-await-of, array destructuring, yield*, and array spread over null/undefined. The substantive fix — adding emitExpressionInfo calls in JSC's BytecodeGenerator — lives entirely in the WebKit fork and is not part of this diff.

Security risks

None identified. The change is a dependency-version pin plus a test file that spawns bun -e subprocesses with fixed string literals; there is no auth, crypto, network, or untrusted-input handling involved.

Level of scrutiny

High. WEBKIT_VERSION selects the JavaScriptCore build that all of Bun links against — it is effectively the most load-bearing dependency in the project, and the diff being small does not make the change low-risk. More importantly, the code I would actually need to review (the BytecodeGenerator.cpp changes in oven-sh/WebKit#255) is not in this repository, so I cannot independently assess correctness of the fix from here. A human who can look at the WebKit-side diff should sign off.

Other factors

  • The pin is explicitly temporary: both the PR description and the inline comment in webkit.ts say to swap it for a main autobuild SHA once oven-sh/WebKit#255 merges. The PR is therefore not in a mergeable state by its own stated criteria, which by itself rules out bot approval.
  • Both of my earlier inline nits are resolved: describe.concurrent was applied in 9856b98, and the author gave a convincing explanation for why call/construct spread tests would not gate anything (those paths already inherit correct expression info and the WebKit-side change there is defensive only).
  • The regression test itself is well-constructed — it uses eval to bypass Bun's transpiler for the JSC-only cases, asserts on e.line / stack frames rather than brittle full-message snapshots, handles the performIteration builtin frame in debug builds, and includes the original const-inlining repro as an end-to-end check. I have no further concerns about the test file.
  • No bugs were found by the bug-hunting system on this revision.

@robobun
robobun force-pushed the farm/0838e1fb/fix-21134-forof-error-location branch from 80fb408 to 51f6f28 Compare June 28, 2026 01:12
@robobun

robobun commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main again to resolve the conflict. main's WEBKIT_VERSION moved from cd821fecca to f72c0151, which picks up oven-sh/WebKit#252 (the AsyncLocalStorage top-level-await fix from #32184). Re-pinning to the previous preview tag would have silently dropped that fix, so I rebased oven-sh/WebKit#255 onto f72c0151 first. This PR now pins autobuild-preview-pr-255-1997f12e, which is current oven-sh/WebKit main plus the one bytecode-generator commit.

CI here will 404 on the WebKit download until that preview build publishes.

@robobun

robobun commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator Author

Build 65945 failed only on HTTP 404 for autobuild-preview-pr-255-1997f12e on every lane; there are no bun-side failures. The preview had not published because its oven-sh/WebKit run lost one arm64-musl job to a runner failure, which cancelled the rest of the musl matrix (details on oven-sh/WebKit#255). I dispatched a fresh preview build for the same sha; once it publishes, this PR needs one CI re-run and no code changes.

@robobun

robobun commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator Author

The WebKit preview (autobuild-preview-pr-255-1997f12e) has published, so the 404s are gone. abb8033830 is an empty commit to re-run CI against it (build 66096, running); there are no source changes since the last review. Once this is green, what remains is merging oven-sh/WebKit#255 and then swapping the temporary preview pin here for an oven-sh/WebKit main autobuild SHA.

@robobun

robobun commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator Author

Build 66096 is the first run against the published preview, and the diff itself is green: 244 jobs passed, and test/regression/issue/21134.test.ts is not involved in any failure on any lane.

The remaining red is unrelated to this PR:

  • The only hard job failure (alpine 3.23 x64 - test-bun) is test/js/sql/sql-mysql.auth.test.ts erroring inside the MySQL docker harness (test/docker/index.ts, "Unhandled error between tests"). Nothing in this PR touches that subsystem.
  • bun-install-security-provider.test.ts (timeout, Windows aarch64) and bundler_compile.test.ts (disk cache log ordering, macOS 13) appear only in CI's flaky annotation and recovered on retry with the same binary, so they are not deterministic effects of the WebKit change.
  • 4 jobs expired waiting for an agent (binary-size, darwin aarch64 - build-rust, linux x64-musl-baseline - build-cpp, windows x64-baseline - build-cpp) and cascaded 37 dependent jobs into waiting_failed; none of them executed any code.

I am not pushing further empty commits to re-roll CI. To land this: re-run the expired lanes (or rebuild), merge oven-sh/WebKit#255, and swap WEBKIT_VERSION here from the temporary preview tag to an oven-sh/WebKit main autobuild SHA that contains it.

JavaScriptCore attributed the TypeError thrown while getting
[Symbol.iterator] (for-of, for-await-of, array destructuring, yield*)
or spreading a null/undefined subject to the previous statement's
expression range whenever the subject emitted no expression info of its
own, such as a literal, including the one Bun produces by inlining
`const a = undefined`.

The fix landed upstream in WebKit/WebKit#67762 and is included in the
WEBKIT_VERSION this branch now sits on (c9ad5813fd23), so this adds the
Bun-side regression coverage for all five constructs plus the original
report's repro.

Fixes #21134
@robobun
robobun force-pushed the farm/0838e1fb/fix-21134-forof-error-location branch from abb8033 to 842047e Compare July 1, 2026 03:34
@robobun robobun changed the title Fix error location for for-of/destructuring/yield*/spread over null/undefined Add regression test for iterator and spread TypeError source locations Jul 1, 2026
@robobun

robobun commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Resolved the conflict by taking main's scripts/build/deps/webkit.ts as is and dropping the preview pin: main's WEBKIT_VERSION (c9ad5813fd23, from #33133) already contains the JavaScriptCore fix, which landed upstream in WebKit/WebKit#67762 (oven-sh/WebKit#255 was closed as superseded by it). I also squashed the branch, so the PR is now a single commit adding test/regression/issue/21134.test.ts and nothing else.

Verified on this branch: bun bd test test/regression/issue/21134.test.ts passes 6/6 against main's WebKit, and the same file fails 6/6 under USE_SYSTEM_BUN=1 (released 1.4.0, which predates the upgrade). Title and description updated to match.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — now a test-only addition since the WebKit pin was dropped after the fix landed on main.

Extended reasoning...

Overview

This PR now touches a single file: test/regression/issue/21134.test.ts, a new 99-line regression test covering error source-location reporting for for-of, for-await-of, array destructuring, yield*, and array spread over null/undefined. The scripts/build/deps/webkit.ts change that earlier revisions carried (the temporary autobuild-preview-pr-255-* pin) is no longer in the diff — the branch was rebased onto a main whose WEBKIT_VERSION already contains the oven-sh/WebKit#255 fix, so this is purely a test addition with zero production/src/ changes.

Security risks

None. The change adds test code only; it spawns bunExe() subprocesses with fixed inline source strings via -e, uses bunEnv, and touches no auth, crypto, network, filesystem, or parsing surface.

Level of scrutiny

Low. Test-only additions that follow harness conventions and don't modify runtime behavior are the lowest-risk category. The tests follow repo conventions: describe.concurrent for independent subprocess spawns, await using proc, Promise.all to drain stdout/stderr/exit concurrently, exact line-number assertions (not just "doesn't crash"), and a debug-build accommodation for the performIteration builtin frame in the spread case. The exit-code assertion comes last per the CLAUDE.md guidance.

Other factors

My two prior nits are resolved: describe.concurrent was applied, and the author gave a well-reasoned explanation for why call/construct spread tests would be vacuous (those paths already inherit expression info from callee resolution and pass on the unpatched build). The bug-hunting system found no issues. The substantive change since my last review — dropping the temporary WebKit preview pin — strictly reduces risk. The actual behavioral fix lives in oven-sh/WebKit and was reviewed there; this PR just pins the regression coverage on the Bun side.

@robobun

robobun commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI result for the test-only head (842047e8, build 67463, finished): 282 jobs passed, 4 failed, and test/regression/issue/21134.test.ts is not involved in any failure on any lane. The 4 red jobs are all unrelated to this PR:

  • darwin 26 aarch64 - test-bun exited during CI bootstrap with buildkite-agent artifact download timed out after 120s for step 'darwin-aarch64-build-bun'; it ran no tests.
  • darwin 14 x64 - test-bun failed on test/js/bun/terminal/terminal.test.ts ("creates subprocess with terminal attached" timed out after 90000ms), a PTY spawn test unrelated to this change.
  • alpine 3.23 x64 - test-bun and alpine 3.23 x64-baseline - test-bun both failed on one file, test/js/node/test/parallel/test-net-connect-memleak.js (assert.strictEqual(collected, true) after globalThis.gc()), an imported Node GC-timing test.
  • The binary-size annotation reports every binary at +0.0 KB vs main, as expected for a diff with no source changes; the only other flagged tests (Windows hot.test.ts and terminal-platform-gaps.test.ts) are in the flaky annotation and passed on retry.

I have already used my one empty retrigger commit, so I am leaving CI as is rather than pushing more. The PR is a single regression test on top of main.

@robobun

robobun commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #33133. #21134 is now closed as fixed on main.

@robobun robobun closed this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect line numbers in stack trace on TypeError: undefined is not an object inside a for loop

1 participant