e33c13c2a2
First step towards the new exception handling proposal: https://github.com/WebAssembly/exception-handling/issues/125 This is essentially a revert of: "[wasm] Switch to new 'catch' and 'br_on_exn' proposal." The changes are: - "catch" instruction takes a tag immediate, - "rethrow" instruction takes a label immediate, - Add "catch_all" instruction, - Remove "br_on_exn" instruction, - Do not push exceptions on the stack, only the encoded values R=clemensb@chromium.org CC=aheejin@chromium.org Bug: v8:8091 Change-Id: Iea4d8d5a5d3ad50693f645e93c13e8de117aa884 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2484514 Commit-Queue: Thibaud Michaud <thibaudm@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#71602}
142 lines
4.5 KiB
JavaScript
142 lines
4.5 KiB
JavaScript
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --expose-wasm --experimental-wasm-eh --allow-natives-syntax
|
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
load("test/mjsunit/wasm/exceptions-utils.js");
|
|
|
|
// Test that rethrow expressions can target catch blocks.
|
|
(function TestRethrowInCatch() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let except = builder.addException(kSig_v_v);
|
|
builder.addFunction("rethrow0", kSig_v_v)
|
|
.addBody([
|
|
kExprTry, kWasmStmt,
|
|
kExprThrow, except,
|
|
kExprCatch, except,
|
|
kExprRethrow, 0,
|
|
kExprEnd,
|
|
]).exportFunc();
|
|
builder.addFunction("rethrow1", kSig_i_i)
|
|
.addBody([
|
|
kExprTry, kWasmI32,
|
|
kExprThrow, except,
|
|
kExprCatch, except,
|
|
kExprLocalGet, 0,
|
|
kExprI32Eqz,
|
|
kExprIf, kWasmStmt,
|
|
kExprRethrow, 1,
|
|
kExprEnd,
|
|
kExprI32Const, 23,
|
|
kExprEnd
|
|
]).exportFunc();
|
|
let instance = builder.instantiate();
|
|
|
|
assertWasmThrows(instance, except, [], () => instance.exports.rethrow0());
|
|
assertWasmThrows(instance, except, [], () => instance.exports.rethrow1(0));
|
|
assertEquals(23, instance.exports.rethrow1(1));
|
|
})();
|
|
|
|
// Test that rethrow expressions can target catch-all blocks.
|
|
(function TestRethrowInCatchAll() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let except = builder.addException(kSig_v_v);
|
|
builder.addFunction("rethrow0", kSig_v_v)
|
|
.addBody([
|
|
kExprTry, kWasmStmt,
|
|
kExprThrow, except,
|
|
kExprCatchAll,
|
|
kExprRethrow, 0,
|
|
kExprEnd,
|
|
]).exportFunc();
|
|
builder.addFunction("rethrow1", kSig_i_i)
|
|
.addBody([
|
|
kExprTry, kWasmI32,
|
|
kExprThrow, except,
|
|
kExprCatchAll,
|
|
kExprLocalGet, 0,
|
|
kExprI32Eqz,
|
|
kExprIf, kWasmStmt,
|
|
kExprRethrow, 1,
|
|
kExprEnd,
|
|
kExprI32Const, 23,
|
|
kExprEnd
|
|
]).exportFunc();
|
|
let instance = builder.instantiate();
|
|
|
|
assertWasmThrows(instance, except, [], () => instance.exports.rethrow0());
|
|
assertWasmThrows(instance, except, [], () => instance.exports.rethrow1(0));
|
|
assertEquals(23, instance.exports.rethrow1(1));
|
|
})();
|
|
|
|
// Test that rethrow expression properly target the correct surrounding try
|
|
// block even in the presence of multiple handlers being involved.
|
|
(function TestRethrowNested() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let except1 = builder.addException(kSig_v_v);
|
|
let except2 = builder.addException(kSig_v_v);
|
|
builder.addFunction("rethrow_nested", kSig_i_i)
|
|
.addBody([
|
|
kExprTry, kWasmI32,
|
|
kExprThrow, except2,
|
|
kExprCatch, except2,
|
|
kExprTry, kWasmI32,
|
|
kExprThrow, except1,
|
|
kExprCatch, except1,
|
|
kExprLocalGet, 0,
|
|
kExprI32Const, 0,
|
|
kExprI32Eq,
|
|
kExprIf, kWasmStmt,
|
|
kExprRethrow, 1,
|
|
kExprEnd,
|
|
kExprLocalGet, 0,
|
|
kExprI32Const, 1,
|
|
kExprI32Eq,
|
|
kExprIf, kWasmStmt,
|
|
kExprRethrow, 2,
|
|
kExprEnd,
|
|
kExprI32Const, 23,
|
|
kExprEnd,
|
|
kExprEnd,
|
|
]).exportFunc();
|
|
let instance = builder.instantiate();
|
|
|
|
assertWasmThrows(instance, except1, [], () => instance.exports.rethrow_nested(0));
|
|
assertWasmThrows(instance, except2, [], () => instance.exports.rethrow_nested(1));
|
|
assertEquals(23, instance.exports.rethrow_nested(2));
|
|
})();
|
|
|
|
// Test that an exception being rethrow can be caught by another local catch
|
|
// block in the same function without ever unwinding the activation.
|
|
(function TestRethrowRecatch() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let except = builder.addException(kSig_v_v);
|
|
builder.addFunction("rethrow_recatch", kSig_i_i)
|
|
.addBody([
|
|
kExprTry, kWasmI32,
|
|
kExprThrow, except,
|
|
kExprCatch, except,
|
|
kExprTry, kWasmI32,
|
|
kExprLocalGet, 0,
|
|
kExprI32Eqz,
|
|
kExprIf, kWasmStmt,
|
|
kExprRethrow, 2,
|
|
kExprEnd,
|
|
kExprI32Const, 42,
|
|
kExprCatch, except,
|
|
kExprI32Const, 23,
|
|
kExprEnd,
|
|
kExprEnd,
|
|
]).exportFunc();
|
|
let instance = builder.instantiate();
|
|
|
|
assertEquals(23, instance.exports.rethrow_recatch(0));
|
|
assertEquals(42, instance.exports.rethrow_recatch(1));
|
|
})();
|