2018-09-06 08:14:22 +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-06 08:14:22 +00:00
|
|
|
|
|
|
|
(function TestExportMultiple() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except1 = builder.addTag(kSig_v_v);
|
|
|
|
let except2 = builder.addTag(kSig_v_i);
|
|
|
|
builder.addExportOfKind("ex1a", kExternalTag, except1);
|
|
|
|
builder.addExportOfKind("ex1b", kExternalTag, except1);
|
|
|
|
builder.addExportOfKind("ex2", kExternalTag, except2);
|
2018-09-06 08:14:22 +00:00
|
|
|
let instance = builder.instantiate();
|
|
|
|
|
|
|
|
assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex1a'));
|
|
|
|
assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex1b'));
|
|
|
|
assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex2'));
|
|
|
|
assertSame(instance.exports.ex1a, instance.exports.ex1b);
|
|
|
|
assertNotSame(instance.exports.ex1a, instance.exports.ex2);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestExportOutOfBounds() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except = builder.addTag(kSig_v_v);
|
|
|
|
builder.addExportOfKind("ex_oob", kExternalTag, except + 1);
|
2018-09-06 08:14:22 +00:00
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate(), WebAssembly.CompileError,
|
2021-07-29 11:09:02 +00:00
|
|
|
'WebAssembly.Module(): tag index 1 out of bounds (1 entry) @+30');
|
2018-09-06 08:14:22 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestExportSameNameTwice() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except = builder.addTag(kSig_v_v);
|
|
|
|
builder.addExportOfKind("ex", kExternalTag, except);
|
|
|
|
builder.addExportOfKind("ex", kExternalTag, except);
|
2018-09-06 08:14:22 +00:00
|
|
|
assertThrows(
|
|
|
|
() => builder.instantiate(), WebAssembly.CompileError,
|
2019-02-01 13:51:23 +00:00
|
|
|
'WebAssembly.Module(): Duplicate export name \'ex\' ' +
|
2021-07-29 11:09:02 +00:00
|
|
|
'for tag 0 and tag 0 @+28');
|
2018-09-06 08:14:22 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestExportModuleGetExports() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
2021-07-29 11:09:02 +00:00
|
|
|
let except = builder.addTag(kSig_v_v);
|
|
|
|
builder.addExportOfKind("ex", kExternalTag, except);
|
2018-09-06 08:14:22 +00:00
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
|
|
|
|
|
|
|
let exports = WebAssembly.Module.exports(module);
|
2021-07-29 11:09:02 +00:00
|
|
|
assertArrayEquals([{ name: "ex", kind: "tag" }], exports);
|
2018-09-06 08:14:22 +00:00
|
|
|
})();
|