v8/test/mjsunit/wasm/exceptions-rethrow.js
Clemens Backes 421fd3929d [wasm] Rename {Get,Set,Tee}Local to Local{Get,Set,Tee}
This brings our constants back in line with the changed spec text. We
already use kExprTableGet and kExprTableSet, but for locals and globals
we still use the old wording.

This renaming is mostly mechanical.

PS1 was created using:
ag -l 'kExpr(Get|Set|Tee)Local' src test | \
  xargs -L1 sed -E 's/kExpr(Get|Set|Tee)Local\b/kExprLocal\1/g' -i

PS2 contains manual fixes.

R=mstarzinger@chromium.org

Bug: v8:9810
Change-Id: I1617f1b2a100685a3bf56218e76845a9481959c5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1847354
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64161}
2019-10-08 14:14:40 +00:00

121 lines
3.8 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 work inside 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,
kExprRethrow,
kExprEnd,
]).exportFunc();
builder.addFunction("rethrow1", kSig_i_i)
.addLocals({except_count: 1})
.addBody([
kExprTry, kWasmI32,
kExprThrow, except,
kExprCatch,
kExprLocalSet, 1,
kExprLocalGet, 0,
kExprI32Eqz,
kExprIf, kWasmStmt,
kExprLocalGet, 1,
kExprRethrow,
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 work properly even in the presence of multiple
// nested 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)
.addLocals({except_count: 2})
.addBody([
kExprTry, kWasmI32,
kExprThrow, except2,
kExprCatch,
kExprLocalSet, 2,
kExprTry, kWasmI32,
kExprThrow, except1,
kExprCatch,
kExprLocalSet, 1,
kExprLocalGet, 0,
kExprI32Const, 0,
kExprI32Eq,
kExprIf, kWasmStmt,
kExprLocalGet, 1,
kExprRethrow,
kExprEnd,
kExprLocalGet, 0,
kExprI32Const, 1,
kExprI32Eq,
kExprIf, kWasmStmt,
kExprLocalGet, 2,
kExprRethrow,
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)
.addLocals({except_count: 1})
.addBody([
kExprTry, kWasmI32,
kExprThrow, except,
kExprCatch,
kExprLocalSet, 1,
kExprTry, kWasmI32,
kExprLocalGet, 0,
kExprI32Eqz,
kExprIf, kWasmStmt,
kExprLocalGet, 1,
kExprRethrow,
kExprEnd,
kExprI32Const, 42,
kExprCatch,
kExprDrop,
kExprI32Const, 23,
kExprEnd,
kExprEnd,
]).exportFunc();
let instance = builder.instantiate();
assertEquals(23, instance.exports.rethrow_recatch(0));
assertEquals(42, instance.exports.rethrow_recatch(1));
})();