Repository navigation
[JSC] A WebAssembly trap's RuntimeError and a SuspendError carry no "(evaluating '...')" source text - #642
[JSC] A WebAssembly trap's RuntimeError and a SuspendError carry no "(evaluating '...')" source text#642robobun wants to merge 2 commits into
Conversation
|
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 (22)
Included review availability: Your plan provides up to 5 included reviews per hour; 1 remains after this review. WalkthroughChangesBun 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
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to 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)
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 |
There was a problem hiding this comment.
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'sSourceAppenderparameter defaults tonullptrandfinishCreationguards it withhasSourceAppender()before use, so passingnullptris 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
#elsebranch 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.
|
Preview build of 1663787: |
…(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.
a9e2b20 to
1663787
Compare
Problem
WebAssembly.RuntimeErrorof 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.bun test,expect(() => div0()).toThrow("nope")passes. The message isDivision by zero (evaluating 'expect(() => div0()).toThrow("nope")'), so the expected text is found in the assertion itself.defaultSourceAppenderincreateJSWebAssemblyRuntimeError(Wasm::ExceptionType)(JSWebAssemblyRuntimeError.cpp:44) and increateJSWebAssemblySuspendError.Fix
USE(BUN_JSC_ADDITIONS), both pass no source appender. The message is the fixed text:Division by zero. TheTypeErrortraps and the stack-overflowRangeErroralready have no appender.CompileError,LinkError, and aRuntimeErrorcreated from a message string. There the nearest JS expression is the one that failed.JSTests/wasmfiles lose the suffix, with// Bun:comments.BUN-TEST-DIFFERENCES.mdgets section A10. The newwasm/stress/trap-message-has-no-source-text.jspins the exact text.main'sjscfails 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
ErrorInstancegets at creation.finishCreationappends the source text of the nearest JS frame's current expression. It exists for errors likeundefined is not an object (evaluating 'a.b').divide by zero).Notes
JSWebAssemblyRuntimeError.cpp:44andJSWebAssemblySuspendError.cpp:39.catchableFromWasmdoes not change.JSTests/BUN-TEST-DIFFERENCES.mdsays how to record a difference on purpose, so the expectations are updated here. The branch is rebased ontomainfor the same reason (lanes.mjs).wasm/assert.js'sthrowsis a substring check, so the edited expectations pass with and without the engine change. That is why the new test comparese.messageexactly. It builds its module from bytes (no wabt) to stay fast.wasm/v8/name the suffix only in a comment of a skipped test. They are not changed.JSTests/,LayoutTests/js,LayoutTests/fast/regexand the wasm web-platform-tests for everyWasm::errorMessageForExceptionTypetext and for the twoSuspendErrortexts.expect(() => WebAssembly.validate(1)).toThrow("x")passes. A general fix needs a stop at native frames ingetBytecodeIndex, andCommonSlowPaths.cppreads that result unchecked, so it is not part of this change.