2022-05-12 09:33:35 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-11-01 18:35:28 +00:00
|
|
|
// Flags: --experimental-wasm-gc
|
2022-05-12 09:33:35 +00:00
|
|
|
|
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
|
|
|
function assertInvalid(fn, message) {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
fn(builder);
|
2022-07-20 04:53:30 +00:00
|
|
|
assertThrows(() => builder.toModule(), WebAssembly.CompileError, message);
|
2022-05-12 09:33:35 +00:00
|
|
|
}
|
|
|
|
|
2022-07-20 04:53:30 +00:00
|
|
|
assertInvalid(
|
|
|
|
builder => builder.addLiteralStringRef("foo"),
|
|
|
|
/unexpected section <StringRef> \(enable with --experimental-wasm-stringref\)/);
|
|
|
|
|
2022-05-13 14:25:48 +00:00
|
|
|
let enableMessage = 'enable with --experimental-wasm-stringref'
|
2022-05-12 09:33:35 +00:00
|
|
|
|
2022-06-20 14:37:49 +00:00
|
|
|
for (let [name, code] of [['string', kStringRefCode],
|
|
|
|
['stringview_wtf8', kStringViewWtf8Code],
|
|
|
|
['stringview_wtf16', kStringViewWtf16Code],
|
|
|
|
['stringview_iter', kStringViewIterCode]]) {
|
2022-07-20 04:53:30 +00:00
|
|
|
let message = new RegExp(`invalid value type '${name}ref', ${enableMessage}`);
|
2022-06-20 14:37:49 +00:00
|
|
|
let default_init = [kExprRefNull, code];
|
2022-05-12 09:33:35 +00:00
|
|
|
|
2022-07-20 04:53:30 +00:00
|
|
|
assertInvalid(b => b.addType(makeSig([code], [])), message);
|
|
|
|
assertInvalid(b => b.addStruct([makeField(code, true)]), message);
|
|
|
|
assertInvalid(b => b.addArray(code, true), message);
|
|
|
|
assertInvalid(b => b.addType(makeSig([], [code])), message);
|
|
|
|
assertInvalid(b => b.addGlobal(code, true, default_init), message);
|
|
|
|
assertInvalid(b => b.addTable(code, 0), message);
|
|
|
|
assertInvalid(b => b.addPassiveElementSegment([default_init], code), message);
|
|
|
|
assertInvalid(b => b.addTag(makeSig([code], [])), message);
|
2022-05-16 08:18:46 +00:00
|
|
|
assertInvalid(
|
|
|
|
b => b.addFunction(undefined, kSig_v_v).addLocals(code, 1).addBody([]),
|
2022-07-20 04:53:30 +00:00
|
|
|
message);
|
2022-05-12 09:33:35 +00:00
|
|
|
}
|