node/deps/v8/test/mjsunit/wasm/exnref-global.js
Michaël Zasso 1d29d81c69 deps: update V8 to 12.3.219.16
PR-URL: https://github.com/nodejs/node/pull/52293
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2024-04-19 08:39:47 +00:00

52 lines
1.8 KiB
JavaScript

// Copyright 2023 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-exnref
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
let kSig_e_v = makeSig([], [kWasmExnRef]);
// First we just test that "exnref" global variables are allowed.
(function TestGlobalExnRefSupported() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let g = builder.addGlobal(kWasmExnRef, false, false);
builder.addFunction("push_and_drop_exnref", kSig_v_v)
.addBody([
kExprGlobalGet, g.index,
kExprDrop,
]).exportFunc();
let instance = builder.instantiate();
assertDoesNotThrow(instance.exports.push_and_drop_exnref);
})();
// Test default value that global "exnref" variables are initialized with.
(function TestGlobalExnRefDefaultValue() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let g = builder.addGlobal(kWasmExnRef, false, false);
builder.addFunction('push_and_return_exnref', kSig_e_v)
.addBody([kExprGlobalGet, g.index])
.exportFunc();
let instance = builder.instantiate();
assertEquals(null, instance.exports.push_and_return_exnref());
})();
// Test custom initialization index for a global "exnref" variable.
(function TestGlobalExnRefInitIndex() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let g_index = builder.addImportedGlobal("m", "exn", kWasmExnRef);
builder.addFunction('push_and_return_exnref', kSig_e_v)
.addBody([kExprGlobalGet, g_index])
.exportFunc();
let exception = { x: "my fancy exception" };
let instance = builder.instantiate({ "m": { "exn": exception }});
assertSame(exception, instance.exports.push_and_return_exnref());
})();