2018-12-10 09:59:29 +00:00
|
|
|
// 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 --experimental-wasm-simd --allow-natives-syntax
|
|
|
|
|
2021-06-01 12:46:36 +00:00
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
d8.file.execute("test/mjsunit/wasm/exceptions-utils.js");
|
2018-12-10 09:59:29 +00:00
|
|
|
|
|
|
|
(function TestThrowS128Default() {
|
2019-11-14 10:12:42 +00:00
|
|
|
print(arguments.callee.name);
|
2018-12-10 09:59:29 +00:00
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
var kSig_v_s = makeSig([kWasmS128], []);
|
|
|
|
var except = builder.addException(kSig_v_s);
|
|
|
|
builder.addFunction("throw_simd", kSig_v_v)
|
2020-09-10 12:39:52 +00:00
|
|
|
.addLocals(kWasmS128, 1)
|
2018-12-10 09:59:29 +00:00
|
|
|
.addBody([
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalGet, 0,
|
2018-12-10 09:59:29 +00:00
|
|
|
kExprThrow, 0,
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
var instance = builder.instantiate();
|
|
|
|
|
|
|
|
assertWasmThrows(instance, except, [0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
() => instance.exports.throw_simd());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestThrowCatchS128Default() {
|
2019-11-14 10:12:42 +00:00
|
|
|
print(arguments.callee.name);
|
2018-12-10 09:59:29 +00:00
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
var kSig_v_s = makeSig([kWasmS128], []);
|
|
|
|
var except = builder.addException(kSig_v_s);
|
|
|
|
builder.addFunction("throw_catch_simd", kSig_i_v)
|
2020-09-10 12:39:52 +00:00
|
|
|
.addLocals(kWasmS128, 1)
|
2018-12-10 09:59:29 +00:00
|
|
|
.addBody([
|
2019-01-15 13:44:03 +00:00
|
|
|
kExprTry, kWasmS128,
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalGet, 0,
|
2018-12-10 09:59:29 +00:00
|
|
|
kExprThrow, 0,
|
2020-12-03 18:00:05 +00:00
|
|
|
kExprCatch, except,
|
2019-01-15 13:44:03 +00:00
|
|
|
kExprEnd,
|
2019-11-14 10:12:42 +00:00
|
|
|
kExprLocalGet, 0,
|
|
|
|
kSimdPrefix, kExprI32x4Eq,
|
2021-03-05 23:56:29 +00:00
|
|
|
kSimdPrefix, kExprI8x16AllTrue,
|
2018-12-10 09:59:29 +00:00
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
var instance = builder.instantiate();
|
|
|
|
|
|
|
|
assertEquals(1, instance.exports.throw_catch_simd());
|
|
|
|
})();
|
2019-11-14 10:12:42 +00:00
|
|
|
|
|
|
|
(function TestThrowCatchS128WithValue() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
var kSig_v_s = makeSig([kWasmS128], []);
|
|
|
|
var except = builder.addException(kSig_v_s);
|
|
|
|
const in_idx = 0x10; // Input index in memory.
|
|
|
|
const out_idx = 0x20; // Output index in memory.
|
|
|
|
builder.addImportedMemory("env", "memory");
|
|
|
|
builder.addFunction("throw_catch_simd", kSig_v_v)
|
|
|
|
.addBody([
|
|
|
|
kExprI32Const, out_idx,
|
|
|
|
kExprTry, kWasmS128,
|
|
|
|
kExprI32Const, in_idx,
|
|
|
|
kSimdPrefix, kExprS128LoadMem, 0, 0,
|
|
|
|
kExprThrow, 0,
|
2020-12-03 18:00:05 +00:00
|
|
|
kExprCatch, except,
|
2019-11-14 10:12:42 +00:00
|
|
|
kExprEnd,
|
|
|
|
kSimdPrefix, kExprS128StoreMem, 0, 0,
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
var memory = new WebAssembly.Memory({initial: 1});
|
|
|
|
var instance = builder.instantiate({env: {memory:memory}});
|
|
|
|
|
|
|
|
var ref = [0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78,
|
|
|
|
0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0];
|
|
|
|
var array = new Uint8Array(memory.buffer);
|
|
|
|
array.set(ref, in_idx); // Store reference value in memory.
|
|
|
|
instance.exports.throw_catch_simd();
|
|
|
|
assertArrayEquals(ref, array.slice(out_idx, out_idx + 0x10));
|
|
|
|
})();
|