v8/test/mjsunit/wasm/exceptions-import.js
Thibaud Michaud 15d3bcbd7f Reland "[wasm][eh] Rename Exception to Tag in the JS API"
This is a reland of 0b091e9bd3

Some blink web tests have been temporarily disabled to allow landing
changes to the JS API in V8.

Original change's description:
> [wasm][eh] Rename Exception to Tag in the JS API
>
> See:
> https://github.com/WebAssembly/exception-handling/issues/159
>
> This change only does the rename where it's observable. This should also
> be renamed throughout the codebase for consistency and will be done
> separately.
>
> R=ahaas@chromium.org
>
> Bug: v8:8091
> Change-Id: Iec1118194981dfd33be6e30256b6e72d12143e1f
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021172
> Reviewed-by: Andreas Haas <ahaas@chromium.org>
> Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#75718}

Bug: v8:8091
Change-Id: Id5375b5287fff81b8e0096377a55ef63e6d9b985
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3035083
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75785}
2021-07-19 12:22:16 +00:00

96 lines
3.5 KiB
JavaScript

// 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
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
// 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.
function NewExportedException() {
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_v);
builder.addExportOfKind("ex", kExternalException, except);
let instance = builder.instantiate();
return instance.exports.ex;
}
(function TestImportSimple() {
print(arguments.callee.name);
let exported = NewExportedException();
let builder = new WasmModuleBuilder();
let except = builder.addImportedException("m", "ex", kSig_v_v);
assertDoesNotThrow(() => builder.instantiate({ m: { ex: exported }}));
})();
(function TestImportMultiple() {
print(arguments.callee.name);
let exported = NewExportedException();
let builder = new WasmModuleBuilder();
let except1 = builder.addImportedException("m", "ex1", kSig_v_v);
let except2 = builder.addImportedException("m", "ex2", kSig_v_v);
let except3 = builder.addException(kSig_v_v);
builder.addExportOfKind("ex2", kExternalException, except2);
builder.addExportOfKind("ex3", kExternalException, except3);
let instance = builder.instantiate({ m: { ex1: exported, ex2: exported }});
assertTrue(except1 < except3 && except2 < except3);
assertEquals(undefined, instance.exports.ex1);
assertSame(exported, instance.exports.ex2);
assertNotSame(exported, instance.exports.ex3);
})();
(function TestImportMissing() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let except = builder.addImportedException("m", "ex", kSig_v_v);
assertThrows(
() => builder.instantiate({}), TypeError,
/module is not an object or function/);
assertThrows(
() => builder.instantiate({ m: {}}), WebAssembly.LinkError,
/tag import requires a WebAssembly.Tag/);
})();
(function TestImportValueMismatch() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let except = builder.addImportedException("m", "ex", kSig_v_v);
assertThrows(
() => builder.instantiate({ m: { ex: 23 }}), WebAssembly.LinkError,
/tag import requires a WebAssembly.Tag/);
assertThrows(
() => builder.instantiate({ m: { ex: {} }}), WebAssembly.LinkError,
/tag import requires a WebAssembly.Tag/);
var monkey = Object.create(NewExportedException());
assertThrows(
() => builder.instantiate({ m: { ex: monkey }}), WebAssembly.LinkError,
/tag import requires a WebAssembly.Tag/);
})();
(function TestImportSignatureMismatch() {
print(arguments.callee.name);
let exported = NewExportedException();
let builder = new WasmModuleBuilder();
let except = builder.addImportedException("m", "ex", kSig_v_i);
assertThrows(
() => builder.instantiate({ m: { ex: exported }}), WebAssembly.LinkError,
/imported tag does not match the expected type/);
})();
(function TestImportModuleGetImports() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let except = builder.addImportedException("m", "ex", kSig_v_v);
let module = new WebAssembly.Module(builder.toBuffer());
let imports = WebAssembly.Module.imports(module);
assertArrayEquals([{ module: "m", name: "ex", kind: "exception" }], imports);
})();