Skip to content

Commit

Permalink
Add test from mstarzinger.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Jul 14, 2021
1 parent 0b1b6f2 commit c87460d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions wasm/jsapi/exceptions/basic.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,27 @@ promise_test(async () => {
});
assert_throws_exactly(error, () => instance.exports.catch_exception());
}, "Imported JS function throws");

promise_test(async () => {
const builder = new WasmModuleBuilder();
const fnIndex = builder.addImport("module", "fn", kSig_v_v);
builder.addFunction("catch_and_rethrow", kSig_r_v)
.addBody([
kExprTry, kWasmStmt,
kExprCallFunction, fnIndex,
kExprCatchAll,
kExprRethrow, 0x00,
kExprEnd,
kExprRefNull, kWasmAnyRef,
])
.exportFunc();

const buffer = builder.toBuffer();

const error = new Error();
const fn = () => { throw error };
const {instance} = await WebAssembly.instantiate(buffer, {
module: { fn }
});
assert_throws_exactly(error, () => instance.exports.catch_and_rethrow());
}, "Imported JS function throws, Wasm catches and rethrows");

0 comments on commit c87460d

Please sign in to comment.