diff options
Diffstat (limited to 'deps/v8/test/mjsunit/wasm')
23 files changed, 947 insertions, 193 deletions
diff --git a/deps/v8/test/mjsunit/wasm/anyfunc.js b/deps/v8/test/mjsunit/wasm/anyfunc.js index 5969950433..eeab4983f5 100644 --- a/deps/v8/test/mjsunit/wasm/anyfunc.js +++ b/deps/v8/test/mjsunit/wasm/anyfunc.js @@ -152,7 +152,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_a_a); builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kWasmAnyFunc, kExprLocalSet, 0, kExprLocalGet, 0]) + .addBody([kExprRefNull, kAnyFuncCode, kExprLocalSet, 0, kExprLocalGet, 0]) .exportFunc(); const main = builder.instantiate().exports.main; @@ -164,7 +164,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_a_v); builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kWasmAnyFunc]) + .addBody([kExprRefNull, kAnyFuncCode]) .exportFunc(); const main = builder.instantiate().exports.main; @@ -176,7 +176,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_a_v); builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kWasmAnyFunc, kExprReturn]) + .addBody([kExprRefNull, kAnyFuncCode, kExprReturn]) .exportFunc(); const main = builder.instantiate().exports.main; diff --git a/deps/v8/test/mjsunit/wasm/exceptions-api.js b/deps/v8/test/mjsunit/wasm/exceptions-api.js index 0f30c6e59f..29d3de0602 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-api.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-api.js @@ -2,58 +2,239 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --experimental-wasm-eh +// Flags: --experimental-wasm-eh --experimental-wasm-reftypes load("test/mjsunit/wasm/wasm-module-builder.js"); (function TestImport() { print(arguments.callee.name); - assertThrows(() => new WebAssembly.Exception(), TypeError, - /Argument 0 must be an exception type/); - assertThrows(() => new WebAssembly.Exception({}), TypeError, - /Argument 0 must be an exception type with 'parameters'/); - assertThrows(() => new WebAssembly.Exception({parameters: ['foo']}), TypeError, + 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.Exception({parameters: {}}), TypeError, + assertThrows(() => new WebAssembly.Tag({parameters: {}}), TypeError, /Argument 0 contains parameters without 'length'/); - let js_except_i32 = new WebAssembly.Exception({parameters: ['i32']}); - let js_except_v = new WebAssembly.Exception({parameters: []}); + 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); + builder.addImportedTag("m", "ex", kSig_v_i); assertDoesNotThrow(() => builder.instantiate({ m: { ex: js_except_i32 }})); assertThrows( () => builder.instantiate({ m: { ex: js_except_v }}), WebAssembly.LinkError, - /imported exception does not match the expected type/); + /imported tag does not match the expected type/); assertThrows( () => builder.instantiate({ m: { ex: js_except_v }}), WebAssembly.LinkError, - /imported exception does not match the expected type/); + /imported tag does not match the expected type/); + assertTrue(js_except_i32.toString() == "[object WebAssembly.Tag]"); })(); (function TestExport() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); - builder.addExportOfKind("ex", kExternalException, except); + let except = builder.addTag(kSig_v_v); + builder.addExportOfKind("ex", kExternalTag, except); let instance = builder.instantiate(); assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex')); assertEquals("object", typeof instance.exports.ex); - assertInstanceof(instance.exports.ex, WebAssembly.Exception); - assertSame(instance.exports.ex.constructor, WebAssembly.Exception); + 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.Exception({parameters: ['i32']}); + 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 index = builder.addImportedTag("m", "ex", kSig_v_i); + builder.addExportOfKind("ex", kExternalTag, index); let instance = builder.instantiate({ m: { ex: js_ex_i32 }}); let res = instance.exports.ex; assertEquals(res, js_ex_i32); })(); + + +(function TestExceptionConstructor() { + print(arguments.callee.name); + // Check errors. + let js_tag = new WebAssembly.Tag({parameters: []}); + assertThrows(() => new WebAssembly.Exception(0), TypeError, + /Argument 0 must be a WebAssembly tag/); + assertThrows(() => new WebAssembly.Exception({}), TypeError, + /Argument 0 must be a WebAssembly tag/); + assertThrows(() => WebAssembly.Exception(js_tag), TypeError, + /WebAssembly.Exception must be invoked with 'new'/); + let js_exception = new WebAssembly.Exception(js_tag, []); + + // Check prototype. + assertSame(WebAssembly.Exception.prototype, js_exception.__proto__); + assertTrue(js_exception instanceof WebAssembly.Exception); + + // Check prototype of a thrown exception. + let builder = new WasmModuleBuilder(); + let wasm_tag = builder.addTag(kSig_v_v); + builder.addFunction("throw", kSig_v_v) + .addBody([kExprThrow, wasm_tag]).exportFunc(); + let instance = builder.instantiate(); + try { + instance.exports.throw(); + } catch (e) { + assertTrue(e instanceof WebAssembly.Exception); + } +})(); + +(function TestExceptionConstructorWithPayload() { + print(arguments.callee.name); + let tag = new WebAssembly.Tag( + {parameters: ['i32', 'f32', 'i64', 'f64', 'externref']}); + assertThrows(() => new WebAssembly.Exception( + tag, [1n, 2, 3n, 4, {}]), TypeError); + assertDoesNotThrow(() => new WebAssembly.Exception(tag, [3, 4, 5n, 6, {}])); +})(); + +(function TestCatchJSException() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + let js_tag = new WebAssembly.Tag({parameters: []}); + let js_func_index = builder.addImport('m', 'js_func', kSig_v_v); + let js_tag_index = builder.addImportedTag("m", "js_tag", kSig_v_v); + let tag_index = builder.addTag(kSig_v_v); + builder.addExportOfKind("wasm_tag", kExternalTag, tag_index); + builder.addFunction("catch", kSig_i_v) + .addBody([ + kExprTry, kWasmI32, + kExprCallFunction, js_func_index, + kExprI32Const, 0, + kExprCatch, js_tag_index, + kExprI32Const, 1, + kExprCatch, tag_index, + kExprI32Const, 2, + kExprEnd + ]).exportFunc(); + let tag; + function js_func() { + throw new WebAssembly.Exception(tag, []); + } + let instance = builder.instantiate({m: {js_func, js_tag}}); + tag = js_tag; + assertEquals(1, instance.exports.catch()); + tag = instance.exports.wasm_tag; + assertEquals(2, instance.exports.catch()); +})(); + +function TestCatchJS(types_str, types, values) { + // Create a JS exception, catch it in wasm and check the unpacked value(s). + let builder = new WasmModuleBuilder(); + let js_tag = new WebAssembly.Tag({parameters: types_str}); + let js_func_index = builder.addImport('m', 'js_func', kSig_v_v); + let sig1 = makeSig(types, []); + let sig2 = makeSig([], types); + let js_tag_index = builder.addImportedTag("m", "js_tag", sig1); + let tag_index = builder.addTag(sig1); + let return_type = builder.addType(sig2); + builder.addExportOfKind("wasm_tag", kExternalTag, tag_index); + builder.addFunction("catch", sig2) + .addBody([ + kExprTry, return_type, + kExprCallFunction, js_func_index, + kExprUnreachable, + kExprCatch, js_tag_index, + kExprCatch, tag_index, + kExprEnd + ]).exportFunc(); + let exception; + function js_func() { + throw exception; + } + let expected = values.length == 1 ? values[0] : values; + let instance = builder.instantiate({m: {js_func, js_tag}}); + exception = new WebAssembly.Exception(js_tag, values); + assertEquals(expected, instance.exports.catch()); + exception = new WebAssembly.Exception(instance.exports.wasm_tag, values); + assertEquals(expected, instance.exports.catch()); +} + +(function TestCatchJSExceptionWithPayload() { + print(arguments.callee.name); + TestCatchJS(['i32'], [kWasmI32], [1]); + TestCatchJS(['i64'], [kWasmI64], [2n]); + TestCatchJS(['f32'], [kWasmF32], [3]); + TestCatchJS(['f64'], [kWasmF64], [4]); + TestCatchJS(['externref'], [kWasmExternRef], [{value: 5}]); + TestCatchJS(['i32', 'i64', 'f32', 'f64', 'externref'], + [kWasmI32, kWasmI64, kWasmF32, kWasmF64, kWasmExternRef], + [6, 7n, 8, 9, {value: 10}]); +})(); + +function TestGetArgHelper(types_str, types, values) { + let tag = new WebAssembly.Tag({parameters: types_str}); + let exception = new WebAssembly.Exception(tag, values); + for (i = 0; i < types.length; ++i) { + assertEquals(exception.getArg(tag, i), values[i]); + } + + let builder = new WasmModuleBuilder(); + let sig = makeSig(types, []); + let tag_index = builder.addImportedTag("m", "t", sig); + let body = []; + for (i = 0; i < types.length; ++i) { + body.push(kExprLocalGet, i); + } + body.push(kExprThrow, tag_index); + builder.addFunction("throw", sig) + .addBody(body).exportFunc(); + let instance = builder.instantiate({'m': {'t': tag}}); + try { + instance.exports.throw(...values); + } catch (e) { + for (i = 0; i < types.length; ++i) { + assertEquals(e.getArg(tag, i), values[i]); + } + } +} + +(function TestGetArg() { + // Check errors. + let tag = new WebAssembly.Tag({parameters: ['i32']}); + let exception = new WebAssembly.Exception(tag, [0]); + assertThrows(() => exception.getArg(0, 0), TypeError, + /Argument 0 must be a WebAssembly.Tag/); + assertThrows(() => exception.getArg({}, 0), TypeError, + /Argument 0 must be a WebAssembly.Tag/); + assertThrows(() => exception.getArg(tag, undefined), TypeError, + /Index must be convertible to a valid number/); + assertThrows(() => exception.getArg(tag, 0xFFFFFFFF), RangeError, + /Index out of range/); + let wrong_tag = new WebAssembly.Tag({parameters: ['i32']}); + assertThrows(() => exception.getArg(wrong_tag, 0), TypeError, + /First argument does not match the exception tag/); + + // Check decoding. + TestGetArgHelper(['i32'], [kWasmI32], [1]); + TestGetArgHelper(['i64'], [kWasmI64], [2n]); + TestGetArgHelper(['f32'], [kWasmF32], [3]); + TestGetArgHelper(['f64'], [kWasmF64], [4]); + TestGetArgHelper(['externref'], [kWasmExternRef], [{val: 5}]); + TestGetArgHelper(['i32', 'i64', 'f32', 'f64', 'externref'], [kWasmI32, kWasmI64, kWasmF32, kWasmF64, kWasmExternRef], [5, 6n, 7, 8, {val: 9}]); +})(); + +(function TestExceptionIs() { + print(arguments.callee.name); + let tag1 = new WebAssembly.Tag({parameters: []}); + let tag2 = new WebAssembly.Tag({parameters: []}); + assertThrows(() => new WebAssembly.Exception({}, []), TypeError, + /Argument 0 must be a WebAssembly tag/); + + let exception = new WebAssembly.Exception(tag1, []); + assertTrue(exception.is(tag1)); + assertFalse(exception.is(tag2)); + + assertThrows(() => exception.is.apply({}, tag1), TypeError, + /Expected a WebAssembly.Exception object/); +})(); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-export.js b/deps/v8/test/mjsunit/wasm/exceptions-export.js index 823688bdee..1bd2cc0602 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-export.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-export.js @@ -9,11 +9,11 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); (function TestExportMultiple() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); - let except2 = builder.addException(kSig_v_i); - builder.addExportOfKind("ex1a", kExternalException, except1); - builder.addExportOfKind("ex1b", kExternalException, except1); - builder.addExportOfKind("ex2", kExternalException, except2); + 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); let instance = builder.instantiate(); assertTrue(Object.prototype.hasOwnProperty.call(instance.exports, 'ex1a')); @@ -26,32 +26,32 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); (function TestExportOutOfBounds() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); - builder.addExportOfKind("ex_oob", kExternalException, except + 1); + let except = builder.addTag(kSig_v_v); + builder.addExportOfKind("ex_oob", kExternalTag, except + 1); assertThrows( () => builder.instantiate(), WebAssembly.CompileError, - 'WebAssembly.Module(): exception index 1 out of bounds (1 entry) @+30'); + 'WebAssembly.Module(): tag index 1 out of bounds (1 entry) @+30'); })(); (function TestExportSameNameTwice() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); - builder.addExportOfKind("ex", kExternalException, except); - builder.addExportOfKind("ex", kExternalException, except); + let except = builder.addTag(kSig_v_v); + builder.addExportOfKind("ex", kExternalTag, except); + builder.addExportOfKind("ex", kExternalTag, except); assertThrows( () => builder.instantiate(), WebAssembly.CompileError, 'WebAssembly.Module(): Duplicate export name \'ex\' ' + - 'for exception 0 and exception 0 @+28'); + 'for tag 0 and tag 0 @+28'); })(); (function TestExportModuleGetExports() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); - builder.addExportOfKind("ex", kExternalException, except); + let except = builder.addTag(kSig_v_v); + builder.addExportOfKind("ex", kExternalTag, except); let module = new WebAssembly.Module(builder.toBuffer()); let exports = WebAssembly.Module.exports(module); - assertArrayEquals([{ name: "ex", kind: "exception" }], exports); + assertArrayEquals([{ name: "ex", kind: "tag" }], exports); })(); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-externref.js b/deps/v8/test/mjsunit/wasm/exceptions-externref.js index 6bc5ffd71b..c0505599b9 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-externref.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-externref.js @@ -11,10 +11,10 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowRefNull() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_r); + let except = builder.addTag(kSig_v_r); builder.addFunction("throw_null", kSig_v_v) .addBody([ - kExprRefNull, kWasmExternRef, + kExprRefNull, kExternRefCode, kExprThrow, except, ]).exportFunc(); let instance = builder.instantiate(); @@ -26,14 +26,14 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowCatchRefNull() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_r); + let except = builder.addTag(kSig_v_r); builder.addFunction("throw_catch_null", kSig_i_i) .addBody([ kExprTry, kWasmI32, kExprLocalGet, 0, kExprI32Eqz, kExprIf, kWasmI32, - kExprRefNull, kWasmExternRef, + kExprRefNull, kExternRefCode, kExprThrow, except, kExprElse, kExprI32Const, 42, @@ -57,7 +57,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowRefParam() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_r); + let except = builder.addTag(kSig_v_r); builder.addFunction("throw_param", kSig_v_r) .addBody([ kExprLocalGet, 0, @@ -76,10 +76,10 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowCatchRefParam() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_r); + let except = builder.addTag(kSig_v_r); builder.addFunction("throw_catch_param", kSig_r_r) .addBody([ - kExprTry, kWasmExternRef, + kExprTry, kExternRefCode, kExprLocalGet, 0, kExprThrow, except, kExprCatch, except, diff --git a/deps/v8/test/mjsunit/wasm/exceptions-import.js b/deps/v8/test/mjsunit/wasm/exceptions-import.js index 500a9168de..8297c90ce7 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-import.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-import.js @@ -9,32 +9,32 @@ 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() { +function NewExportedTag() { let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); - builder.addExportOfKind("ex", kExternalException, except); + let tag = builder.addTag(kSig_v_v); + builder.addExportOfKind("t", kExternalTag, tag); let instance = builder.instantiate(); - return instance.exports.ex; + return instance.exports.t; } (function TestImportSimple() { print(arguments.callee.name); - let exported = NewExportedException(); + let exported = NewExportedTag(); let builder = new WasmModuleBuilder(); - let except = builder.addImportedException("m", "ex", kSig_v_v); + let except = builder.addImportedTag("m", "ex", kSig_v_v); assertDoesNotThrow(() => builder.instantiate({ m: { ex: exported }})); })(); (function TestImportMultiple() { print(arguments.callee.name); - let exported = NewExportedException(); + let exported = NewExportedTag(); 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 except1 = builder.addImportedTag("m", "ex1", kSig_v_v); + let except2 = builder.addImportedTag("m", "ex2", kSig_v_v); + let except3 = builder.addTag(kSig_v_v); + builder.addExportOfKind("ex2", kExternalTag, except2); + builder.addExportOfKind("ex3", kExternalTag, except3); let instance = builder.instantiate({ m: { ex1: exported, ex2: exported }}); assertTrue(except1 < except3 && except2 < except3); @@ -46,50 +46,50 @@ function NewExportedException() { (function TestImportMissing() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addImportedException("m", "ex", kSig_v_v); + let except = builder.addImportedTag("m", "ex", kSig_v_v); assertThrows( () => builder.instantiate({}), TypeError, /module is not an object or function/); assertThrows( () => builder.instantiate({ m: {}}), WebAssembly.LinkError, - /exception import requires a WebAssembly.Exception/); + /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); + let except = builder.addImportedTag("m", "ex", kSig_v_v); assertThrows( () => builder.instantiate({ m: { ex: 23 }}), WebAssembly.LinkError, - /exception import requires a WebAssembly.Exception/); + /tag import requires a WebAssembly.Tag/); assertThrows( () => builder.instantiate({ m: { ex: {} }}), WebAssembly.LinkError, - /exception import requires a WebAssembly.Exception/); - var monkey = Object.create(NewExportedException()); + /tag import requires a WebAssembly.Tag/); + var monkey = Object.create(NewExportedTag()); assertThrows( () => builder.instantiate({ m: { ex: monkey }}), WebAssembly.LinkError, - /exception import requires a WebAssembly.Exception/); + /tag import requires a WebAssembly.Tag/); })(); (function TestImportSignatureMismatch() { print(arguments.callee.name); - let exported = NewExportedException(); + let exported = NewExportedTag(); let builder = new WasmModuleBuilder(); - let except = builder.addImportedException("m", "ex", kSig_v_i); + let except = builder.addImportedTag("m", "ex", kSig_v_i); assertThrows( () => builder.instantiate({ m: { ex: exported }}), WebAssembly.LinkError, - /imported exception does not match the expected type/); + /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 except = builder.addImportedTag("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); + assertArrayEquals([{ module: "m", name: "ex", kind: "tag" }], imports); })(); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-rethrow.js b/deps/v8/test/mjsunit/wasm/exceptions-rethrow.js index 7920ac73f8..13421a4cf1 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-rethrow.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-rethrow.js @@ -11,7 +11,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestRethrowInCatch() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction("rethrow0", kSig_v_v) .addBody([ kExprTry, kWasmVoid, @@ -44,7 +44,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestRethrowInCatchAll() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction("rethrow0", kSig_v_v) .addBody([ kExprTry, kWasmVoid, @@ -78,8 +78,8 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestRethrowNested() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); - let except2 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); + let except2 = builder.addTag(kSig_v_v); builder.addFunction("rethrow_nested", kSig_i_i) .addBody([ kExprTry, kWasmI32, @@ -116,7 +116,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestRethrowRecatch() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction("rethrow_recatch", kSig_i_i) .addBody([ kExprTry, kWasmI32, diff --git a/deps/v8/test/mjsunit/wasm/exceptions-shared.js b/deps/v8/test/mjsunit/wasm/exceptions-shared.js index 4c2f8a7fde..3bf2883000 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-shared.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-shared.js @@ -10,8 +10,8 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); // signature from an anonymous module. The underlying module is thrown away. function NewExportedException() { let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); - builder.addExportOfKind("ex", kExternalException, except); + let except = builder.addTag(kSig_v_v); + builder.addExportOfKind("ex", kExternalTag, except); let instance = builder.instantiate(); return instance.exports.ex; } @@ -23,7 +23,7 @@ function NewExportedException() { let builder = new WasmModuleBuilder(); let sig_index = builder.addType(kSig_v_v); let fun = builder.addImport("m", "f", sig_index); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction("throw", kSig_v_v) .addBody([ kExprThrow, except @@ -38,7 +38,7 @@ function NewExportedException() { let ex_obj = new Error("my exception"); let instance = builder.instantiate({ m: { f: function() { throw ex_obj }}}); - assertThrows(() => instance.exports.throw(), WebAssembly.RuntimeError); + assertThrows(() => instance.exports.throw(), WebAssembly.Exception); assertThrowsEquals(() => instance.exports.catch(), ex_obj); try { instance.exports.throw(); @@ -55,7 +55,7 @@ function NewExportedException() { let builder = new WasmModuleBuilder(); let sig_index = builder.addType(kSig_v_v); let fun = builder.addImport("m", "f", sig_index); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction("throw", kSig_v_v) .addBody([ kExprThrow, except @@ -71,7 +71,7 @@ function NewExportedException() { let instance1 = builder.instantiate({ m: { f: assertUnreachable }}); let instance2 = builder.instantiate({ m: { f: function() { throw ex_obj }}}); - assertThrows(() => instance1.exports.throw(), WebAssembly.RuntimeError); + assertThrows(() => instance1.exports.throw(), WebAssembly.Exception); assertThrowsEquals(() => instance2.exports.catch(), ex_obj); try { instance1.exports.throw(); @@ -88,9 +88,9 @@ function NewExportedException() { let builder = new WasmModuleBuilder(); let sig_index = builder.addType(kSig_v_v); let fun = builder.addImport("m", "f", sig_index); - let except1 = builder.addImportedException("m", "ex1", kSig_v_v); - let except2 = builder.addException(kSig_v_v); - builder.addExportOfKind("ex2", kExternalException, except2); + let except1 = builder.addImportedTag("m", "ex1", kSig_v_v); + let except2 = builder.addTag(kSig_v_v); + builder.addExportOfKind("ex2", kExternalTag, except2); builder.addFunction("throw", kSig_v_v) .addBody([ kExprThrow, except2 @@ -108,7 +108,7 @@ function NewExportedException() { let instance2 = builder.instantiate({ m: { f: function() { throw ex_obj }, ex1: instance1.exports.ex2 }}); - assertThrows(() => instance1.exports.throw(), WebAssembly.RuntimeError); + assertThrows(() => instance1.exports.throw(), WebAssembly.Exception); assertThrowsEquals(() => instance2.exports.catch(), ex_obj); try { instance1.exports.throw(); @@ -123,9 +123,9 @@ function NewExportedException() { (function TestMultiModuleShared() { print(arguments.callee.name); let builder1 = new WasmModuleBuilder(); - let except1 = builder1.addException(kSig_v_v); - let except2 = builder1.addException(kSig_v_v); - builder1.addExportOfKind("ex", kExternalException, except2); + let except1 = builder1.addTag(kSig_v_v); + let except2 = builder1.addTag(kSig_v_v); + builder1.addExportOfKind("ex", kExternalTag, except2); builder1.addFunction("throw", kSig_v_v) .addBody([ kExprThrow, except2 @@ -133,7 +133,7 @@ function NewExportedException() { let builder2 = new WasmModuleBuilder(); let sig_index = builder2.addType(kSig_v_v); let fun = builder2.addImport("m", "f", sig_index); - let except = builder2.addImportedException("m", "ex", kSig_v_v); + let except = builder2.addImportedTag("m", "ex", kSig_v_v); builder2.addFunction("catch", kSig_v_v) .addBody([ kExprTry, kWasmVoid, @@ -146,7 +146,7 @@ function NewExportedException() { let instance2 = builder2.instantiate({ m: { f: function() { throw ex_obj }, ex: instance1.exports.ex }}); - assertThrows(() => instance1.exports.throw(), WebAssembly.RuntimeError); + assertThrows(() => instance1.exports.throw(), WebAssembly.Exception); assertThrowsEquals(() => instance2.exports.catch(), ex_obj); try { instance1.exports.throw(); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-simd.js b/deps/v8/test/mjsunit/wasm/exceptions-simd.js index ace3322480..ed6b287ddd 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-simd.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-simd.js @@ -11,7 +11,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); print(arguments.callee.name); var builder = new WasmModuleBuilder(); var kSig_v_s = makeSig([kWasmS128], []); - var except = builder.addException(kSig_v_s); + var except = builder.addTag(kSig_v_s); builder.addFunction("throw_simd", kSig_v_v) .addLocals(kWasmS128, 1) .addBody([ @@ -29,7 +29,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); print(arguments.callee.name); var builder = new WasmModuleBuilder(); var kSig_v_s = makeSig([kWasmS128], []); - var except = builder.addException(kSig_v_s); + var except = builder.addTag(kSig_v_s); builder.addFunction("throw_catch_simd", kSig_i_v) .addLocals(kWasmS128, 1) .addBody([ @@ -52,7 +52,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); print(arguments.callee.name); var builder = new WasmModuleBuilder(); var kSig_v_s = makeSig([kWasmS128], []); - var except = builder.addException(kSig_v_s); + var except = builder.addTag(kSig_v_s); const in_idx = 0x10; // Input index in memory. const out_idx = 0x20; // Output index in memory. builder.addImportedMemory("env", "memory"); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-type-reflection.js b/deps/v8/test/mjsunit/wasm/exceptions-type-reflection.js new file mode 100644 index 0000000000..a17d30ed10 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/exceptions-type-reflection.js @@ -0,0 +1,49 @@ +// 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 --experimental-wasm-type-reflection + +load("test/mjsunit/wasm/wasm-module-builder.js"); + +let testcases = [ +{types: {parameters:[]}, sig: kSig_v_v}, +{types: {parameters:["i32"]}, sig: kSig_v_i}, +{types: {parameters:["i64"]}, sig: kSig_v_l}, +{types: {parameters:["f64", "f64", "i32"]}, sig: kSig_v_ddi}, +{types: {parameters:["f32"]}, sig: kSig_v_f}, +]; + +(function TestExport() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + + testcases.forEach(function(expected, i) { + let except = builder.addTag(expected.sig); + builder.addExportOfKind("ex" + i, kExternalTag, except); + }); + + let instance = builder.instantiate(); + testcases.forEach(function(expected, i) { + assertEquals(instance.exports["ex" + i].type(), expected.types); + }); +})(); + +(function TestImportExport() { + print(arguments.callee.name); + + let builder = new WasmModuleBuilder(); + let imports = {m: {}}; + + testcases.forEach(function(expected, i) { + let t = new WebAssembly.Tag(expected.types); + let index = builder.addImportedTag("m", "ex" + i, expected.sig); + builder.addExportOfKind("ex" + i, kExternalTag, index); + imports.m["ex" + i] = t; + }); + + let instance = builder.instantiate(imports); + testcases.forEach(function(expected, i) { + assertEquals(instance.exports["ex" + i].type(), expected.types); + }) +})(); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-utils.js b/deps/v8/test/mjsunit/wasm/exceptions-utils.js index 344ca64da1..218f87f33e 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-utils.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-utils.js @@ -15,8 +15,8 @@ function assertWasmThrows(instance, runtime_id, values, code) { eval(code); } } catch (e) { - assertInstanceof(e, WebAssembly.RuntimeError); - var e_runtime_id = %GetWasmExceptionId(e, instance); + assertInstanceof(e, WebAssembly.Exception); + var e_runtime_id = %GetWasmExceptionTagId(e, instance); assertTrue(Number.isInteger(e_runtime_id)); assertEquals(e_runtime_id, runtime_id); var e_values = %GetWasmExceptionValues(e); diff --git a/deps/v8/test/mjsunit/wasm/exceptions.js b/deps/v8/test/mjsunit/wasm/exceptions.js index 578fa09e25..db4d6ed9bb 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions.js +++ b/deps/v8/test/mjsunit/wasm/exceptions.js @@ -11,7 +11,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowSimple() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction("throw_if_param_not_zero", kSig_i_i) .addBody([ kExprLocalGet, 0, @@ -33,7 +33,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestCatchEmptyBlocks() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction("catch_empty_try", kSig_v_v) .addBody([ kExprTry, kWasmVoid, @@ -49,7 +49,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestCatchSimple() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction("simple_throw_catch_to_0_1", kSig_i_i) .addBody([ kExprTry, kWasmI32, @@ -173,7 +173,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestExnWithWasmProtoNotCaught() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); let imp = builder.addImport('imp', 'ort', kSig_v_v); let throw_fn = builder.addFunction('throw', kSig_v_v) .addBody([kExprThrow, except]) @@ -212,7 +212,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); } assertTrue(!!caught, 'should have trapped'); assertEquals(caught, wrapped_exn); - assertInstanceof(caught.__proto__, WebAssembly.RuntimeError); + assertInstanceof(caught.__proto__, WebAssembly.Exception); })(); (function TestStackOverflowNotCaught() { @@ -241,9 +241,9 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestCatchComplex1() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); - let except2 = builder.addException(kSig_v_v); - let except3 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); + let except2 = builder.addTag(kSig_v_v); + let except3 = builder.addTag(kSig_v_v); builder.addFunction("catch_complex", kSig_i_i) .addBody([ kExprTry, kWasmI32, @@ -282,9 +282,9 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestCatchComplex2() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); - let except2 = builder.addException(kSig_v_v); - let except3 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); + let except2 = builder.addTag(kSig_v_v); + let except3 = builder.addTag(kSig_v_v); builder.addFunction("catch_complex", kSig_i_i) .addBody([ kExprTry, kWasmI32, @@ -320,7 +320,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowMultipleValues() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_ii); + let except = builder.addTag(kSig_v_ii); builder.addFunction("throw_1_2", kSig_v_v) .addBody([ kExprI32Const, 1, @@ -336,7 +336,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowCatchParamI() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_i); + let except = builder.addTag(kSig_v_i); builder.addFunction("throw_catch_param", kSig_i_i) .addBody([ kExprTry, kWasmI32, @@ -358,7 +358,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowParamI() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_i); + let except = builder.addTag(kSig_v_i); builder.addFunction("throw_param", kSig_v_i) .addBody([ kExprLocalGet, 0, @@ -374,7 +374,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowCatchParamF() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_f); + let except = builder.addTag(kSig_v_f); builder.addFunction("throw_catch_param", kSig_f_f) .addBody([ kExprTry, kWasmF32, @@ -395,7 +395,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowParamF() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_f); + let except = builder.addTag(kSig_v_f); builder.addFunction("throw_param", kSig_v_f) .addBody([ kExprLocalGet, 0, @@ -411,7 +411,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowCatchParamL() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_l); + let except = builder.addTag(kSig_v_l); builder.addFunction("throw_catch_param", kSig_i_i) .addLocals(kWasmI64, 1) .addBody([ @@ -443,7 +443,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowParamL() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_l); + let except = builder.addTag(kSig_v_l); builder.addFunction("throw_param", kSig_v_ii) .addBody([ kExprLocalGet, 0, @@ -465,7 +465,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowCatchParamD() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_d); + let except = builder.addTag(kSig_v_d); builder.addFunction("throw_catch_param", kSig_d_d) .addBody([ kExprTry, kWasmF64, @@ -486,7 +486,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowParamD() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_d); + let except = builder.addTag(kSig_v_d); builder.addFunction("throw_param", kSig_v_f) .addBody([ kExprLocalGet, 0, @@ -503,7 +503,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowParamComputed() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_i); + let except = builder.addTag(kSig_v_i); builder.addFunction("throw_expr_with_params", kSig_v_ddi) .addBody([ // p2 * (p0 + min(p0, p1))|0 - 20 @@ -530,7 +530,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestCatchCrossFunctions() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_i); + let except = builder.addTag(kSig_v_i); // Helper function for throwing from JS. It is imported by the Wasm module // as throw_i. @@ -816,7 +816,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestDelegateNoThrow() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); builder.addFunction('test', kSig_i_v) .addBody([ kExprTry, kWasmI32, @@ -835,7 +835,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestDelegateThrow() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); let throw_if = builder.addFunction('throw', kSig_v_i) .addBody([ kExprLocalGet, 0, @@ -863,8 +863,8 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestDelegateThrowNoCatch() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); - let except2 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); + let except2 = builder.addTag(kSig_v_v); let throw_fn = builder.addFunction('throw', kSig_v_v) .addBody([kExprThrow, except1]) .exportFunc(); @@ -883,15 +883,15 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); kExprEnd, ]).exportFunc(); instance = builder.instantiate(); - assertTraps(WebAssembly.RuntimeError, instance.exports.test); + assertThrows(instance.exports.test, WebAssembly.Exception); })(); // Check that the exception is merged properly when both scopes can throw. (function TestDelegateMerge() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); - let except2 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); + let except2 = builder.addTag(kSig_v_v); // throw_fn: 0 -> returns // 1 -> throw except1 // 2 -> throw except2 @@ -925,9 +925,9 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); ]).exportFunc(); instance = builder.instantiate(); assertEquals(2, instance.exports.test(1, 0)); - assertTraps(WebAssembly.RuntimeError, () => instance.exports.test(2, 0)); + assertThrows(() => instance.exports.test(2, 0), WebAssembly.Exception); assertEquals(2, instance.exports.test(0, 1)); - assertTraps(WebAssembly.RuntimeError, () => instance.exports.test(0, 2)); + assertThrows(() => instance.exports.test(0, 2), WebAssembly.Exception); assertEquals(1, instance.exports.test(0, 0)); })(); @@ -935,7 +935,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestDelegate1() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); let throw_fn = builder.addFunction('throw', kSig_v_v) .addBody([kExprThrow, except]) .exportFunc(); @@ -961,8 +961,8 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestDelegateUnreachable() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); - let except2 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); + let except2 = builder.addTag(kSig_v_v); builder.addFunction('test', kSig_i_v) .addBody([ kExprTry, kWasmI32, @@ -983,7 +983,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestDelegateToCaller() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction('test', kSig_v_v) .addBody([ kExprTry, kWasmVoid, @@ -994,13 +994,13 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); kExprEnd ]).exportFunc(); instance = builder.instantiate(); - assertTraps(WebAssembly.RuntimeError, () => instance.exports.test()); + assertThrows(() => instance.exports.test(), WebAssembly.Exception); })(); (function TestThrowBeforeUnreachable() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction('throw_before_unreachable', kSig_i_v) .addBody([ kExprTry, kWasmI32, @@ -1018,7 +1018,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestUnreachableInCatchAll() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction('throw_before_unreachable', kSig_i_v) .addBody([ kExprTry, kWasmI32, @@ -1035,7 +1035,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowWithLocal() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction('throw_with_local', kSig_i_v) .addLocals(kWasmI32, 4) .addBody([ @@ -1058,7 +1058,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestCatchlessTry() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except = builder.addException(kSig_v_v); + let except = builder.addTag(kSig_v_v); builder.addFunction('catchless_try', kSig_v_i) .addBody([ kExprTry, kWasmVoid, diff --git a/deps/v8/test/mjsunit/wasm/externref.js b/deps/v8/test/mjsunit/wasm/externref.js index 7c75a2b8c0..43192a7ef7 100644 --- a/deps/v8/test/mjsunit/wasm/externref.js +++ b/deps/v8/test/mjsunit/wasm/externref.js @@ -165,7 +165,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); print(arguments.callee.name); const builder = new WasmModuleBuilder(); builder.addFunction('main', kSig_r_v) - .addBody([kExprRefNull, kWasmExternRef]) + .addBody([kExprRefNull, kExternRefCode]) .exportFunc(); const instance = builder.instantiate(); @@ -196,7 +196,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); const builder = new WasmModuleBuilder(); builder.addFunction('main', kSig_i_v) - .addBody([kExprRefNull, kWasmExternRef, kExprRefIsNull]) + .addBody([kExprRefNull, kExternRefCode, kExprRefIsNull]) .exportFunc(); const instance = builder.instantiate(); @@ -225,7 +225,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_r_v); builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kWasmExternRef]) + .addBody([kExprRefNull, kExternRefCode]) .exportFunc(); const main = builder.instantiate().exports.main; @@ -237,7 +237,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_r_v); builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kWasmExternRef, kExprReturn]) + .addBody([kExprRefNull, kExternRefCode, kExprReturn]) .exportFunc(); const main = builder.instantiate().exports.main; diff --git a/deps/v8/test/mjsunit/wasm/gc-nominal.js b/deps/v8/test/mjsunit/wasm/gc-nominal.js new file mode 100644 index 0000000000..0483b4a78f --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/gc-nominal.js @@ -0,0 +1,31 @@ +// 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-gc-experiments + +d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); + +var builder = new WasmModuleBuilder(); +let struct1 = builder.addStruct([makeField(kWasmI32, true)]); +let struct2 = builder.addStructExtending( + [makeField(kWasmI32, true), makeField(kWasmI32, true)], struct1); + +let array1 = builder.addArray(kWasmI32, true); +let array2 = builder.addArrayExtending(kWasmI32, true, array1); + +builder.addFunction("main", kSig_v_v) + .addLocals(wasmOptRefType(struct1), 1) + .addLocals(wasmOptRefType(array1), 1) + .addBody([ + kGCPrefix, kExprRttCanon, struct2, + kGCPrefix, kExprStructNewDefault, struct2, + kExprLocalSet, 0, + kExprI32Const, 10, // length + kGCPrefix, kExprRttCanon, array2, + kGCPrefix, kExprArrayNewDefault, array2, + kExprLocalSet, 1 + ]); + +// This test is only interested in type checking. +builder.instantiate(); diff --git a/deps/v8/test/mjsunit/wasm/load-elimination.js b/deps/v8/test/mjsunit/wasm/load-elimination.js new file mode 100644 index 0000000000..8ca04ed040 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/load-elimination.js @@ -0,0 +1,319 @@ +// 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-gc + +// This tests are meant to examine if Turbofan CsaLoadElimination works +// correctly for wasm. The TurboFan graphs can be examined with --trace-turbo. +d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); + +// Fresh objects, known offsets +(function LoadEliminationtFreshKnownTest() { + print(arguments.callee.name); + + let builder = new WasmModuleBuilder(); + let struct = builder.addStruct([makeField(kWasmI32, true), + makeField(kWasmI32, true)]); + + builder.addFunction("main", makeSig([kWasmI32], [kWasmI32])) + .addLocals(wasmOptRefType(struct), 1) + .addBody([ + kExprI32Const, 10, // local1 = struct(10, 100); + kExprI32Const, 100, + kGCPrefix, kExprRttCanon, struct, + kGCPrefix, kExprStructNewWithRtt, struct, + kExprLocalSet, 1, + kExprLocalGet, 0, // Split control based on an unknown value + kExprIf, kWasmI32, + kExprLocalGet, 1, // local1.field1 = 42 + kExprI32Const, 42, + kGCPrefix, kExprStructSet, struct, 1, + kExprLocalGet, 1, // local1.field1 + kGCPrefix, kExprStructGet, struct, 1, + kExprElse, + kExprLocalGet, 1, // local1.field1 = 11 + kExprI32Const, 11, + kGCPrefix, kExprStructSet, struct, 1, + kExprLocalGet, 1, // local1.field1 = 22 + kExprI32Const, 22, + kGCPrefix, kExprStructSet, struct, 1, + kExprLocalGet, 1, // local1.field1 + local1.field1 + kGCPrefix, kExprStructGet, struct, 1, + kExprLocalGet, 1, + kGCPrefix, kExprStructGet, struct, 1, + kExprI32Add, + kExprEnd, + kExprLocalGet, 1, // return if-result * (local1.field1 + local1.field0) + kGCPrefix, kExprStructGet, struct, 0, + kExprLocalGet, 1, + kGCPrefix, kExprStructGet, struct, 1, + kExprI32Add, + kExprI32Mul + ]) + .exportFunc(); + + let instance = builder.instantiate({}); + assertEquals(instance.exports.main(1), 42 * (42 + 10)); + assertEquals(instance.exports.main(0), (22 + 22) * (22 + 10)); +})(); + +(function LoadEliminationtConstantKnownTest() { + print(arguments.callee.name); + + let builder = new WasmModuleBuilder(); + let struct = builder.addStruct([makeField(kWasmI32, true)]); + + let replaced_value = 55 + let param_1_value = 42 + let init_value_1 = 5 + let init_value_2 = 17 + + let tester = builder.addFunction("tester", makeSig( + [wasmRefType(struct), wasmRefType(struct)], [kWasmI32])) + .addBody([ + kExprLocalGet, 0, + kGCPrefix, kExprStructGet, struct, 0, + + kExprLocalGet, 0, + kExprI32Const, replaced_value, + kGCPrefix, kExprStructSet, struct, 0, + + // We should eliminate this load and replace it with replaced_value + kExprLocalGet, 0, + kGCPrefix, kExprStructGet, struct, 0, + + kExprLocalGet, 1, + kExprI32Const, param_1_value, + kGCPrefix, kExprStructSet, struct, 0, + + // Although we could eliminate this load before, we cannot anymore, + // because the parameters may alias. + kExprLocalGet, 0, + kGCPrefix, kExprStructGet, struct, 0, + + kExprI32Add, kExprI32Add + ]); + + function buildStruct(value) { + return [kExprI32Const, value, kGCPrefix, kExprRttCanon, struct, + kGCPrefix, kExprStructNewWithRtt, struct]; + } + + builder.addFunction("main_non_aliasing", kSig_i_v) + .addBody([ + ...buildStruct(init_value_1), ...buildStruct(init_value_2), + kExprCallFunction, tester.index]) + .exportFunc(); + + builder.addFunction("main_aliasing", kSig_i_v) + .addLocals(wasmOptRefType(struct), 1) + .addBody([ + ...buildStruct(init_value_1), kExprLocalSet, 0, + kExprLocalGet, 0, kExprRefAsNonNull, + kExprLocalGet, 0, kExprRefAsNonNull, + kExprCallFunction, tester.index]) + .exportFunc(); + + let instance = builder.instantiate({}); + assertEquals(init_value_1 + replaced_value + replaced_value, + instance.exports.main_non_aliasing()); + assertEquals(init_value_1 + replaced_value + param_1_value, + instance.exports.main_aliasing()); +})(); + +(function LoadEliminationtArbitraryKnownTest() { + print(arguments.callee.name); + + let builder = new WasmModuleBuilder(); + let struct = builder.addStruct([makeField(kWasmI32, true)]); + + let initial_value = 19; + let replacing_value_1 = 55; + let replacing_value_2 = 37; + + let id = builder.addFunction("id", makeSig([wasmOptRefType(struct)], + [wasmOptRefType(struct)])) + .addBody([kExprLocalGet, 0]) + + builder.addFunction("main", kSig_i_v) + .addLocals(wasmOptRefType(struct), 2) + .addBody([ + // We store a fresh struct in local0 + kExprI32Const, initial_value, + kGCPrefix, kExprRttCanon, struct, + kGCPrefix, kExprStructNewWithRtt, struct, + kExprLocalSet, 0, + + // We pass it through a function and store it to local1. local1 may now + // alias with anything. + kExprLocalGet, 0, kExprCallFunction, id.index, kExprLocalSet, 1, + + kExprLocalGet, 0, + kExprI32Const, replacing_value_1, + kGCPrefix, kExprStructSet, struct, 0, + + // We should eliminate this load. + kExprLocalGet, 0, kGCPrefix, kExprStructGet, struct, 0, + + kExprLocalGet, 1, + kExprI32Const, replacing_value_2, + kGCPrefix, kExprStructSet, struct, 0, + + // We should not eliminate this load. + kExprLocalGet, 0, kGCPrefix, kExprStructGet, struct, 0, + + kExprI32Add]) + .exportFunc(); + + let instance = builder.instantiate({}); + assertEquals(replacing_value_1 + replacing_value_2, instance.exports.main()); +})(); + +(function LoadEliminationtFreshUnknownTest() { + print(arguments.callee.name); + + let builder = new WasmModuleBuilder(); + let array = builder.addArray(kWasmI64, true); + + // parameter: unknown array index + builder.addFunction("main", makeSig([kWasmI32], [kWasmI32])) + .addLocals(wasmOptRefType(array), 1) + .addBody([ + kExprI32Const, 5, + kGCPrefix, kExprRttCanon, array, + kGCPrefix, kExprArrayNewDefault, array, + kExprLocalSet, 1, + + kExprLocalGet, 1, // a[i] = i for i = {0..4} + kExprI32Const, 0, + kExprI64Const, 0, + kGCPrefix, kExprArraySet, array, + + kExprLocalGet, 1, + kExprI32Const, 1, + kExprI64Const, 1, + kGCPrefix, kExprArraySet, array, + + kExprLocalGet, 1, + kExprI32Const, 2, + kExprI64Const, 2, + kGCPrefix, kExprArraySet, array, + + kExprLocalGet, 1, + kExprI32Const, 3, + kExprI64Const, 3, + kGCPrefix, kExprArraySet, array, + + kExprLocalGet, 1, + kExprI32Const, 4, + kExprI64Const, 4, + kGCPrefix, kExprArraySet, array, + + // Get a constant index a[4] before setting unknown indices + kExprLocalGet, 1, + kExprI32Const, 4, + kGCPrefix, kExprArrayGet, array, + + kExprLocalGet, 1, // Set a[local0] = 33 + kExprLocalGet, 0, + kExprI64Const, 33, + kGCPrefix, kExprArraySet, array, + + kExprLocalGet, 1, // Get a[local0] + kExprLocalGet, 0, + kGCPrefix, kExprArrayGet, array, + + kExprLocalGet, 1, // Known index load cannot be eliminated anymore + kExprI32Const, 3, + kGCPrefix, kExprArrayGet, array, + + // A load from different unknown index a[local0 + 1] cannot be eliminated + kExprLocalGet, 1, + kExprLocalGet, 0, + kExprI32Const, 1, + kExprI32Add, + kGCPrefix, kExprArrayGet, array, + + kExprI64Add, // return a[4] * (a[local0] - (a[3] + a[local0 + 1])) + kExprI64Sub, + kExprI64Mul, + kExprI32ConvertI64 // To not have to worry about BigInts in JS world + ]) + .exportFunc(); + + let instance = builder.instantiate({}); + assertEquals(4 * (33 - (3 + 1)), instance.exports.main(0)); + assertEquals(4 * (33 - (3 + 2)), instance.exports.main(1)); + assertEquals(4 * (33 - (3 + 3)), instance.exports.main(2)); + assertEquals(4 * (33 - (33 + 4)), instance.exports.main(3)); +})(); + +(function LoadEliminationtAllBetsAreOffTest() { + print(arguments.callee.name); + + let builder = new WasmModuleBuilder(); + let struct = builder.addStruct([makeField(kWasmI32, true)]); + let array = builder.addArray(kWasmI32, true); + + let value_0 = 19; + let value_1 = 55; + let value_2 = 2; + + let id = builder.addFunction("id", makeSig([wasmOptRefType(array)], + [wasmOptRefType(array)])) + .addBody([kExprLocalGet, 0]) + + // parameters: array, index + let tester = builder.addFunction("tester", + makeSig([wasmRefType(array), kWasmI32], [kWasmI32])) + .addLocals(wasmOptRefType(struct), 1) + .addLocals(wasmOptRefType(array), 1) + .addBody([ + // We store a fresh struct in local1 + kExprI32Const, 0, + kGCPrefix, kExprRttCanon, struct, + kGCPrefix, kExprStructNewWithRtt, struct, + kExprLocalSet, 2, + + // We pass the array parameter through a function and store it to local2. + kExprLocalGet, 0, kExprCallFunction, id.index, kExprLocalSet, 3, + + // Set the parameter array, the fresh struct, then the arbitrary array to + // an unknown offset. + kExprLocalGet, 0, + kExprI32Const, 5, + kExprI32Const, value_0, + kGCPrefix, kExprArraySet, array, + + kExprLocalGet, 2, + kExprI32Const, value_1, + kGCPrefix, kExprStructSet, struct, 0, + + kExprLocalGet, 3, + kExprLocalGet, 1, + kExprI32Const, value_2, + kGCPrefix, kExprArraySet, array, + + // Neither load can be eliminated. + kExprLocalGet, 0, + kExprI32Const, 5, + kGCPrefix, kExprArrayGet, array, + + kExprLocalGet, 2, + kGCPrefix, kExprStructGet, struct, 0, + + kExprI32Add]); + + builder.addFunction("main", kSig_i_i) + .addBody([ + kExprI32Const, 10, kGCPrefix, kExprRttCanon, array, + kGCPrefix, kExprArrayNewDefault, array, + kExprI32Const, 7, + kExprCallFunction, tester.index, + ]) + .exportFunc(); + + let instance = builder.instantiate({}); + assertEquals(value_0 + value_1, instance.exports.main()); +})(); diff --git a/deps/v8/test/mjsunit/wasm/loop-unrolling.js b/deps/v8/test/mjsunit/wasm/loop-unrolling.js index a20701f381..881a4567cc 100644 --- a/deps/v8/test/mjsunit/wasm/loop-unrolling.js +++ b/deps/v8/test/mjsunit/wasm/loop-unrolling.js @@ -93,8 +93,8 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestRethrowNested() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); - let except2 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); + let except2 = builder.addTag(kSig_v_v); builder.addFunction("rethrow_nested", kSig_i_i) .addBody([ kExprLoop, kWasmI32, @@ -139,7 +139,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrow() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); builder.addFunction("throw", kSig_i_i) .addBody([ kExprLoop, kWasmVoid, @@ -167,7 +167,7 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js"); (function TestThrowCatch() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - let except1 = builder.addException(kSig_v_v); + let except1 = builder.addTag(kSig_v_v); builder.addFunction("throw_catch", kSig_i_i) .addBody([ kExprLoop, kWasmI32, diff --git a/deps/v8/test/mjsunit/wasm/stack.js b/deps/v8/test/mjsunit/wasm/stack.js index f0328274e8..5547c9c62f 100644 --- a/deps/v8/test/mjsunit/wasm/stack.js +++ b/deps/v8/test/mjsunit/wasm/stack.js @@ -23,7 +23,7 @@ function verifyStack(frames, expected) { assertContains(exp[4], frames[i].getFileName(), "["+i+"].getFileName()"); var toString; if (exp[0]) { - toString = "<anonymous>:wasm-function[" + exp[6] + "]:" + exp[5]; + toString = exp[4] + ":wasm-function[" + exp[6] + "]:" + exp[5]; if (exp[1] !== null) toString = exp[1] + " (" + toString + ")"; } else { toString = exp[4] + ":" + exp[2] + ":"; @@ -68,10 +68,10 @@ var module = builder.instantiate({mod: {func: STACK}}); (function testSimpleStack() { var expected_string = 'Error\n' + // The line numbers below will change as this test gains / loses lines.. - ' at STACK (stack.js:38:11)\n' + // -- - ' at main (<anonymous>:wasm-function[1]:0x72)\n' + // -- - ' at testSimpleStack (stack.js:76:18)\n' + // -- - ' at stack.js:78:3'; // -- + ' at STACK (stack.js:38:11)\n' + // -- + ' at main (wasm://wasm/862e1cf6:wasm-function[1]:0x72)\n' + // -- + ' at testSimpleStack (stack.js:76:18)\n' + // -- + ' at stack.js:78:3'; // -- module.exports.main(); assertEquals(expected_string, stripPath(stack)); diff --git a/deps/v8/test/mjsunit/wasm/test-partial-serialization.js b/deps/v8/test/mjsunit/wasm/test-partial-serialization.js new file mode 100644 index 0000000000..150c5c8e69 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/test-partial-serialization.js @@ -0,0 +1,56 @@ +// 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: --allow-natives-syntax --liftoff --no-wasm-tier-up --expose-gc +// Compile functions 0 and 2 with Turbofan, the rest with Liftoff: +// Flags: --wasm-tier-mask-for-testing=5 + +d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); + +const num_functions = 5; + +function create_builder() { + const builder = new WasmModuleBuilder(); + for (let i = 0; i < num_functions; ++i) { + builder.addFunction('f' + i, kSig_i_v) + .addBody(wasmI32Const(i)) + .exportFunc(); + } + return builder; +} + +function check(instance) { + for (let i = 0; i < num_functions; ++i) { + const expect_liftoff = i != 0 && i != 2; + assertEquals( + expect_liftoff, %IsLiftoffFunction(instance.exports['f' + i]), + 'function ' + i); + } +} + +const wire_bytes = create_builder().toBuffer(); + +function testTierTestingFlag() { + print(arguments.callee.name); + const module = new WebAssembly.Module(wire_bytes); + const buff = %SerializeWasmModule(module); + const instance = new WebAssembly.Instance(module); + check(instance); + return buff; +}; + +const serialized_module = testTierTestingFlag(); +// Do some GCs to make sure the first module got collected and removed from the +// module cache. +gc(); +gc(); +gc(); + +(function testSerializedModule() { + print(arguments.callee.name); + const module = %DeserializeWasmModule(serialized_module, wire_bytes); + + const instance = new WebAssembly.Instance(module); + check(instance); +})(); diff --git a/deps/v8/test/mjsunit/wasm/test-serialization-with-lazy-compilation.js b/deps/v8/test/mjsunit/wasm/test-serialization-with-lazy-compilation.js new file mode 100644 index 0000000000..ad1d54a594 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/test-serialization-with-lazy-compilation.js @@ -0,0 +1,43 @@ +// 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: --allow-natives-syntax --wasm-lazy-compilation --expose-gc + +d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); + +const num_functions = 2; + +function create_builder() { + const builder = new WasmModuleBuilder(); + for (let i = 0; i < num_functions; ++i) { + builder.addFunction('f' + i, kSig_i_v) + .addBody(wasmI32Const(i)) + .exportFunc(); + } + return builder; +} + +const wire_bytes = create_builder().toBuffer(); + +function serializeModule() { + const module = new WebAssembly.Module(wire_bytes); + const buff = %SerializeWasmModule(module); + return buff; +}; + +const serialized_module = serializeModule(); +// Do some GCs to make sure the first module got collected and removed from the +// module cache. +gc(); +gc(); +gc(); + +(function testSerializedModule() { + print(arguments.callee.name); + const module = %DeserializeWasmModule(serialized_module, wire_bytes); + + const instance = new WebAssembly.Instance(module); + assertEquals(0, instance.exports.f0()); + assertEquals(1, instance.exports.f1()); +})(); diff --git a/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js b/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js index 0b01df4427..3915109bbe 100644 --- a/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js +++ b/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --expose-wasm +// Flags: --expose-wasm --experimental-wasm-typed-funcref d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); @@ -183,3 +183,24 @@ function instantiate(buffer, ffi) { assertEquals(i, instance.exports.main()); } })(); + +(function TestBigTypeIndices() { + print(arguments.callee.name); + // These are all positive type indices (e.g. kI31RefCode and not kWasmI31Ref) + // and should be treated as such. + let indices = [kI31RefCode, kDataRefCode, 200, 400]; + let kMaxIndex = 400; + let builder = new WasmModuleBuilder(); + for (let i = 0; i <= kMaxIndex; i++) { + builder.addType(kSig_i_i); + builder.addFunction(undefined, i) + .addBody([kExprLocalGet, 0]); + builder.addGlobal(wasmRefType(i), false, WasmInitExpr.RefFunc(i)); + } + for (let i of indices) { + builder.addFunction('f_' + i, makeSig([], [wasmRefType(i)])) + .addBody([kExprRefFunc, ...wasmSignedLeb(i, 5)]) + .exportFunc(); + } + builder.instantiate(); +})(); diff --git a/deps/v8/test/mjsunit/wasm/wasm-array-js-interop.js b/deps/v8/test/mjsunit/wasm/wasm-array-js-interop.js index 7f7c411c34..e3f0891256 100644 --- a/deps/v8/test/mjsunit/wasm/wasm-array-js-interop.js +++ b/deps/v8/test/mjsunit/wasm/wasm-array-js-interop.js @@ -9,9 +9,6 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); const kIterationsCountForICProgression = 20; -// TODO(ishell): remove once leaked maps could keep NativeModule alive. -let instances = []; - function createArray_i() { let builder = new WasmModuleBuilder(); @@ -49,7 +46,6 @@ function createArray_i() { .exportAs("array_set"); let instance = builder.instantiate(); - instances.push(instance); let new_array = instance.exports.new_array; let array_get = instance.exports.array_get; let array_set = instance.exports.array_set; diff --git a/deps/v8/test/mjsunit/wasm/wasm-gc-js-roundtrip.js b/deps/v8/test/mjsunit/wasm/wasm-gc-js-roundtrip.js index 70156d262a..7ed8769d50 100644 --- a/deps/v8/test/mjsunit/wasm/wasm-gc-js-roundtrip.js +++ b/deps/v8/test/mjsunit/wasm/wasm-gc-js-roundtrip.js @@ -57,7 +57,7 @@ let instance = (() => { .addBody([kExprLocalGet, 0]) .exportFunc(); builder.addFunction(key + '_null', makeSig([], [type])) - .addBody([kExprRefNull, test_types[key]]) + .addBody([kExprRefNull, ...wasmSignedLeb(test_types[key])]) .exportFunc(); } diff --git a/deps/v8/test/mjsunit/wasm/wasm-module-builder.js b/deps/v8/test/mjsunit/wasm/wasm-module-builder.js index 563af6f8b7..4f0c32fbab 100644 --- a/deps/v8/test/mjsunit/wasm/wasm-module-builder.js +++ b/deps/v8/test/mjsunit/wasm/wasm-module-builder.js @@ -67,7 +67,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 Memory & Global) +let kTagSectionCode = 13; // Tag section (between Memory & Global) // Name section types let kModuleNameCode = 0; @@ -77,6 +77,9 @@ let kLocalNamesCode = 2; let kWasmFunctionTypeForm = 0x60; let kWasmStructTypeForm = 0x5f; let kWasmArrayTypeForm = 0x5e; +let kWasmFunctionExtendingTypeForm = 0x5d; +let kWasmStructExtendingTypeForm = 0x5c; +let kWasmArrayExtendingTypeForm = 0x5b; let kLimitsNoMaximum = 0x00; let kLimitsWithMaximum = 0x01; @@ -108,35 +111,52 @@ let kWasmF64 = 0x7c; let kWasmS128 = 0x7b; let kWasmI8 = 0x7a; let kWasmI16 = 0x79; -let kWasmFuncRef = 0x70; + +// These are defined as negative integers to distinguish them from positive type +// indices. +let kWasmFuncRef = -0x10; let kWasmAnyFunc = kWasmFuncRef; // Alias named as in the JS API spec -let kWasmExternRef = 0x6f; -let kWasmAnyRef = 0x6e; -let kWasmEqRef = 0x6d; +let kWasmExternRef = -0x11; +let kWasmAnyRef = -0x12; +let kWasmEqRef = -0x13; +let kWasmI31Ref = -0x16; +let kWasmDataRef = -0x19; + +// Use the positive-byte versions inside function bodies. +let kLeb128Mask = 0x7f; +let kFuncRefCode = kWasmFuncRef & kLeb128Mask; +let kAnyFuncCode = kFuncRefCode; // Alias named as in the JS API spec +let kExternRefCode = kWasmExternRef & kLeb128Mask; +let kAnyRefCode = kWasmAnyRef & kLeb128Mask; +let kEqRefCode = kWasmEqRef & kLeb128Mask; +let kI31RefCode = kWasmI31Ref & kLeb128Mask; +let kDataRefCode = kWasmDataRef & kLeb128Mask; + let kWasmOptRef = 0x6c; let kWasmRef = 0x6b; -function wasmOptRefType(index) { - return {opcode: kWasmOptRef, index: index}; +function wasmOptRefType(heap_type) { + return {opcode: kWasmOptRef, heap_type: heap_type}; } -function wasmRefType(index) { - return {opcode: kWasmRef, index: index}; +function wasmRefType(heap_type) { + return {opcode: kWasmRef, heap_type: heap_type}; } -let kWasmI31Ref = 0x6a; + let kWasmRttWithDepth = 0x69; function wasmRtt(index, depth) { + if (index < 0) throw new Error("Expecting non-negative type index"); return {opcode: kWasmRttWithDepth, index: index, depth: depth}; } let kWasmRtt = 0x68; function wasmRttNoDepth(index) { + if (index < 0) throw new Error("Expecting non-negative type index"); return {opcode: kWasmRtt, index: index}; } -let kWasmDataRef = 0x67; let kExternalFunction = 0; let kExternalTable = 1; let kExternalMemory = 2; let kExternalGlobal = 3; -let kExternalException = 4; +let kExternalTag = 4; let kTableZero = 0; let kMemoryZero = 0; @@ -199,6 +219,10 @@ function makeSig_v_x(x) { return makeSig([x], []); } +function makeSig_x_v(x) { + return makeSig([], [x]); +} + function makeSig_v_xx(x) { return makeSig([x, x], []); } @@ -936,16 +960,21 @@ class Binary { } } + emit_heap_type(heap_type) { + this.emit_bytes(wasmSignedLeb(heap_type, kMaxVarInt32Size)); + } + emit_type(type) { if ((typeof type) == 'number') { - this.emit_u8(type); + this.emit_u8(type >= 0 ? type : type & kLeb128Mask); } else { this.emit_u8(type.opcode); if ('depth' in type) this.emit_u8(type.depth); - this.emit_u32v(type.index); + this.emit_heap_type(type.heap_type); } } + emit_init_expr_recursive(expr) { switch (expr.kind) { case kExprGlobalGet: @@ -973,7 +1002,7 @@ class Binary { break; case kExprRefNull: this.emit_u8(kExprRefNull); - this.emit_u32v(expr.value); + this.emit_heap_type(expr.value); break; case kExprStructNewWithRtt: for (let operand of expr.operands) { @@ -1170,14 +1199,14 @@ class WasmInitExpr { if ((typeof type) != 'number' && type.opcode != kWasmOptRef) { throw new Error("Non-defaultable type"); } - let heap_type = (typeof type) == 'number' ? type : type.index; + let heap_type = (typeof type) == 'number' ? type : type.heap_type; return this.RefNull(heap_type); } } } class WasmGlobalBuilder { - // {init} a pair {type, immediate}. Construct it with WasmInitExpr. + // {init} should be constructed with WasmInitExpr. constructor(module, type, mutable, init) { this.module = module; this.type = type; @@ -1223,6 +1252,15 @@ class WasmStruct { throw new Error('struct fields must be an array'); } this.fields = fields; + this.type_form = kWasmStructTypeForm; + } +} + +class WasmStructExtending extends WasmStruct { + constructor(fields, supertype_idx) { + super(fields); + this.supertype = supertype_idx; + this.type_form = kWasmStructExtendingTypeForm; } } @@ -1231,9 +1269,17 @@ class WasmArray { this.type = type; if (!mutability) throw new Error("Immutable arrays are not supported yet"); this.mutability = mutability; + this.type_form = kWasmArrayTypeForm; } } +class WasmArrayExtending extends WasmArray { + constructor(type, mutability, supertype_idx) { + super(type, mutability); + this.supertype = supertype_idx; + this.type_form = kWasmArrayExtendingTypeForm; + } +} class WasmElemSegment { constructor(table, offset, type, elements, is_decl) { this.table = table; @@ -1276,7 +1322,7 @@ class WasmModuleBuilder { this.exports = []; this.globals = []; this.tables = []; - this.exceptions = []; + this.tags = []; this.functions = []; this.compilation_hints = []; this.element_segments = []; @@ -1285,7 +1331,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; } @@ -1356,11 +1402,21 @@ class WasmModuleBuilder { return this.types.length - 1; } + addStructExtending(fields, supertype_idx) { + this.types.push(new WasmStructExtending(fields, supertype_idx)); + return this.types.length - 1; + } + addArray(type, mutability) { this.types.push(new WasmArray(type, mutability)); return this.types.length - 1; } + addArrayExtending(type, mutability, supertype_idx) { + this.types.push(new WasmArrayExtending(type, mutability, supertype_idx)); + return this.types.length - 1; + } + addGlobal(type, mutable, init) { if (init === undefined) init = WasmInitExpr.defaultFor(type); let glob = new WasmGlobalBuilder(this, type, mutable, init); @@ -1382,11 +1438,11 @@ 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); - return except_index; + let tag_index = this.tags.length + this.num_imported_tags; + this.tags.push(type_index); + return tag_index; } addFunction(name, type, arg_names) { @@ -1461,19 +1517,19 @@ 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, + kind: kExternalTag, type_index: type_index }; this.imports.push(o); - return this.num_imported_exceptions++; + return this.num_imported_tags++; } addExport(name, index) { @@ -1589,16 +1645,22 @@ class WasmModuleBuilder { section.emit_u32v(wasm.types.length); for (let type of wasm.types) { if (type instanceof WasmStruct) { - section.emit_u8(kWasmStructTypeForm); + section.emit_u8(type.type_form); section.emit_u32v(type.fields.length); for (let field of type.fields) { section.emit_type(field.type); section.emit_u8(field.mutability ? 1 : 0); } + if (type instanceof WasmStructExtending) { + section.emit_u32v(type.supertype); + } } else if (type instanceof WasmArray) { - section.emit_u8(kWasmArrayTypeForm); + section.emit_u8(type.type_form); section.emit_type(type.type); section.emit_u8(type.mutability ? 1 : 0); + if (type instanceof WasmArrayExtending) { + section.emit_u32v(type.supertype); + } } else { section.emit_u8(kWasmFunctionTypeForm); section.emit_u32v(type.params.length); @@ -1644,7 +1706,7 @@ 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) { + } else if (imp.kind == kExternalTag) { section.emit_u32v(kExceptionAttribute); section.emit_u32v(imp.type_index); } else { @@ -1708,12 +1770,12 @@ class WasmModuleBuilder { }); } - // Add event section. - if (wasm.exceptions.length > 0) { - if (debug) print('emitting events @ ' + binary.length); - binary.emit_section(kExceptionSectionCode, section => { - section.emit_u32v(wasm.exceptions.length); - for (let type_index of wasm.exceptions) { + // Add tag section. + 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_index of wasm.tags) { section.emit_u32v(kExceptionAttribute); section.emit_u32v(type_index); } diff --git a/deps/v8/test/mjsunit/wasm/wasm-struct-js-interop.js b/deps/v8/test/mjsunit/wasm/wasm-struct-js-interop.js index 2545fa68d8..ec53dbe370 100644 --- a/deps/v8/test/mjsunit/wasm/wasm-struct-js-interop.js +++ b/deps/v8/test/mjsunit/wasm/wasm-struct-js-interop.js @@ -9,9 +9,6 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); const kIterationsCountForICProgression = 20; -// TODO(ishell): remove once leaked maps could keep NativeModule alive. -let instances = []; - function createSimpleStruct(field_type, value1, value2) { const builder = new WasmModuleBuilder(); @@ -52,7 +49,6 @@ function createSimpleStruct(field_type, value1, value2) { .exportAs("set_field"); let instance = builder.instantiate(); - instances.push(instance); let new_struct = instance.exports.new_struct; let get_field = instance.exports.get_field; let set_field = instance.exports.set_field; |