diff --git a/JSTests/BUN-TEST-DIFFERENCES.md b/JSTests/BUN-TEST-DIFFERENCES.md index d5f89acbbcc4e..13077324e7e1d 100644 --- a/JSTests/BUN-TEST-DIFFERENCES.md +++ b/JSTests/BUN-TEST-DIFFERENCES.md @@ -1,10 +1,10 @@ # Where this fork's tests differ from upstream's, and why -`JSTests/`, `LayoutTests/js` and the PerformanceTests collections are upstream's tests. This fork changes 120 of them and +`JSTests/`, `LayoutTests/js` and the PerformanceTests collections are upstream's tests. This fork changes 138 of them and three runner scripts. Every change is listed here by the reason for it, so that after an upstream sync a failing test can be sorted into one of three piles: -1. **The fork behaves differently on purpose.** Update the expectation. Sections A1–A9 list every such behavior, how to +1. **The fork behaves differently on purpose.** Update the expectation. Sections A1–A10 list every such behavior, how to recognize it in a failure, and the fork code that causes it. If a failure matches one of these and the fork code is still there, the test is the thing to change. 2. **The test cannot pass in a mode or build we run.** Skip it in that mode only, with the reason. Section B. @@ -113,6 +113,29 @@ Rules for an edit to an upstream test: - Fork code: `DecoderStringTable::jsStringFor` (`runtime/CachedTypes.h:132`): loading a cache interns nothing. - File: `stress/jsstring-definitely-atom-bit.js`: `$skipModes << "bytecode-cache"`. The other modes run it unchanged. +### A10. A wasm trap's message has no `(evaluating '...')` source text + +- Upstream: `Division by zero (evaluating 'test(1, 0)')`. The text is that of the nearest JS frame above the wasm frame, + so it names some JS caller, not the trap. When the call into wasm is a tail call it is the caller's caller: + `expect(() => trap()).toThrow("nope")` finds `nope` in its own source text and can never fail. Node and V8 print fixed + text (`divide by zero`). +- Fork code: `createJSWebAssemblyRuntimeError(JSGlobalObject*, VM&, Wasm::ExceptionType)` + (`wasm/js/JSWebAssemblyRuntimeError.cpp:44`) and `createJSWebAssemblySuspendError` + (`wasm/js/JSWebAssemblySuspendError.cpp:39`) pass no source appender under `USE(BUN_JSC_ADDITIONS)`. +- Recognize: a `WebAssembly.RuntimeError` whose message is one of `Wasm::errorMessageForExceptionType`'s + (`wasm/WasmExceptionType.h`), or a `WebAssembly.SuspendError`, and the only difference is the missing suffix. + `CompileError`, `LinkError` and a `RuntimeError` made from a message string (instantiation, `Global.prototype.value`) + keep the suffix, as upstream. +- Files (18), all under `wasm/`. Only the suffix is removed from each expectation (34): + - `function-references/ref_as_non_null.js`, `function-tests/memcpy-wasm-loop.js`, `function-tests/trap-load-2.js` + - `ipint-tests/`: `ipint-error-check-call-null.js`, `-call-sig.js`, `-div-0.js`, `-mem-outofbounds.js`, + `-trunc-outofbounds.js`, `-unreachable.js`, `ipint-test-data-drop.js`, `ipint-test-elem-drop.js` + - `references/func_ref.js` (2), `references/multitable.js` (9), `references/table_misc.js` (3) + - `stress/js-to-wasm-calls-wrong-memory-mode.js`, `stress/memory64-write-to-address-over-4-gigs.js`, + `stress/table-get-funcref.js`, `stress/trunc-int-min-minus-one.js` (6) +- `wasm/assert.js`'s `throws` is a substring check, so these expectations also pass on upstream. The exact text is + pinned by `wasm/stress/trap-message-has-no-source-text.js`. + --- ## B. The test cannot pass in a mode or build we run: narrowed, not changed @@ -154,7 +177,7 @@ Rules for an edit to an upstream test: ## E. After a sync: a failing test, step by step -1. Does the difference match A1–A9 exactly (same text, same shape)? Check that the fork code named there is still in the +1. Does the difference match A1–A10 exactly (same text, same shape)? Check that the fork code named there is still in the tree, then update the expectation with a `// Bun:` comment and add the file to its list here. 2. Does it fail only in one mode or only with ASan, for a reason in the test and not the engine (it counts JIT compiles, depends on allocation never failing, needs more than 300 s)? Narrow it as in B. diff --git a/JSTests/wasm/function-references/ref_as_non_null.js b/JSTests/wasm/function-references/ref_as_non_null.js index 01ed724dcc62c..3cbe56bddeb6c 100644 --- a/JSTests/wasm/function-references/ref_as_non_null.js +++ b/JSTests/wasm/function-references/ref_as_non_null.js @@ -37,7 +37,8 @@ async function ref_as_non_null() { assert.throws( () => new WebAssembly.Instance(module("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x8e\x80\x80\x80\x00\x03\x60\x00\x00\x60\x00\x01\x63\x00\x60\x00\x01\x64\x00\x03\x84\x80\x80\x80\x00\x03\x00\x01\x02\x07\x88\x80\x80\x80\x00\x01\x04\x6d\x61\x69\x6e\x00\x02\x09\x87\x80\x80\x80\x00\x01\x07\x70\x01\xd2\x00\x0b\x0a\x9b\x80\x80\x80\x00\x03\x82\x80\x80\x80\x00\x00\x0b\x84\x80\x80\x80\x00\x00\xd0\x00\x0b\x85\x80\x80\x80\x00\x00\x10\x01\xd4\x0b")).exports.main(), WebAssembly.RuntimeError, - "ref.as_non_null to a null reference (evaluating 'func(...args)')" + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')". + "ref.as_non_null to a null reference" ) } diff --git a/JSTests/wasm/function-tests/memcpy-wasm-loop.js b/JSTests/wasm/function-tests/memcpy-wasm-loop.js index f1741a6c2b56b..ab565c2d8fc62 100644 --- a/JSTests/wasm/function-tests/memcpy-wasm-loop.js +++ b/JSTests/wasm/function-tests/memcpy-wasm-loop.js @@ -84,7 +84,8 @@ for (let i = 15; i < 20; i++) { assert.eq(i32[i], i); } -assert.throws(() => $1.exports.do_memcpy(0,16384-5,6), Error, "Out of bounds memory access (evaluating 'func(...args)')") +// Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')". +assert.throws(() => $1.exports.do_memcpy(0,16384-5,6), Error, "Out of bounds memory access") for (let i = 0; i < 5; i++) { assert.eq(i32[16384-5 + i], i); } diff --git a/JSTests/wasm/function-tests/trap-load-2.js b/JSTests/wasm/function-tests/trap-load-2.js index a4c695e5079f9..c2c66d6a20d49 100644 --- a/JSTests/wasm/function-tests/trap-load-2.js +++ b/JSTests/wasm/function-tests/trap-load-2.js @@ -66,7 +66,8 @@ function wasmFrameCountFromError(e) { } for (let i = 0; i < 5000; i++) { - const e = assert.throws(() => foo(5, address), WebAssembly.RuntimeError, "Out of bounds memory access (evaluating 'foo(x - 1, address)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'foo(x - 1, address)')". + const e = assert.throws(() => foo(5, address), WebAssembly.RuntimeError, "Out of bounds memory access"); // There are 5 total calls, and each call does: // JS entry, wasm entry, js call stub. // The last call that traps just has JS entry and wasm entry. diff --git a/JSTests/wasm/ipint-tests/ipint-error-check-call-null.js b/JSTests/wasm/ipint-tests/ipint-error-check-call-null.js index adb1e57e62a71..fab0a100d9d52 100644 --- a/JSTests/wasm/ipint-tests/ipint-error-check-call-null.js +++ b/JSTests/wasm/ipint-tests/ipint-error-check-call-null.js @@ -21,7 +21,8 @@ let wat = ` async function test() { const instance = await instantiate(wat, {}); const { table, read, write_null, write_inc, call, inc } = instance.exports - assert.throws(() => {call(5)}, WebAssembly.RuntimeError, "call_indirect to a signature that does not match (evaluating 'call(5)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'call(5)')". + assert.throws(() => {call(5)}, WebAssembly.RuntimeError, "call_indirect to a signature that does not match"); } await assert.asyncTest(test()) diff --git a/JSTests/wasm/ipint-tests/ipint-error-check-call-sig.js b/JSTests/wasm/ipint-tests/ipint-error-check-call-sig.js index a82b8718dc833..c0d0e563b02cf 100644 --- a/JSTests/wasm/ipint-tests/ipint-error-check-call-sig.js +++ b/JSTests/wasm/ipint-tests/ipint-error-check-call-sig.js @@ -28,7 +28,8 @@ async function test() { const instance = await instantiate(wat, {}); const { table, read, write_null, write_inc, call, inc } = instance.exports write_inc(); - assert.throws(() => {call(5)}, WebAssembly.RuntimeError, "call_indirect to a signature that does not match (evaluating 'call(5)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'call(5)')". + assert.throws(() => {call(5)}, WebAssembly.RuntimeError, "call_indirect to a signature that does not match"); } await assert.asyncTest(test()) diff --git a/JSTests/wasm/ipint-tests/ipint-error-check-div-0.js b/JSTests/wasm/ipint-tests/ipint-error-check-div-0.js index dcff6619e7692..fb71cee0b249d 100644 --- a/JSTests/wasm/ipint-tests/ipint-error-check-div-0.js +++ b/JSTests/wasm/ipint-tests/ipint-error-check-div-0.js @@ -15,7 +15,8 @@ let wat = ` async function test() { const instance = await instantiate(wat, {}); const { test } = instance.exports - assert.throws(() => {test(1, 0)}, WebAssembly.RuntimeError, "Division by zero (evaluating 'test(1, 0)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'test(1, 0)')". + assert.throws(() => {test(1, 0)}, WebAssembly.RuntimeError, "Division by zero"); } await assert.asyncTest(test()) diff --git a/JSTests/wasm/ipint-tests/ipint-error-check-mem-outofbounds.js b/JSTests/wasm/ipint-tests/ipint-error-check-mem-outofbounds.js index 0f57ae5b5d21d..9c18b6fc3f44d 100644 --- a/JSTests/wasm/ipint-tests/ipint-error-check-mem-outofbounds.js +++ b/JSTests/wasm/ipint-tests/ipint-error-check-mem-outofbounds.js @@ -16,7 +16,8 @@ let wat = ` async function test() { const instance = await instantiate(wat, {}); const { memory, test } = instance.exports - assert.throws(() => {test(65536)}, WebAssembly.RuntimeError, "Out of bounds memory access (evaluating 'test(65536)')") + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'test(65536)')". + assert.throws(() => {test(65536)}, WebAssembly.RuntimeError, "Out of bounds memory access") } await assert.asyncTest(test()) diff --git a/JSTests/wasm/ipint-tests/ipint-error-check-trunc-outofbounds.js b/JSTests/wasm/ipint-tests/ipint-error-check-trunc-outofbounds.js index d8f5dc78eedef..fdf580049fe7d 100644 --- a/JSTests/wasm/ipint-tests/ipint-error-check-trunc-outofbounds.js +++ b/JSTests/wasm/ipint-tests/ipint-error-check-trunc-outofbounds.js @@ -13,7 +13,8 @@ let wat = ` async function test() { const instance = await instantiate(wat, {}); const { memory, test } = instance.exports - assert.throws(() => {test(4294967296)}, WebAssembly.RuntimeError, "Out of bounds Trunc operation (evaluating 'test(4294967296)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'test(4294967296)')". + assert.throws(() => {test(4294967296)}, WebAssembly.RuntimeError, "Out of bounds Trunc operation"); } await assert.asyncTest(test()) diff --git a/JSTests/wasm/ipint-tests/ipint-error-check-unreachable.js b/JSTests/wasm/ipint-tests/ipint-error-check-unreachable.js index ca25e165f8038..dadd4b69d2a85 100644 --- a/JSTests/wasm/ipint-tests/ipint-error-check-unreachable.js +++ b/JSTests/wasm/ipint-tests/ipint-error-check-unreachable.js @@ -13,7 +13,8 @@ let wat = ` async function test() { const instance = await instantiate(wat, {}); const { test } = instance.exports - assert.throws(() => {test()}, WebAssembly.RuntimeError, "Unreachable code should not be executed (evaluating 'test()')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'test()')". + assert.throws(() => {test()}, WebAssembly.RuntimeError, "Unreachable code should not be executed"); } await assert.asyncTest(test()) diff --git a/JSTests/wasm/ipint-tests/ipint-test-data-drop.js b/JSTests/wasm/ipint-tests/ipint-test-data-drop.js index 9408572d175e2..a8d0c6cfc4426 100644 --- a/JSTests/wasm/ipint-tests/ipint-test-data-drop.js +++ b/JSTests/wasm/ipint-tests/ipint-test-data-drop.js @@ -33,7 +33,8 @@ async function test() { init(0, 0, 69); assert.eq(decodeString(memory.buffer), "the option is whether or not to let failure be the last thing you do."); yeet(); - assert.throws(() => {init(0, 0, 5)}, WebAssembly.RuntimeError, "Out of bounds memory access (evaluating 'init(0, 0, 5)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'init(0, 0, 5)')". + assert.throws(() => {init(0, 0, 5)}, WebAssembly.RuntimeError, "Out of bounds memory access"); } await assert.asyncTest(test()) diff --git a/JSTests/wasm/ipint-tests/ipint-test-elem-drop.js b/JSTests/wasm/ipint-tests/ipint-test-elem-drop.js index f628b3def51f3..73392cfcb4427 100644 --- a/JSTests/wasm/ipint-tests/ipint-test-elem-drop.js +++ b/JSTests/wasm/ipint-tests/ipint-test-elem-drop.js @@ -45,7 +45,8 @@ async function test() { assert.eq(read(), 0); assert.eq(call(5), 6); drop(); - assert.throws(() => {init(0, 0, 1)}, WebAssembly.RuntimeError, "Out of bounds table access (evaluating 'init(0, 0, 1)'") + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'init(0, 0, 1)'". + assert.throws(() => {init(0, 0, 1)}, WebAssembly.RuntimeError, "Out of bounds table access") } await assert.asyncTest(test()) diff --git a/JSTests/wasm/references/func_ref.js b/JSTests/wasm/references/func_ref.js index f78124d3b161f..edcf994c1394f 100644 --- a/JSTests/wasm/references/func_ref.js +++ b/JSTests/wasm/references/func_ref.js @@ -314,11 +314,13 @@ assert.throws(() => new WebAssembly.Module((new Builder()) const ident = makeExportedIdent(); $1.exports.set_glob($1.exports.ret_20); assert.eq($1.exports.get_glob(), $1.exports.ret_20); assert.eq($1.exports.call_glob(42), 20) - $1.exports.set_glob(null); assert.eq($1.exports.get_glob(), null); assert.throws(() => $1.exports.call_glob(42), Error, "call_indirect to a signature that does not match (evaluating 'func(...args)')") + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')". + $1.exports.set_glob(null); assert.eq($1.exports.get_glob(), null); assert.throws(() => $1.exports.call_glob(42), Error, "call_indirect to a signature that does not match") $1.exports.set_glob(ident); assert.eq($1.exports.get_glob(), ident); assert.eq($1.exports.call_glob(42), 42) assert.throws(() => $1.exports.set_glob(fun), TypeError, "Argument value did not match the reference type") - $1.exports.set_glob(myfun); assert.eq($1.exports.get_glob(), myfun); assert.throws(() => $1.exports.call_glob(42), Error, "call_indirect to a signature that does not match (evaluating 'func(...args)')") + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')". + $1.exports.set_glob(myfun); assert.eq($1.exports.get_glob(), myfun); assert.throws(() => $1.exports.call_glob(42), Error, "call_indirect to a signature that does not match") for (let i=0; i<1000; ++i) { assert.throws(() => $1.exports.set_glob(function() {}), TypeError, "Argument value did not match the reference type"); diff --git a/JSTests/wasm/references/multitable.js b/JSTests/wasm/references/multitable.js index ba750868b97d6..5d1fe05ab411c 100644 --- a/JSTests/wasm/references/multitable.js +++ b/JSTests/wasm/references/multitable.js @@ -54,8 +54,9 @@ import Builder from '../Builder.js'; assert.eq($1.exports.tbl.get(0), "hi") assert.eq($1.exports.tbl.get(1), null) - assert.throws(() => $1.exports.get_tbl0(), Error, "Out of bounds table access (evaluating 'func(...args)')"); - assert.throws(() => $1.exports.set_tbl0(null), Error, "Out of bounds table access (evaluating 'func(...args)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')" on each. + assert.throws(() => $1.exports.get_tbl0(), Error, "Out of bounds table access"); + assert.throws(() => $1.exports.set_tbl0(null), Error, "Out of bounds table access"); } { @@ -110,8 +111,9 @@ import Builder from '../Builder.js'; assert.eq($1.exports.tbl.get(0), "hi") assert.eq($1.exports.tbl.get(1), null) - assert.throws(() => $1.exports.get_tbl0(), Error, "Out of bounds table access (evaluating 'func(...args)')"); - assert.throws(() => $1.exports.set_tbl0(null), Error, "Out of bounds table access (evaluating 'func(...args)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')" on each. + assert.throws(() => $1.exports.get_tbl0(), Error, "Out of bounds table access"); + assert.throws(() => $1.exports.set_tbl0(null), Error, "Out of bounds table access"); } { @@ -215,8 +217,9 @@ import Builder from '../Builder.js'; fullGC() assert.eq($1.exports.call_tbl1(0), 42) - assert.throws(() => $1.exports.call_tbl0(0), Error, "call_indirect to a signature that does not match (evaluating 'func(...args)')") - assert.throws(() => $1.exports.call_tbl1(1), Error, "call_indirect to a signature that does not match (evaluating 'func(...args)')") + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')" on each. + assert.throws(() => $1.exports.call_tbl0(0), Error, "call_indirect to a signature that does not match") + assert.throws(() => $1.exports.call_tbl1(1), Error, "call_indirect to a signature that does not match") } { @@ -268,9 +271,10 @@ import Builder from '../Builder.js'; assert.eq($1.exports.call_tbl1(0), 42) assert.eq($1.exports.call_tbl0(0), 1337) assert.eq($1.exports.call_tbl1(1), 256) - assert.throws(() => $1.exports.call_tbl0(1), Error, "call_indirect to a signature that does not match (evaluating 'func(...args)')") - assert.throws(() => $1.exports.call_tbl0(2), Error, "call_indirect to a signature that does not match (evaluating 'func(...args)')") - assert.throws(() => $1.exports.call_tbl1(2), Error, "Out of bounds call_indirect (evaluating 'func(...args)')") + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')" on each. + assert.throws(() => $1.exports.call_tbl0(1), Error, "call_indirect to a signature that does not match") + assert.throws(() => $1.exports.call_tbl0(2), Error, "call_indirect to a signature that does not match") + assert.throws(() => $1.exports.call_tbl1(2), Error, "Out of bounds call_indirect") } assert.throws(() => new WebAssembly.Instance(new WebAssembly.Module((new Builder()) .Type().End() diff --git a/JSTests/wasm/references/table_misc.js b/JSTests/wasm/references/table_misc.js index 2bac85ed7bef9..d7bed08fb7829 100644 --- a/JSTests/wasm/references/table_misc.js +++ b/JSTests/wasm/references/table_misc.js @@ -164,9 +164,10 @@ assert.throws(() => new WebAssembly.Module((new Builder()) assert.eq($1.exports.tbl.get(19), "test") assert.eq($1.exports.tbl.get(18), null) - assert.throws(() => $1.exports.tbl_fill(20,null,1), Error, "Out of bounds table access (evaluating 'func(...args)") - assert.throws(() => $1.exports.tbl_fill(19,null,2), Error, "Out of bounds table access (evaluating 'func(...args)") - assert.throws(() => $1.exports.tbl_fill(4294967295,null,1), Error, "Out of bounds table access (evaluating 'func(...args)") + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)" on each. + assert.throws(() => $1.exports.tbl_fill(20,null,1), Error, "Out of bounds table access") + assert.throws(() => $1.exports.tbl_fill(19,null,2), Error, "Out of bounds table access") + assert.throws(() => $1.exports.tbl_fill(4294967295,null,1), Error, "Out of bounds table access") } assert.throws(() => new WebAssembly.Module((new Builder()) diff --git a/JSTests/wasm/stress/js-to-wasm-calls-wrong-memory-mode.js b/JSTests/wasm/stress/js-to-wasm-calls-wrong-memory-mode.js index d984c0011911c..0330244235c98 100644 --- a/JSTests/wasm/stress/js-to-wasm-calls-wrong-memory-mode.js +++ b/JSTests/wasm/stress/js-to-wasm-calls-wrong-memory-mode.js @@ -27,4 +27,5 @@ let boundsCheckedInstance = new WebAssembly.Instance(wasmModule, { foo: { mem: b for (let i = 0; i < 1e5; ++i) signalingInstance.exports.test(1); -assert.throws(boundsCheckedInstance.exports.test, WebAssembly.RuntimeError, "Out of bounds memory access (evaluating 'func(...args)')", 0); \ No newline at end of file +// Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')". +assert.throws(boundsCheckedInstance.exports.test, WebAssembly.RuntimeError, "Out of bounds memory access", 0); \ No newline at end of file diff --git a/JSTests/wasm/stress/memory64-write-to-address-over-4-gigs.js b/JSTests/wasm/stress/memory64-write-to-address-over-4-gigs.js index 01ea543400148..e77be2e9b5b91 100644 --- a/JSTests/wasm/stress/memory64-write-to-address-over-4-gigs.js +++ b/JSTests/wasm/stress/memory64-write-to-address-over-4-gigs.js @@ -19,7 +19,8 @@ const {write, read} = instance.exports; const writeAddr = BigInt(Number.MAX_SAFE_INTEGER + 1); const outOfBoundsError = [ WebAssembly.RuntimeError, - "Out of bounds memory access (evaluating 'func(...args)')", + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')". + "Out of bounds memory access", ]; function test() { diff --git a/JSTests/wasm/stress/table-get-funcref.js b/JSTests/wasm/stress/table-get-funcref.js index 7ef60250cf0b9..f8f735d949562 100644 --- a/JSTests/wasm/stress/table-get-funcref.js +++ b/JSTests/wasm/stress/table-get-funcref.js @@ -43,7 +43,8 @@ async function test() { set(2, f); assert.eq(get(2), f); - assert.throws(() => get(3), WebAssembly.RuntimeError, "Out of bounds table access (evaluating 'func(...args)')"); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')". + assert.throws(() => get(3), WebAssembly.RuntimeError, "Out of bounds table access"); } await assert.asyncTest(test()); diff --git a/JSTests/wasm/stress/trap-message-has-no-source-text.js b/JSTests/wasm/stress/trap-message-has-no-source-text.js new file mode 100644 index 0000000000000..e44a3650ed7d0 --- /dev/null +++ b/JSTests/wasm/stress/trap-message-has-no-source-text.js @@ -0,0 +1,48 @@ +//@ requireOptions("--useJSPI=1") +import * as assert from "../assert.js"; + +// An error raised under a wasm frame (a trap, a SuspendError) has no JS expression of its own. Its message is the fixed +// text, with no " (evaluating '')" of a JS caller. See JSTests/BUN-TEST-DIFFERENCES.md, A10. + +// (module +// (import "m" "suspending" (func $suspending)) +// (func (export "div0") i32.const 1 i32.const 0 i32.div_s drop) +// (func (export "unreachable") unreachable) +// (func (export "callSuspending") call $suspending)) +const bytes = new Uint8Array([ + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x04, 0x01, 0x60, 0x00, 0x00, + 0x02, 0x10, 0x01, 0x01, 0x6d, 0x0a, 0x73, 0x75, 0x73, 0x70, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, + 0x03, 0x04, 0x03, 0x00, 0x00, 0x00, + 0x07, 0x27, 0x03, + 0x04, 0x64, 0x69, 0x76, 0x30, 0x00, 0x01, + 0x0b, 0x75, 0x6e, 0x72, 0x65, 0x61, 0x63, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x02, + 0x0e, 0x63, 0x61, 0x6c, 0x6c, 0x53, 0x75, 0x73, 0x70, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x00, 0x03, + 0x0a, 0x13, 0x03, + 0x08, 0x00, 0x41, 0x01, 0x41, 0x00, 0x6d, 0x1a, 0x0b, + 0x03, 0x00, 0x00, 0x0b, + 0x04, 0x00, 0x10, 0x00, 0x0b, +]); +const suspending = new WebAssembly.Suspending(async () => { }); +const { div0, unreachable, callSuspending } = new WebAssembly.Instance(new WebAssembly.Module(bytes), { m: { suspending } }).exports; + +function thrownBy(fn) { + try { + fn(); + } catch (e) { + return e; + } + throw new Error("did not throw"); +} + +// In a module a call in tail position leaves no frame: the nearest JS expression is the `fn()` in thrownBy. +const tailCall = thrownBy(() => div0()); +assert.instanceof(tailCall, WebAssembly.RuntimeError); +assert.eq(tailCall.message, "Division by zero"); +assert.eq(thrownBy(() => { div0(); }).message, "Division by zero"); +assert.eq(thrownBy(div0).message, "Division by zero"); +assert.eq(thrownBy(() => unreachable()).message, "Unreachable code should not be executed"); + +const suspendError = thrownBy(() => callSuspending()); +assert.instanceof(suspendError, WebAssembly.SuspendError); +assert.eq(suspendError.message, "Suspending() wrapper called outside of a promising() context"); diff --git a/JSTests/wasm/stress/trunc-int-min-minus-one.js b/JSTests/wasm/stress/trunc-int-min-minus-one.js index 02b33d6dcc232..c0f4b54a63722 100644 --- a/JSTests/wasm/stress/trunc-int-min-minus-one.js +++ b/JSTests/wasm/stress/trunc-int-min-minus-one.js @@ -17,15 +17,17 @@ async function test() { assert.eq(truncS(-2147483648.1), -2147483648); assert.eq(truncS(-2147483648.9), -2147483648); assert.eq(truncS(2147483647.9), 2147483647); - assert.throws(() => truncS(-2147483649), WebAssembly.RuntimeError, `Out of bounds Trunc operation (evaluating 'func(...args)')`); - assert.throws(() => truncS(2147483648), WebAssembly.RuntimeError, `Out of bounds Trunc operation (evaluating 'func(...args)')`); - assert.throws(() => truncS(NaN), WebAssembly.RuntimeError, `Out of bounds Trunc operation (evaluating 'func(...args)')`); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')" on each. + assert.throws(() => truncS(-2147483649), WebAssembly.RuntimeError, `Out of bounds Trunc operation`); + assert.throws(() => truncS(2147483648), WebAssembly.RuntimeError, `Out of bounds Trunc operation`); + assert.throws(() => truncS(NaN), WebAssembly.RuntimeError, `Out of bounds Trunc operation`); assert.eq(truncU(-0.9), 0); assert.eq(truncU(4294967295.9), -1); - assert.throws(() => truncU(-1), WebAssembly.RuntimeError, `Out of bounds Trunc operation (evaluating 'func(...args)')`); - assert.throws(() => truncU(4294967296), WebAssembly.RuntimeError, `Out of bounds Trunc operation (evaluating 'func(...args)')`); - assert.throws(() => truncU(NaN), WebAssembly.RuntimeError, `Out of bounds Trunc operation (evaluating 'func(...args)')`); + // Bun: a trap's message has no source text. Upstream expects the suffix " (evaluating 'func(...args)')" on each. + assert.throws(() => truncU(-1), WebAssembly.RuntimeError, `Out of bounds Trunc operation`); + assert.throws(() => truncU(4294967296), WebAssembly.RuntimeError, `Out of bounds Trunc operation`); + assert.throws(() => truncU(NaN), WebAssembly.RuntimeError, `Out of bounds Trunc operation`); } await assert.asyncTest(test()); diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp index 56eba1476ab03..4e4b25e58e7fa 100644 --- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp +++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp @@ -41,7 +41,12 @@ JSObject* createJSWebAssemblyRuntimeError(JSGlobalObject* globalObject, VM& vm, JSObject* createJSWebAssemblyRuntimeError(JSGlobalObject* globalObject, VM& vm, Wasm::ExceptionType type) { +#if USE(BUN_JSC_ADDITIONS) + // No source appender. A trap is raised under a wasm frame, so the source text it would add is that of some JS caller. + ErrorInstance* error = ErrorInstance::create(vm, globalObject->webAssemblyRuntimeErrorStructure(), Wasm::errorMessageForExceptionType(type), JSValue(), nullptr, TypeNothing, ErrorType::Error, true); +#else ErrorInstance* error = ErrorInstance::create(vm, globalObject->webAssemblyRuntimeErrorStructure(), Wasm::errorMessageForExceptionType(type), JSValue(), defaultSourceAppender, TypeNothing, ErrorType::Error, true); +#endif error->setCatchableFromWasm(false); return error; } diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblySuspendError.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblySuspendError.cpp index 6ff837d9e66a7..eac498c510e6a 100644 --- a/Source/JavaScriptCore/wasm/js/JSWebAssemblySuspendError.cpp +++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblySuspendError.cpp @@ -36,7 +36,12 @@ namespace JSC { JSObject* createJSWebAssemblySuspendError(JSGlobalObject* globalObject, VM& vm, const String& message) { ASSERT(!message.isEmpty()); +#if USE(BUN_JSC_ADDITIONS) + // No source appender. A Suspending import is called from wasm, so the source text it would add is that of some JS caller. + return ErrorInstance::create(vm, globalObject->webAssemblySuspendErrorStructure(), message, JSValue(), nullptr, TypeNothing, ErrorType::Error, true); +#else return ErrorInstance::create(vm, globalObject->webAssemblySuspendErrorStructure(), message, JSValue(), defaultSourceAppender, TypeNothing, ErrorType::Error, true); +#endif } } // namespace JSC