mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: update wasm/jsapi WPT
PR-URL: https://github.com/nodejs/node/pull/47210 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
parent
da8c099f10
commit
0b2555cb51
2
test/fixtures/wpt/README.md
vendored
2
test/fixtures/wpt/README.md
vendored
@ -29,7 +29,7 @@ Last update:
|
||||
- streams: https://github.com/web-platform-tests/wpt/tree/51750bc8d7/streams
|
||||
- url: https://github.com/web-platform-tests/wpt/tree/7c5c3cc125/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
|
||||
|
2
test/fixtures/wpt/versions.json
vendored
2
test/fixtures/wpt/versions.json
vendored
@ -76,7 +76,7 @@
|
||||
"path": "user-timing"
|
||||
},
|
||||
"wasm/jsapi": {
|
||||
"commit": "d8dbe6990bed03ec03beee25069a9347d4c3d6d5",
|
||||
"commit": "cde25e7e3c3b9d2280eb088a3fb9da988793d255",
|
||||
"path": "wasm/jsapi"
|
||||
},
|
||||
"wasm/webapi": {
|
||||
|
@ -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,
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
||||
|
61
test/fixtures/wpt/wasm/jsapi/exception/identity.tentative.any.js
vendored
Normal file
61
test/fixtures/wpt/wasm/jsapi/exception/identity.tentative.any.js
vendored
Normal file
@ -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");
|
@ -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(() => {
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user