2023-10-05 08:46:07 +02:00
|
|
|
// 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.
|
|
|
|
|
2025-04-29 08:03:15 +02:00
|
|
|
// Flags: --wasm-staging
|
2023-10-05 08:46:07 +02:00
|
|
|
|
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
|
|
|
(function CastToView() {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
|
|
|
|
builder.addFunction("main", kSig_v_r)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0,
|
2024-03-30 09:54:35 +01:00
|
|
|
kGCPrefix, kExprAnyConvertExtern,
|
2023-10-05 08:46:07 +02:00
|
|
|
kGCPrefix, kExprRefCastNull, kStringViewWtf16Code,
|
|
|
|
kExprDrop,
|
|
|
|
]).exportFunc();
|
|
|
|
|
|
|
|
assertThrows(() => builder.instantiate().exports.main("foo"),
|
|
|
|
WebAssembly.CompileError,
|
|
|
|
/string views are not classifiable/);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestView() {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
|
|
|
|
builder.addFunction("main", kSig_v_r)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0,
|
2024-03-30 09:54:35 +01:00
|
|
|
kGCPrefix, kExprAnyConvertExtern,
|
2023-10-05 08:46:07 +02:00
|
|
|
kGCPrefix, kExprRefTestNull, kStringViewWtf16Code,
|
|
|
|
kExprDrop,
|
|
|
|
]).exportFunc();
|
|
|
|
|
|
|
|
assertThrows(() => builder.instantiate().exports.main("foo"),
|
|
|
|
WebAssembly.CompileError,
|
|
|
|
/string views are not classifiable/);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestBranchOnCast() {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
|
|
|
|
const view = kStringViewWtf16Code;
|
|
|
|
|
|
|
|
builder.addFunction("main", kSig_v_r)
|
|
|
|
.addBody([
|
|
|
|
kExprBlock, kWasmVoid,
|
|
|
|
kExprLocalGet, 0,
|
2024-03-30 09:54:35 +01:00
|
|
|
kGCPrefix, kExprAnyConvertExtern,
|
2024-04-19 12:51:52 +02:00
|
|
|
kGCPrefix, kExprBrOnCast, 0b11, 0, kAnyRefCode, view,
|
2023-10-05 08:46:07 +02:00
|
|
|
kExprDrop,
|
|
|
|
kExprEnd,
|
|
|
|
]).exportFunc();
|
|
|
|
|
|
|
|
assertThrows(() => builder.instantiate().exports.main("foo"),
|
|
|
|
WebAssembly.CompileError,
|
|
|
|
/invalid types for br_on_cast/);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestBranchOnCastFail() {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
|
|
|
|
const view = kStringViewWtf16Code;
|
|
|
|
|
|
|
|
builder.addFunction("main", kSig_v_r)
|
|
|
|
.addBody([
|
|
|
|
kExprBlock, kWasmVoid,
|
|
|
|
kExprLocalGet, 0,
|
2024-03-30 09:54:35 +01:00
|
|
|
kGCPrefix, kExprAnyConvertExtern,
|
2024-04-19 12:51:52 +02:00
|
|
|
kGCPrefix, kExprBrOnCastFail, 0b11, 0, kAnyRefCode, view,
|
2023-10-05 08:46:07 +02:00
|
|
|
kExprDrop,
|
|
|
|
kExprEnd,
|
|
|
|
]).exportFunc();
|
|
|
|
|
|
|
|
assertThrows(() => builder.instantiate().exports.main("foo"),
|
|
|
|
WebAssembly.CompileError,
|
|
|
|
/invalid types for br_on_cast/);
|
|
|
|
})();
|