Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions JSTests/BUN-TEST-DIFFERENCES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion JSTests/wasm/function-references/ref_as_non_null.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}

Expand Down
3 changes: 2 additions & 1 deletion JSTests/wasm/function-tests/memcpy-wasm-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion JSTests/wasm/function-tests/trap-load-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion JSTests/wasm/ipint-tests/ipint-error-check-call-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
3 changes: 2 additions & 1 deletion JSTests/wasm/ipint-tests/ipint-error-check-call-sig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
3 changes: 2 additions & 1 deletion JSTests/wasm/ipint-tests/ipint-error-check-div-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Original file line number Diff line number Diff line change
Expand Up @@ -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())
3 changes: 2 additions & 1 deletion JSTests/wasm/ipint-tests/ipint-error-check-unreachable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
3 changes: 2 additions & 1 deletion JSTests/wasm/ipint-tests/ipint-test-data-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
3 changes: 2 additions & 1 deletion JSTests/wasm/ipint-tests/ipint-test-elem-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
6 changes: 4 additions & 2 deletions JSTests/wasm/references/func_ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
22 changes: 13 additions & 9 deletions JSTests/wasm/references/multitable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

{
Expand Down Expand Up @@ -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");
}

{
Expand Down Expand Up @@ -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")
}

{
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions JSTests/wasm/references/table_misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion JSTests/wasm/stress/js-to-wasm-calls-wrong-memory-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// 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);
3 changes: 2 additions & 1 deletion JSTests/wasm/stress/memory64-write-to-address-over-4-gigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion JSTests/wasm/stress/table-get-funcref.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
48 changes: 48 additions & 0 deletions JSTests/wasm/stress/trap-message-has-no-source-text.js
Original file line number Diff line number Diff line change
@@ -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 '<source text>')" 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");
Loading
Loading