2021-08-04 20:58:16 +00:00
|
|
|
// Copyright 2021 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.
|
|
|
|
|
2021-09-07 18:34:13 +00:00
|
|
|
// Flags: --experimental-wasm-gc
|
2021-08-04 20:58:16 +00:00
|
|
|
|
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
2022-01-24 08:29:50 +00:00
|
|
|
(function TestNominalTypesBasic() {
|
|
|
|
print(arguments.callee.name);
|
2021-09-15 12:59:42 +00:00
|
|
|
var builder = new WasmModuleBuilder();
|
2022-01-27 16:24:31 +00:00
|
|
|
let struct1 = builder.addStruct([makeField(kWasmI32, true)]);
|
|
|
|
let struct2 = builder.addStruct(
|
2021-09-15 12:59:42 +00:00
|
|
|
[makeField(kWasmI32, true), makeField(kWasmI32, true)], struct1);
|
2021-08-04 20:58:16 +00:00
|
|
|
|
2022-01-27 16:24:31 +00:00
|
|
|
let array1 = builder.addArray(kWasmI32, true);
|
|
|
|
let array2 = builder.addArray(kWasmI32, true, array1);
|
2021-08-04 20:58:16 +00:00
|
|
|
|
2021-09-15 12:59:42 +00:00
|
|
|
builder.addFunction("main", kSig_v_v)
|
2022-07-01 11:50:04 +00:00
|
|
|
.addLocals(wasmRefNullType(struct1), 1)
|
|
|
|
.addLocals(wasmRefNullType(array1), 1)
|
2021-09-15 12:59:42 +00:00
|
|
|
.addBody([
|
|
|
|
// Check that we can create a struct with implicit RTT.
|
2022-07-18 15:31:03 +00:00
|
|
|
kGCPrefix, kExprStructNewDefault, struct2,
|
2021-09-15 12:59:42 +00:00
|
|
|
// ...and upcast it.
|
2022-07-18 15:31:03 +00:00
|
|
|
kExprLocalSet, 0,
|
2021-09-15 12:59:42 +00:00
|
|
|
// Check that we can create an array with implicit RTT.
|
|
|
|
kExprI32Const, 10, // length
|
2022-07-18 15:31:03 +00:00
|
|
|
kGCPrefix, kExprArrayNewDefault, array2,
|
|
|
|
// ...and upcast it.
|
|
|
|
kExprLocalSet, 1])
|
2021-09-15 12:59:42 +00:00
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
// This test is only interested in type checking.
|
|
|
|
builder.instantiate();
|
|
|
|
})();
|
2021-08-04 20:58:16 +00:00
|
|
|
|
2022-01-24 08:29:50 +00:00
|
|
|
(function TestSubtypingDepthTooLarge() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
2022-01-27 16:24:31 +00:00
|
|
|
builder.addStruct([]);
|
|
|
|
for (let i = 0; i < 32; i++) builder.addStruct([], i);
|
2022-01-24 08:29:50 +00:00
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate(), WebAssembly.CompileError,
|
|
|
|
/subtyping depth is greater than allowed/);
|
2021-09-15 12:59:42 +00:00
|
|
|
})();
|