2018-09-11 08:38:24 +00:00
|
|
|
// Copyright 2018 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: --expose-wasm --experimental-wasm-eh
|
|
|
|
|
2021-06-01 12:46:36 +00:00
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
2018-09-11 08:38:24 +00:00
|
|
|
|
|
|
|
// Helper function to return a new exported exception with the {kSig_v_v} type
|
|
|
|
// signature from an anonymous module. The underlying module is thrown away.
|
|
|
|
// This allows tests to reason solely about importing exceptions.
|
2021-07-29 11:09:02 +00:00
|
|
|
function NewExportedTag() {
|
2018-09-11 08:38:24 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let tag = builder.addTag(kSig_v_v);
|
|
|
|
builder.addExportOfKind("t", kExternalTag, tag);
|
2018-09-11 08:38:24 +00:00
|
|
|
let instance = builder.instantiate();
|
2021-07-29 11:09:02 +00:00
|
|
|
return instance.exports.t;
|
2018-09-11 08:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(function TestImportSimple() {
|
|
|
|
print(arguments.callee.name);
|
2021-07-29 11:09:02 +00:00
|
|
|
let exported = NewExportedTag();
|
2018-09-11 08:38:24 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except = builder.addImportedTag("m", "ex", kSig_v_v);
|
2018-09-11 08:38:24 +00:00
|
|
|
|
|
|
|
assertDoesNotThrow(() => builder.instantiate({ m: { ex: exported }}));
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestImportMultiple() {
|
|
|
|
print(arguments.callee.name);
|
2021-07-29 11:09:02 +00:00
|
|
|
let exported = NewExportedTag();
|
2018-09-11 08:38:24 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except1 = builder.addImportedTag("m", "ex1", kSig_v_v);
|
|
|
|
let except2 = builder.addImportedTag("m", "ex2", kSig_v_v);
|
|
|
|
let except3 = builder.addTag(kSig_v_v);
|
|
|
|
builder.addExportOfKind("ex2", kExternalTag, except2);
|
|
|
|
builder.addExportOfKind("ex3", kExternalTag, except3);
|
2018-09-11 08:38:24 +00:00
|
|
|
let instance = builder.instantiate({ m: { ex1: exported, ex2: exported }});
|
|
|
|
|
|
|
|
assertTrue(except1 < except3 && except2 < except3);
|
|
|
|
assertEquals(undefined, instance.exports.ex1);
|
2018-09-17 12:19:53 +00:00
|
|
|
assertSame(exported, instance.exports.ex2);
|
2018-09-11 08:38:24 +00:00
|
|
|
assertNotSame(exported, instance.exports.ex3);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestImportMissing() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except = builder.addImportedTag("m", "ex", kSig_v_v);
|
2018-09-11 08:38:24 +00:00
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate({}), TypeError,
|
|
|
|
/module is not an object or function/);
|
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate({ m: {}}), WebAssembly.LinkError,
|
2021-07-13 15:32:18 +00:00
|
|
|
/tag import requires a WebAssembly.Tag/);
|
2018-09-11 08:38:24 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestImportValueMismatch() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except = builder.addImportedTag("m", "ex", kSig_v_v);
|
2018-09-11 08:38:24 +00:00
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate({ m: { ex: 23 }}), WebAssembly.LinkError,
|
2021-07-13 15:32:18 +00:00
|
|
|
/tag import requires a WebAssembly.Tag/);
|
2018-09-11 08:38:24 +00:00
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate({ m: { ex: {} }}), WebAssembly.LinkError,
|
2021-07-13 15:32:18 +00:00
|
|
|
/tag import requires a WebAssembly.Tag/);
|
2021-07-29 11:09:02 +00:00
|
|
|
var monkey = Object.create(NewExportedTag());
|
2018-09-11 08:38:24 +00:00
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate({ m: { ex: monkey }}), WebAssembly.LinkError,
|
2021-07-13 15:32:18 +00:00
|
|
|
/tag import requires a WebAssembly.Tag/);
|
2018-09-11 08:38:24 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestImportSignatureMismatch() {
|
|
|
|
print(arguments.callee.name);
|
2021-07-29 11:09:02 +00:00
|
|
|
let exported = NewExportedTag();
|
2018-09-11 08:38:24 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except = builder.addImportedTag("m", "ex", kSig_v_i);
|
2018-09-11 08:38:24 +00:00
|
|
|
|
2018-09-11 12:47:21 +00:00
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate({ m: { ex: exported }}), WebAssembly.LinkError,
|
2021-07-13 15:32:18 +00:00
|
|
|
/imported tag does not match the expected type/);
|
2018-09-11 08:38:24 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestImportModuleGetImports() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except = builder.addImportedTag("m", "ex", kSig_v_v);
|
2018-09-11 08:38:24 +00:00
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
|
|
|
|
|
|
|
let imports = WebAssembly.Module.imports(module);
|
2021-07-29 11:09:02 +00:00
|
|
|
assertArrayEquals([{ module: "m", name: "ex", kind: "tag" }], imports);
|
2018-09-11 08:38:24 +00:00
|
|
|
})();
|