1688cad47f
This extends crrev.com/c/3948663 (ref.cast) by adding the new "ref.cast null" which only behaves different for null for which it doesn't trap but instead casts the null value to the target (null)type. Bug: v8:7748 Change-Id: I3ac85d83cc06c95af8830c1c60ae2f28414e2570 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3960329 Reviewed-by: Manos Koukoutos <manoskouk@chromium.org> Commit-Queue: Matthias Liedtke <mliedtke@chromium.org> Cr-Commit-Position: refs/heads/main@{#83934}
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/);
|
|
}
|
|
}
|
|
})();
|