From e2b5d968c32cba303de455b82d738d861b84ce7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Fri, 31 Mar 2023 12:48:42 +0200 Subject: [PATCH] test: update wasm/jsapi WPT PR-URL: https://github.com/nodejs/node/pull/47210 Reviewed-By: Michael Dawson Reviewed-By: Luigi Pinca Reviewed-By: Filip Skokan --- test/fixtures/wpt/README.md | 2 +- test/fixtures/wpt/versions.json | 2 +- .../jsapi/exception/basic.tentative.any.js | 16 ++--- .../exception/constructor.tentative.any.js | 8 +-- .../jsapi/exception/getArg.tentative.any.js | 4 +- .../jsapi/exception/identity.tentative.any.js | 61 +++++++++++++++++++ .../jsapi/exception/toString.tentative.any.js | 4 +- .../wpt/wasm/jsapi/wasm-module-builder.js | 44 ++++++------- 8 files changed, 101 insertions(+), 40 deletions(-) create mode 100644 test/fixtures/wpt/wasm/jsapi/exception/identity.tentative.any.js diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index 7b7150bb0866fc..d1db99383e7ceb 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -29,7 +29,7 @@ Last update: - streams: https://github.com/web-platform-tests/wpt/tree/9e5ef42bd3/streams - url: https://github.com/web-platform-tests/wpt/tree/84caeb6fbd/url - user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing -- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi +- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi - wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi - WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/188993d46b/WebCryptoAPI - webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index a83554fa0c3615..0ea187b3a9eb4b 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -76,7 +76,7 @@ "path": "user-timing" }, "wasm/jsapi": { - "commit": "d8dbe6990bed03ec03beee25069a9347d4c3d6d5", + "commit": "cde25e7e3c3b9d2280eb088a3fb9da988793d255", "path": "wasm/jsapi" }, "wasm/webapi": { diff --git a/test/fixtures/wpt/wasm/jsapi/exception/basic.tentative.any.js b/test/fixtures/wpt/wasm/jsapi/exception/basic.tentative.any.js index 9ddebae0e968a2..acf644f904f53d 100644 --- a/test/fixtures/wpt/wasm/jsapi/exception/basic.tentative.any.js +++ b/test/fixtures/wpt/wasm/jsapi/exception/basic.tentative.any.js @@ -14,11 +14,11 @@ promise_test(async () => { const kWasmAnyRef = 0x6f; const kSig_v_r = makeSig([kWasmAnyRef], []); const builder = new WasmModuleBuilder(); - const except = builder.addException(kSig_v_r); + const tagIndex = builder.addTag(kSig_v_r); builder.addFunction("throw_param", kSig_v_r) .addBody([ kExprLocalGet, 0, - kExprThrow, except, + kExprThrow, tagIndex, ]) .exportFunc(); const buffer = builder.toBuffer(); @@ -45,11 +45,11 @@ promise_test(async () => { promise_test(async () => { const builder = new WasmModuleBuilder(); - const except = builder.addException(kSig_v_a); + const tagIndex = builder.addTag(kSig_v_a); builder.addFunction("throw_null", kSig_v_v) .addBody([ kExprRefNull, kWasmAnyFunc, - kExprThrow, except, + kExprThrow, tagIndex, ]) .exportFunc(); const buffer = builder.toBuffer(); @@ -59,11 +59,11 @@ promise_test(async () => { promise_test(async () => { const builder = new WasmModuleBuilder(); - const except = builder.addException(kSig_v_i); + const tagIndex = builder.addTag(kSig_v_i); builder.addFunction("throw_int", kSig_v_v) .addBody([ ...wasmI32Const(7), - kExprThrow, except, + kExprThrow, tagIndex, ]) .exportFunc(); const buffer = builder.toBuffer(); @@ -74,12 +74,12 @@ promise_test(async () => { promise_test(async () => { const builder = new WasmModuleBuilder(); const fnIndex = builder.addImport("module", "fn", kSig_v_v); - const except = builder.addException(kSig_v_r); + const tagIndex= builder.addTag(kSig_v_r); builder.addFunction("catch_exception", kSig_r_v) .addBody([ kExprTry, kWasmStmt, kExprCallFunction, fnIndex, - kExprCatch, except, + kExprCatch, tagIndex, kExprReturn, kExprEnd, kExprRefNull, kWasmAnyRef, diff --git a/test/fixtures/wpt/wasm/jsapi/exception/constructor.tentative.any.js b/test/fixtures/wpt/wasm/jsapi/exception/constructor.tentative.any.js index 0fd47b455e023c..7ad08e1883ba13 100644 --- a/test/fixtures/wpt/wasm/jsapi/exception/constructor.tentative.any.js +++ b/test/fixtures/wpt/wasm/jsapi/exception/constructor.tentative.any.js @@ -18,8 +18,8 @@ test(() => { }, "No arguments"); test(() => { - const argument = new WebAssembly.Tag({ parameters: [] }); - assert_throws_js(TypeError, () => WebAssembly.Exception(argument)); + const tag = new WebAssembly.Tag({ parameters: [] }); + assert_throws_js(TypeError, () => WebAssembly.Exception(tag)); }, "Calling"); test(() => { @@ -53,10 +53,10 @@ test(() => { ["i64", undefined], ]; for (const typeAndArg of typesAndArgs) { - const exn = new WebAssembly.Tag({ parameters: [typeAndArg[0]] }); + const tag = new WebAssembly.Tag({ parameters: [typeAndArg[0]] }); assert_throws_js( TypeError, - () => new WebAssembly.Exception(exn, typeAndArg[1]) + () => new WebAssembly.Exception(tag, typeAndArg[1]) ); } }, "Invalid exception argument"); diff --git a/test/fixtures/wpt/wasm/jsapi/exception/getArg.tentative.any.js b/test/fixtures/wpt/wasm/jsapi/exception/getArg.tentative.any.js index ecd2fbd42fd18a..f0a568a857f0e7 100644 --- a/test/fixtures/wpt/wasm/jsapi/exception/getArg.tentative.any.js +++ b/test/fixtures/wpt/wasm/jsapi/exception/getArg.tentative.any.js @@ -20,7 +20,7 @@ test(() => { test(() => { const tag = new WebAssembly.Tag({ parameters: [] }); const exn = new WebAssembly.Exception(tag, []); - assert_throws_js(TypeError, () => exn.getArg(tag, 1)); + assert_throws_js(RangeError, () => exn.getArg(tag, 1)); }, "Index out of bounds"); test(() => { @@ -43,7 +43,7 @@ test(() => { const tag = new WebAssembly.Tag({ parameters: [] }); const exn = new WebAssembly.Exception(tag, []); for (const value of outOfRangeValues) { - assert_throws_js(TypeError, () => exn.getArg(tag, value)); + assert_throws_js(RangeError, () => exn.getArg(tag, value)); } }, "Getting out-of-range argument"); diff --git a/test/fixtures/wpt/wasm/jsapi/exception/identity.tentative.any.js b/test/fixtures/wpt/wasm/jsapi/exception/identity.tentative.any.js new file mode 100644 index 00000000000000..65787c107e3c29 --- /dev/null +++ b/test/fixtures/wpt/wasm/jsapi/exception/identity.tentative.any.js @@ -0,0 +1,61 @@ +// META: global=window,dedicatedworker,jsshell +// META: script=/wasm/jsapi/assertions.js +// META: script=/wasm/jsapi/wasm-module-builder.js + +test(() => { + const tag = new WebAssembly.Tag({ parameters: ["i32"] }); + const exn = new WebAssembly.Exception(tag, [42]); + const exn_same_payload = new WebAssembly.Exception(tag, [42]); + const exn_diff_payload = new WebAssembly.Exception(tag, [53]); + + const builder = new WasmModuleBuilder(); + const jsfuncIndex = builder.addImport("module", "jsfunc", kSig_v_v); + const tagIndex = builder.addImportedTag("module", "tag", kSig_v_i); + const imports = { + module: { + jsfunc: function() { throw exn; }, + tag: tag + } + }; + + builder + .addFunction("catch_rethrow", kSig_v_v) + .addBody([ + kExprTry, kWasmStmt, + kExprCallFunction, jsfuncIndex, + kExprCatch, tagIndex, + kExprDrop, + kExprRethrow, 0x00, + kExprEnd + ]) + .exportFunc(); + + builder + .addFunction("catch_all_rethrow", kSig_v_v) + .addBody([ + kExprTry, kWasmStmt, + kExprCallFunction, jsfuncIndex, + kExprCatchAll, + kExprRethrow, 0x00, + kExprEnd + ]) + .exportFunc(); + + const buffer = builder.toBuffer(); + WebAssembly.instantiate(buffer, imports).then(result => { + try { + result.instance.exports.catch_rethrow(); + } catch (e) { + assert_equals(e, exn); + assert_not_equals(e, exn_same_payload); + assert_not_equals(e, exn_diff_payload); + } + try { + result.instance.exports.catch_all_rethrow(); + } catch (e) { + assert_equals(e, exn); + assert_not_equals(e, exn_same_payload); + assert_not_equals(e, exn_diff_payload); + } + }); +}, "Identity check"); diff --git a/test/fixtures/wpt/wasm/jsapi/exception/toString.tentative.any.js b/test/fixtures/wpt/wasm/jsapi/exception/toString.tentative.any.js index 52635186c762fc..00e801a6fc1a4a 100644 --- a/test/fixtures/wpt/wasm/jsapi/exception/toString.tentative.any.js +++ b/test/fixtures/wpt/wasm/jsapi/exception/toString.tentative.any.js @@ -3,8 +3,8 @@ test(() => { const argument = { parameters: [] }; const tag = new WebAssembly.Tag(argument); - const exception = new WebAssembly.Exception(tag, []); - assert_class_string(exception, "WebAssembly.Exception"); + const exn = new WebAssembly.Exception(tag, []); + assert_class_string(exn, "WebAssembly.Exception"); }, "Object.prototype.toString on an Exception"); test(() => { diff --git a/test/fixtures/wpt/wasm/jsapi/wasm-module-builder.js b/test/fixtures/wpt/wasm/jsapi/wasm-module-builder.js index 7be72f86dae752..86d836a5a37245 100644 --- a/test/fixtures/wpt/wasm/jsapi/wasm-module-builder.js +++ b/test/fixtures/wpt/wasm/jsapi/wasm-module-builder.js @@ -65,7 +65,7 @@ let kElementSectionCode = 9; // Elements section let kCodeSectionCode = 10; // Function code let kDataSectionCode = 11; // Data segments let kDataCountSectionCode = 12; // Data segment count (between Element & Code) -let kExceptionSectionCode = 13; // Exception section (between Global & Export) +let kTagSectionCode = 13; // Tag section (between Memory & Global) // Name section types let kModuleNameCode = 0; @@ -104,13 +104,13 @@ let kExternalFunction = 0; let kExternalTable = 1; let kExternalMemory = 2; let kExternalGlobal = 3; -let kExternalException = 4; +let kExternalTag = 4; let kTableZero = 0; let kMemoryZero = 0; let kSegmentZero = 0; -let kExceptionAttribute = 0; +let kTagAttribute = 0; // Useful signatures let kSig_i_i = makeSig([kWasmI32], [kWasmI32]); @@ -681,7 +681,7 @@ class WasmModuleBuilder { this.exports = []; this.globals = []; this.tables = []; - this.exceptions = []; + this.tags = []; this.functions = []; this.element_segments = []; this.data_segments = []; @@ -689,7 +689,7 @@ class WasmModuleBuilder { this.num_imported_funcs = 0; this.num_imported_globals = 0; this.num_imported_tables = 0; - this.num_imported_exceptions = 0; + this.num_imported_tags = 0; return this; } @@ -752,10 +752,10 @@ class WasmModuleBuilder { return table; } - addException(type) { + addTag(type) { let type_index = (typeof type) == "number" ? type : this.addType(type); - let except_index = this.exceptions.length + this.num_imported_exceptions; - this.exceptions.push(type_index); + let except_index = this.tags.length + this.num_imported_tags; + this.tags.push(type_index); return except_index; } @@ -804,14 +804,14 @@ class WasmModuleBuilder { return this.num_imported_tables++; } - addImportedException(module, name, type) { - if (this.exceptions.length != 0) { - throw new Error('Imported exceptions must be declared before local ones'); + addImportedTag(module, name, type) { + if (this.tags.length != 0) { + throw new Error('Imported tags must be declared before local ones'); } let type_index = (typeof type) == "number" ? type : this.addType(type); - let o = {module: module, name: name, kind: kExternalException, type: type_index}; + let o = {module: module, name: name, kind: kExternalTag, type: type_index}; this.imports.push(o); - return this.num_imported_exceptions++; + return this.num_imported_tags++; } addExport(name, index) { @@ -938,8 +938,8 @@ class WasmModuleBuilder { section.emit_u8(has_max ? 1 : 0); // flags section.emit_u32v(imp.initial); // initial if (has_max) section.emit_u32v(imp.maximum); // maximum - } else if (imp.kind == kExternalException) { - section.emit_u32v(kExceptionAttribute); + } else if (imp.kind == kExternalTag) { + section.emit_u32v(kTagAttribute); section.emit_u32v(imp.type); } else { throw new Error("unknown/unsupported import kind " + imp.kind); @@ -1036,13 +1036,13 @@ class WasmModuleBuilder { }); } - // Add exceptions. - if (wasm.exceptions.length > 0) { - if (debug) print("emitting exceptions @ " + binary.length); - binary.emit_section(kExceptionSectionCode, section => { - section.emit_u32v(wasm.exceptions.length); - for (let type of wasm.exceptions) { - section.emit_u32v(kExceptionAttribute); + // Add tags. + if (wasm.tags.length > 0) { + if (debug) print("emitting tags @ " + binary.length); + binary.emit_section(kTagSectionCode, section => { + section.emit_u32v(wasm.tags.length); + for (let type of wasm.tags) { + section.emit_u32v(kTagAttribute); section.emit_u32v(type); } });