v8/test/mjsunit/wasm/exceptions-api.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

60 lines
2.3 KiB
JavaScript

// 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.
// Flags: --experimental-wasm-eh
load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestImport() {
print(arguments.callee.name);
assertThrows(() => new WebAssembly.Tag(), TypeError,
/Argument 0 must be a tag type/);
assertThrows(() => new WebAssembly.Tag({}), TypeError,
/Argument 0 must be a tag type with 'parameters'/);
assertThrows(() => new WebAssembly.Tag({parameters: ['foo']}), TypeError,
/Argument 0 parameter type at index #0 must be a value type/);
assertThrows(() => new WebAssembly.Tag({parameters: {}}), TypeError,
/Argument 0 contains parameters without 'length'/);
let js_except_i32 = new WebAssembly.Tag({parameters: ['i32']});
let js_except_v = new WebAssembly.Tag({parameters: []});
let builder = new WasmModuleBuilder();
builder.addImportedException("m", "ex", kSig_v_i);
assertDoesNotThrow(() => builder.instantiate({ m: { ex: js_except_i32 }}));
assertThrows(
() => builder.instantiate({ m: { ex: js_except_v }}), WebAssembly.LinkError,
/imported tag does not match the expected type/);
assertThrows(
() => builder.instantiate({ m: { ex: js_except_v }}), WebAssembly.LinkError,
/imported tag does not match the expected type/);
})();
(function TestExport() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_v);
builder.addExportOfKind("ex", kExternalException, except);
let instance = builder.instantiate();
assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex'));
assertEquals("object", typeof instance.exports.ex);
assertInstanceof(instance.exports.ex, WebAssembly.Tag);
assertSame(instance.exports.ex.constructor, WebAssembly.Tag);
})();
(function TestImportExport() {
print(arguments.callee.name);
let js_ex_i32 = new WebAssembly.Tag({parameters: ['i32']});
let builder = new WasmModuleBuilder();
let index = builder.addImportedException("m", "ex", kSig_v_i);
builder.addExportOfKind("ex", kExternalException, index);
let instance = builder.instantiate({ m: { ex: js_ex_i32 }});
let res = instance.exports.ex;
assertEquals(res, js_ex_i32);
})();