Skip to content

[JSC] A WebAssembly trap's RuntimeError and a SuspendError carry no "(evaluating '...')" source text - #642

Open
robobun wants to merge 2 commits into
mainfrom
robobun/3d64169f/wasm-trap-message-no-source-text
Open

robobun wants to merge 2 commits into
mainfrom
robobun/3d64169f/wasm-trap-message-no-source-text

Conversation

@robobun

@robobun robobun commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • The WebAssembly.RuntimeError of a trap ends in (evaluating '<source text>'). The text is that of the nearest JS frame above the wasm frame: some JS caller. With a tail call (() => wasmExport()) it is not even the call into wasm.
  • In bun test, expect(() => div0()).toThrow("nope") passes. The message is Division by zero (evaluating 'expect(() => div0()).toThrow("nope")'), so the expected text is found in the assertion itself.
  • The cause is defaultSourceAppender in createJSWebAssemblyRuntimeError(Wasm::ExceptionType) (JSWebAssemblyRuntimeError.cpp:44) and in createJSWebAssemblySuspendError.

Fix

  • Under USE(BUN_JSC_ADDITIONS), both pass no source appender. The message is the fixed text: Division by zero. The TypeError traps and the stack-overflow RangeError already have no appender.
  • Not changed: CompileError, LinkError, and a RuntimeError created from a message string. There the nearest JS expression is the one that failed.
  • Tests: 34 trap expectations in 18 JSTests/wasm files lose the suffix, with // Bun: comments. BUN-TEST-DIFFERENCES.md gets section A10. The new wasm/stress/trap-message-has-no-source-text.js pins the exact text.
  • Verified on a Debug+ASan build: the new test and the edited files pass. main's jsc fails the new test. The bun tests are in WebAssembly: a trap's RuntimeError and a SuspendError message carry no source text of a JS caller (WebKit bump for oven-sh/WebKit#642) bun#42508.

Background

  • A source appender is a function pointer an ErrorInstance gets at creation. finishCreation appends the source text of the nearest JS frame's current expression. It exists for errors like undefined is not an object (evaluating 'a.b').
  • Bug 166295 added the appender to the wasm error types.
  • node v26.3.0 trap messages are fixed text (divide by zero).
Notes
  • The two gated lines are JSWebAssemblyRuntimeError.cpp:44 and JSWebAssemblySuspendError.cpp:39. catchableFromWasm does not change.
  • The first version of this PR left the upstream tests alone. Since CI: one workflow, planned lanes, toolchain images, and the JavaScriptCore tests #645 the lanes run the JavaScriptCore tests, and JSTests/BUN-TEST-DIFFERENCES.md says how to record a difference on purpose, so the expectations are updated here. The branch is rebased onto main for the same reason (lanes.mjs).
  • wasm/assert.js's throws is a substring check, so the edited expectations pass with and without the engine change. That is why the new test compares e.message exactly. It builds its module from bytes (no wabt) to stay fast.
  • Four files under wasm/v8/ name the suffix only in a comment of a skipped test. They are not changed.
  • No other collection that the lanes run expects the suffix on a trap: I searched JSTests/, LayoutTests/js, LayoutTests/fast/regex and the wasm web-platform-tests for every Wasm::errorMessageForExceptionType text and for the two SuspendError texts.
  • The suffix was also a hint of which JS call entered wasm when the wasm frames have no names. The stack still lists the JS frames under the wasm frames.
  • Host functions of the JS API keep their suffix. When one is called in tail position the suffix is again a caller's text: expect(() => WebAssembly.validate(1)).toThrow("x") passes. A general fix needs a stop at native frames in getBytecodeIndex, and CommonSlowPaths.cpp reads that result unchecked, so it is not part of this change.
  • Upstream WebKit has the same lines. This is a candidate for an upstream bug.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Review Change StackReview 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: 5018d1c2-d134-4e0c-a791-ca4bd3162efb

📥 Commits

Reviewing files that changed from the base of the PR and between d3720d5 and 1663787.

📒 Files selected for processing (22)
  • JSTests/BUN-TEST-DIFFERENCES.md
  • JSTests/wasm/function-references/ref_as_non_null.js
  • JSTests/wasm/function-tests/memcpy-wasm-loop.js
  • JSTests/wasm/function-tests/trap-load-2.js
  • JSTests/wasm/ipint-tests/ipint-error-check-call-null.js
  • JSTests/wasm/ipint-tests/ipint-error-check-call-sig.js
  • JSTests/wasm/ipint-tests/ipint-error-check-div-0.js
  • JSTests/wasm/ipint-tests/ipint-error-check-mem-outofbounds.js
  • JSTests/wasm/ipint-tests/ipint-error-check-trunc-outofbounds.js
  • JSTests/wasm/ipint-tests/ipint-error-check-unreachable.js
  • JSTests/wasm/ipint-tests/ipint-test-data-drop.js
  • JSTests/wasm/ipint-tests/ipint-test-elem-drop.js
  • JSTests/wasm/references/func_ref.js
  • JSTests/wasm/references/multitable.js
  • JSTests/wasm/references/table_misc.js
  • JSTests/wasm/stress/js-to-wasm-calls-wrong-memory-mode.js
  • JSTests/wasm/stress/memory64-write-to-address-over-4-gigs.js
  • JSTests/wasm/stress/table-get-funcref.js
  • JSTests/wasm/stress/trap-message-has-no-source-text.js
  • JSTests/wasm/stress/trunc-int-min-minus-one.js
  • Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp
  • Source/JavaScriptCore/wasm/js/JSWebAssemblySuspendError.cpp

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


Walkthrough

Changes

Bun WebAssembly runtime and suspend errors now omit upstream source-text suffixes. WebAssembly tests expect the shorter messages, and the test-difference guide documents the behavior as intentional.

Wasm trap message alignment

Layer / File(s) Summary
Runtime error formatting
Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp, Source/JavaScriptCore/wasm/js/JSWebAssemblySuspendError.cpp
Bun builds create WebAssembly runtime and suspend errors without a source appender. Other builds retain the default appender.
Wasm message test coverage
JSTests/wasm/function-references/*, JSTests/wasm/function-tests/*, JSTests/wasm/ipint-tests/*, JSTests/wasm/references/*, JSTests/wasm/stress/*
Trap assertions now omit upstream evaluation suffixes. A JSPI stress test verifies source-text-free WebAssembly.RuntimeError and WebAssembly.SuspendError messages.
Intentional difference documentation
JSTests/BUN-TEST-DIFFERENCES.md
The guide records 138 changed tests, adds category A10, lists the affected behavior, and updates the post-sync checklist.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 16637

The WebAssembly trap-message change is covered by matching runtime-specific tests and documentation, with no current merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 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: WebAssembly trap and suspend-error messages no longer include JavaScript source-text suffixes.
Description check ✅ Passed The description gives a detailed problem statement, fix, scope, testing results, affected files, functions, and Bugzilla context. It does not use the exact template format or include a separate review…

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.

@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.

LGTM — a one-argument swap that drops the misleading (evaluating '…') suffix from wasm trap and suspend errors, gated behind USE(BUN_JSC_ADDITIONS).

What was reviewed:

  • Confirmed ErrorInstance::create's SourceAppender parameter defaults to nullptr and finishCreation guards it with hasSourceAppender() before use, so passing nullptr is safe.
  • Both call sites keep every other argument identical (structure, message, useCurrentFrame=true, setCatchableFromWasm(false)), so only the message suffix changes.
  • Upstream behavior is preserved verbatim in the #else branch per this fork's convention.
Extended reasoning...

Overview

This PR touches two files in Source/JavaScriptCore/wasm/js/: JSWebAssemblyRuntimeError.cpp and JSWebAssemblySuspendError.cpp. In each, a single ErrorInstance::create call is duplicated under #if USE(BUN_JSC_ADDITIONS) with the SourceAppender argument changed from defaultSourceAppender to nullptr. The upstream line is kept unchanged in the #else branch. The effect is that WebAssembly trap RuntimeErrors and SuspendErrors no longer append (evaluating '<nearest JS caller source>') to their message under Bun builds.

Security risks

None. This is purely an error-message-formatting change. No memory management, no control flow, no user-controlled input handling is altered. nullptr is the declared default for the SourceAppender parameter (ErrorInstance.h:59), and ErrorInstance::finishCreation checks hasSourceAppender() (!!m_sourceAppender) before dereferencing it (ErrorInstance.cpp:185), so there is no null-deref risk.

Level of scrutiny

Low. The diff is two effective lines, each swapping one argument to a well-established default value. The change is guarded by the fork's standard USE(BUN_JSC_ADDITIONS) macro so upstream/non-Bun builds are byte-identical. The rationale (the appended source text names an unrelated JS caller, which pollutes toThrow matchers) is sound and matches how throwWasmToJSException already constructs the TypeError/RangeError trap variants without an appender.

Other factors

The repo's CODEOWNERS lists /Source/JavaScriptCore @ WebKit/jsc-reviewers, but that file is inherited verbatim from upstream Apple WebKit and explicitly states contributors do not "own" components — it exists for upstream auto-review assignment and references a team that does not exist in this fork. Every change to this fork touches Source/JavaScriptCore, so treating it as a hard ownership gate would be meaningless here. Given the change is mechanical, self-contained, and follows the fork's established #if USE(BUN_JSC_ADDITIONS) pattern, approval is appropriate.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Preview build of 1663787: autobuild-preview-pr-642-16637873

…(evaluating '...')" source text

Both are created with defaultSourceAppender (bug 166295 added it to the
wasm error types). ErrorInstance::finishCreation then walks up from the
wasm frame to the nearest JS frame that has a CodeBlock and appends the
source text of the expression at that frame's bytecode index. That text
names some JS caller. It says nothing about the trap. With a call in tail
position (`() => wasmExport()` in strict code) it is not even the call
that entered wasm. In `expect(() => trap()).toThrow("nope")` the suffix is
the text of the assertion itself, so the assertion can never fail.

Under USE(BUN_JSC_ADDITIONS), pass no source appender in
createJSWebAssemblyRuntimeError(Wasm::ExceptionType) and in
createJSWebAssemblySuspendError. The traps that throw a TypeError or a
stack-overflow RangeError from throwWasmToJSException already have no
suffix. CompileError, LinkError and the RuntimeErrors created from a
message string (instantiation, Global.prototype.value) keep it: there the
nearest JS expression is the one that failed.
…t that pins the text

The lanes run the JavaScriptCore tests (#645), and JSTests/BUN-TEST-DIFFERENCES.md
says how to record a difference that is on purpose.

- 34 trap expectations in 18 JSTests/wasm files lose " (evaluating '...')".
  Each change has a `// Bun:` comment with the suffix upstream expects.
  assert.js's `throws` is a substring check, so they also pass on upstream.
- BUN-TEST-DIFFERENCES.md gets section A10 with the fork code, how to
  recognize the difference, and the file list.
- wasm/stress/trap-message-has-no-source-text.js compares `e.message` exactly
  for a trap (tail call, statement call, direct reference, unreachable) and
  for a SuspendError. It fails without the engine change. It builds its
  module from bytes, so it needs no wabt.
@robobun
robobun force-pushed the robobun/3d64169f/wasm-trap-message-no-source-text branch from a9e2b20 to 1663787 Compare September 16, 2026 05:01

@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.

Code review found no issues

No high-confidence issues detected in this change.

2 verified lower-impact observations (convention, logging or cleanup points) were not posted.

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.

1 participant