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}
97 lines
3.2 KiB
JavaScript
97 lines
3.2 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: --experimental-wasm-eh --experimental-wasm-reftypes --allow-natives-syntax
|
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
load("test/mjsunit/wasm/exceptions-utils.js");
|
|
|
|
// Test the encoding of a thrown exception with a null-ref value.
|
|
(function TestThrowRefNull() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let except = builder.addException(kSig_v_r);
|
|
builder.addFunction("throw_null", kSig_v_v)
|
|
.addBody([
|
|
kExprRefNull, kWasmExternRef,
|
|
kExprThrow, except,
|
|
]).exportFunc();
|
|
let instance = builder.instantiate();
|
|
|
|
assertWasmThrows(instance, except, [null], () => instance.exports.throw_null());
|
|
})();
|
|
|
|
// Test throwing/catching the null-ref value.
|
|
(function TestThrowCatchRefNull() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let except = builder.addException(kSig_v_r);
|
|
builder.addFunction("throw_catch_null", kSig_i_i)
|
|
.addBody([
|
|
kExprTry, kWasmI32,
|
|
kExprLocalGet, 0,
|
|
kExprI32Eqz,
|
|
kExprIf, kWasmI32,
|
|
kExprRefNull, kWasmExternRef,
|
|
kExprThrow, except,
|
|
kExprElse,
|
|
kExprI32Const, 42,
|
|
kExprEnd,
|
|
kExprCatch, except,
|
|
kExprRefIsNull,
|
|
kExprIf, kWasmI32,
|
|
kExprI32Const, 23,
|
|
kExprElse,
|
|
kExprUnreachable,
|
|
kExprEnd,
|
|
kExprEnd,
|
|
]).exportFunc();
|
|
let instance = builder.instantiate();
|
|
|
|
assertEquals(23, instance.exports.throw_catch_null(0));
|
|
assertEquals(42, instance.exports.throw_catch_null(1));
|
|
})();
|
|
|
|
// Test the encoding of a thrown exception with a reference type value.
|
|
(function TestThrowRefParam() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let except = builder.addException(kSig_v_r);
|
|
builder.addFunction("throw_param", kSig_v_r)
|
|
.addBody([
|
|
kExprLocalGet, 0,
|
|
kExprThrow, except,
|
|
]).exportFunc();
|
|
let instance = builder.instantiate();
|
|
let o = new Object();
|
|
|
|
assertWasmThrows(instance, except, [o], () => instance.exports.throw_param(o));
|
|
assertWasmThrows(instance, except, [1], () => instance.exports.throw_param(1));
|
|
assertWasmThrows(instance, except, [2.3], () => instance.exports.throw_param(2.3));
|
|
assertWasmThrows(instance, except, ["str"], () => instance.exports.throw_param("str"));
|
|
})();
|
|
|
|
// Test throwing/catching the reference type value.
|
|
(function TestThrowCatchRefParam() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let except = builder.addException(kSig_v_r);
|
|
builder.addFunction("throw_catch_param", kSig_r_r)
|
|
.addBody([
|
|
kExprTry, kWasmExternRef,
|
|
kExprLocalGet, 0,
|
|
kExprThrow, except,
|
|
kExprCatch, except,
|
|
// fall-through
|
|
kExprEnd,
|
|
]).exportFunc();
|
|
let instance = builder.instantiate();
|
|
let o = new Object();
|
|
|
|
assertEquals(o, instance.exports.throw_catch_param(o));
|
|
assertEquals(1, instance.exports.throw_catch_param(1));
|
|
assertEquals(2.3, instance.exports.throw_catch_param(2.3));
|
|
assertEquals("str", instance.exports.throw_catch_param("str"));
|
|
})();
|