mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 20:06:54 +00:00

PR-URL: https://github.com/nodejs/node/pull/45579 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
// Copyright 2022 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-gc
|
|
|
|
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
(function TestRefTestInvalid() {
|
|
let struct = 0;
|
|
let array = 1;
|
|
let sig = 2;
|
|
let types = [
|
|
// source value type |target heap type
|
|
[kWasmI32, kAnyRefCode],
|
|
[kWasmNullExternRef, struct],
|
|
[wasmRefType(struct), kNullFuncRefCode],
|
|
[wasmRefType(array), kFuncRefCode],
|
|
[wasmRefType(struct), sig],
|
|
[wasmRefType(sig), struct],
|
|
[wasmRefType(sig), kExternRefCode],
|
|
[kWasmAnyRef, kExternRefCode],
|
|
[kWasmAnyRef, kFuncRefCode],
|
|
];
|
|
let casts = [
|
|
kExprRefTest,
|
|
kExprRefTestNull,
|
|
kExprRefCast,
|
|
kExprRefCastNull,
|
|
];
|
|
|
|
for (let [source_type, target_type_imm] of types) {
|
|
for (let cast of casts) {
|
|
let builder = new WasmModuleBuilder();
|
|
assertEquals(struct, builder.addStruct([makeField(kWasmI32, true)]));
|
|
assertEquals(array, builder.addArray(kWasmI32));
|
|
assertEquals(sig, builder.addType(makeSig([kWasmI32], [])));
|
|
builder.addFunction('refTest', makeSig([source_type], []))
|
|
.addBody([
|
|
kExprLocalGet, 0,
|
|
kGCPrefix, cast, target_type_imm,
|
|
kExprDrop,
|
|
]);
|
|
|
|
assertThrows(() => builder.instantiate(),
|
|
WebAssembly.CompileError,
|
|
/has to be in the same reference type hierarchy/);
|
|
}
|
|
}
|
|
})();
|