diff options
author | Michaël Zasso <targos@protonmail.com> | 2020-10-15 20:17:08 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2020-10-18 20:16:47 +0200 |
commit | a1d639ba5de4ff34e34fb575fbb6cc1d41ec3cce (patch) | |
tree | abc7d41c12f1495b1208fa4449cb2508c92c5e85 /deps/v8/test/mjsunit/wasm | |
parent | 089d654dd85f8e548597329f60a41d6029260caa (diff) | |
download | node-new-a1d639ba5de4ff34e34fb575fbb6cc1d41ec3cce.tar.gz |
deps: update V8 to 8.6.395
PR-URL: https://github.com/nodejs/node/pull/35415
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/test/mjsunit/wasm')
47 files changed, 1052 insertions, 770 deletions
diff --git a/deps/v8/test/mjsunit/wasm/anyfunc.js b/deps/v8/test/mjsunit/wasm/anyfunc.js index 6f6384cd61..0f04dbbeb0 100644 --- a/deps/v8/test/mjsunit/wasm/anyfunc.js +++ b/deps/v8/test/mjsunit/wasm/anyfunc.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 --experimental-wasm-anyref --expose-gc +// Flags: --expose-wasm --experimental-wasm-reftypes --expose-gc load('test/mjsunit/wasm/wasm-module-builder.js'); @@ -147,60 +147,36 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); assertEquals(null, main()); })(); -(function testAssignNullRefToAnyFuncLocal() { +(function testAssignNullToAnyFuncLocal() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_a_a); builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kExprLocalSet, 0, kExprLocalGet, 0]) + .addBody([kExprRefNull, kWasmAnyFunc, kExprLocalSet, 0, kExprLocalGet, 0]) .exportFunc(); const main = builder.instantiate().exports.main; assertEquals(null, main(main)); })(); -(function testImplicitReturnNullRefAsAnyFunc() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_a_v); - builder.addFunction('main', sig_index).addBody([kExprRefNull]).exportFunc(); - - const main = builder.instantiate().exports.main; - assertEquals(null, main()); -})(); - -(function testExplicitReturnNullRefAsAnyFunc() { +(function testImplicitReturnNullAsAnyFunc() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_a_v); builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kExprReturn]) + .addBody([kExprRefNull, kWasmAnyFunc]) .exportFunc(); const main = builder.instantiate().exports.main; assertEquals(null, main()); })(); -(function testImplicitReturnAnyFuncAsAnyRef() { +(function testExplicitReturnNullAsAnyFunc() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_r_v); - builder.addFunction('main', sig_index) - .addLocals({anyfunc_count: 1}) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - const main = builder.instantiate().exports.main; - assertEquals(null, main()); -})(); - -(function testExplicitReturnAnyFuncAsAnyRef() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_r_v); + const sig_index = builder.addType(kSig_a_v); builder.addFunction('main', sig_index) - .addLocals({anyfunc_count: 1}) - .addBody([kExprLocalGet, 0, kExprReturn]) + .addBody([kExprRefNull, kWasmAnyFunc, kExprReturn]) .exportFunc(); const main = builder.instantiate().exports.main; diff --git a/deps/v8/test/mjsunit/wasm/atomics-non-shared.js b/deps/v8/test/mjsunit/wasm/atomics-non-shared.js index d4fb826cea..510a2ce165 100644 --- a/deps/v8/test/mjsunit/wasm/atomics-non-shared.js +++ b/deps/v8/test/mjsunit/wasm/atomics-non-shared.js @@ -58,3 +58,67 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); let module = new WebAssembly.Module(builder.toBuffer()); let instance = new WebAssembly.Instance(module, {m: {memory}}); })(); + +(function TestWasmAtomicNotifyResult() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + builder.addImportedMemory("m", "memory", 0, 20); + builder.addFunction("main", kSig_i_ii) + .addBody([ + kExprLocalGet, 0, + kExprLocalGet, 1, + kAtomicPrefix, + kExprAtomicNotify, 0, 0]) + .exportAs("main"); + + // Instantiate module, get function exports + let module = new WebAssembly.Module(builder.toBuffer()); + let memory = new WebAssembly.Memory({initial: 1, maximum: 1}); + let instance = new WebAssembly.Instance(module, {m: {memory}}); + assertEquals(0, instance.exports.main(0, 100)); +})(); + +(function TestWasmI32AtomicWaitTraps() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + builder.addImportedMemory("m", "memory", 0, 20); + builder.addFunction("main", + makeSig([kWasmI32, kWasmI32, kWasmF64], [kWasmI32])) + .addBody([ + kExprLocalGet, 0, + kExprLocalGet, 1, + kExprLocalGet, 2, + kExprI64SConvertF64, + kAtomicPrefix, + kExprI32AtomicWait, 0, 0]) + .exportAs("main"); + + // Instantiate module, get function exports + let module = new WebAssembly.Module(builder.toBuffer()); + let memory = new WebAssembly.Memory({initial: 1, maximum: 1}); + let instance = new WebAssembly.Instance(module, {m: {memory}}); + assertThrows(() => instance.exports.main(0, 5, 0), WebAssembly.RuntimeError); +})(); + +(function TestWasmI64AtomicWaitTraps() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + builder.addImportedMemory("m", "memory", 0, 20); + builder.addFunction("main", + makeSig([kWasmI32, kWasmI32, kWasmF64], [kWasmI32])) + .addBody([ + kExprLocalGet, 0, + kExprLocalGet, 1, + kExprI64UConvertI32, + kExprLocalGet, 2, + kExprI64SConvertF64, + kAtomicPrefix, + kExprI64AtomicWait, 0, 0]) + .exportAs("main"); + + // Instantiate module, get function exports + let module = new WebAssembly.Module(builder.toBuffer()); + let memory = new WebAssembly.Memory({initial: 1, maximum: 1}); + let instance = new WebAssembly.Instance(module, {m: {memory}}); + assertThrows(() => instance.exports.main(0, 5, 0), WebAssembly.RuntimeError); +})(); diff --git a/deps/v8/test/mjsunit/wasm/bigint.js b/deps/v8/test/mjsunit/wasm/bigint.js index 0c9ebb6559..785ee182f1 100644 --- a/deps/v8/test/mjsunit/wasm/bigint.js +++ b/deps/v8/test/mjsunit/wasm/bigint.js @@ -164,8 +164,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); try { new WebAssembly.Global(argument); } catch (e) { - assertContains("'value' must be", e.message); - assertContains("i64", e.message); + assertContains("'value' must be a WebAssembly type", e.message); } })(); diff --git a/deps/v8/test/mjsunit/wasm/call-ref.js b/deps/v8/test/mjsunit/wasm/call-ref.js new file mode 100644 index 0000000000..355986cf6b --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/call-ref.js @@ -0,0 +1,105 @@ +// Copyright 2020 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-type-reflection --experimental-wasm-gc + +load("test/mjsunit/wasm/wasm-module-builder.js"); + +(function Test1() { + var instance = (function () { + var builder = new WasmModuleBuilder(); + + var sig_index = builder.addType(kSig_i_ii); + + var imported_webassembly_function_index = + builder.addImport("imports", "mul", sig_index); + + var imported_js_function_index = + builder.addImport("imports", "add", sig_index); + + builder.addExport("reexported_js_function", + imported_js_function_index); + builder.addExport("reexported_webassembly_function", + imported_webassembly_function_index); + + var locally_defined_function = + builder.addFunction("sub", sig_index) + .addBody([ + kExprLocalGet, 0, + kExprLocalGet, 1, + kExprI32Sub + ]) + .exportFunc(); + + builder.addFunction("main", makeSig([kWasmAnyFunc, kWasmI32, kWasmI32], + [kWasmI32])) + .addBody([ + kExprLocalGet, 1, + kExprLocalGet, 2, + kExprLocalGet, 0, + kGCPrefix, kExprRttCanon, 0, + kGCPrefix, kExprRefCast, kWasmAnyFunc, 0, + kExprCallRef + ]) + .exportFunc(); + + builder.addFunction("test_local", makeSig([], [kWasmI32])) + .addBody([ + kExprI32Const, 55, + kExprI32Const, 42, + kExprRefFunc, locally_defined_function.index, + kExprCallRef + ]) + .exportFunc(); + + builder.addFunction("test_js_import", makeSig([], [kWasmI32])) + .addBody([ + kExprI32Const, 15, + kExprI32Const, 42, + kExprRefFunc, imported_js_function_index, + kExprCallRef + ]) + .exportFunc(); + + builder.addFunction("test_webassembly_import", makeSig([], [kWasmI32])) + .addBody([ + kExprI32Const, 3, + kExprI32Const, 7, + kExprRefFunc, imported_webassembly_function_index, + kExprCallRef + ]) + .exportFunc(); + + return builder.instantiate({imports: { + add: function(a, b) { return a + b; }, + mul: new WebAssembly.Function({parameters:['i32', 'i32'], + results: ['i32']}, + function(a, b) { return a * b; }) + }}); + })(); + + // Check the modules exist. + assertFalse(instance === undefined); + assertFalse(instance === null); + assertFalse(instance === 0); + assertEquals("object", typeof instance.exports); + assertEquals("function", typeof instance.exports.main); + + print("--locally defined func--"); + assertEquals(13, instance.exports.test_local()); + print("--locally defined exported func--") + assertEquals(5, instance.exports.main(instance.exports.sub, 12, 7)); + + print("--imported js func--"); + assertEquals(57, instance.exports.test_js_import()); + print("--imported and reexported js func--") + assertEquals(19, instance.exports.main( + instance.exports.reexported_js_function, 12, 7)); + + // TODO(7748): Make this work. + //print("--imported WebAssembly.Function--") + //assertEquals(21, instance.exports.test_webassembly_import()); + + //print(" --not imported WebAssembly.Function--") +})(); diff --git a/deps/v8/test/mjsunit/wasm/compare-exchange-stress.js b/deps/v8/test/mjsunit/wasm/compare-exchange-stress.js index 050a15e380..f7607e144d 100644 --- a/deps/v8/test/mjsunit/wasm/compare-exchange-stress.js +++ b/deps/v8/test/mjsunit/wasm/compare-exchange-stress.js @@ -9,6 +9,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); const kSequenceLength = 8192; const kNumberOfWorkers = 4; const kBitMask = kNumberOfWorkers - 1; +const kMemoryAddress = 0; const kSequenceStartAddress = 32; function makeWorkerCodeForOpcode(compareExchangeOpcode, size, functionName, @@ -186,15 +187,19 @@ function testOpcode(opcode, opcodeSize) { shared: true }); let memoryView = new Uint8Array(memory.buffer); - generateSequence(memoryView, kSequenceStartAddress, kSequenceLength * (opcodeSize / 8)); + let numBytes = opcodeSize / 8; + generateSequence( + memoryView, kSequenceStartAddress, kSequenceLength * numBytes); - let module = new WebAssembly.Module(builder.toBuffer()); - let workers = spawnWorker(module, memory, 0, kSequenceStartAddress); + // Write the first element of the sequence to memory, such that the workers + // can start running as soon as they are spawned. + memoryView.copyWithin( + kMemoryAddress, kSequenceStartAddress, + kSequenceStartAddress + numBytes); - // Fire the workers off - for (let i = opcodeSize / 8 - 1; i >= 0; i--) { - memoryView[i] = memoryView[kSequenceStartAddress + i]; - } + let module = new WebAssembly.Module(builder.toBuffer()); + let workers = + spawnWorker(module, memory, kMemoryAddress, kSequenceStartAddress); waitForWorkers(workers); diff --git a/deps/v8/test/mjsunit/wasm/compare-exchange64-stress.js b/deps/v8/test/mjsunit/wasm/compare-exchange64-stress.js index b2ffcf1475..05d3476193 100644 --- a/deps/v8/test/mjsunit/wasm/compare-exchange64-stress.js +++ b/deps/v8/test/mjsunit/wasm/compare-exchange64-stress.js @@ -9,6 +9,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); const kSequenceLength = 8192; const kNumberOfWorkers = 4; const kBitMask = kNumberOfWorkers - 1; +const kMemoryAddress = 0; const kSequenceStartAddress = 32; function makeWorkerCodeForOpcode(compareExchangeOpcode, size, functionName, @@ -191,15 +192,19 @@ function testOpcode(opcode, opcodeSize) { shared: true }); let memoryView = new Uint8Array(memory.buffer); - generateSequence(memoryView, kSequenceStartAddress, kSequenceLength * (opcodeSize / 8)); + let numBytes = opcodeSize / 8; + generateSequence( + memoryView, kSequenceStartAddress, kSequenceLength * numBytes); - let module = new WebAssembly.Module(builder.toBuffer()); - let workers = spawnWorker(module, memory, 0, kSequenceStartAddress); + // Write the first element of the sequence to memory, such that the workers + // can start running as soon as they are spawned. + memoryView.copyWithin( + kMemoryAddress, kSequenceStartAddress, + kSequenceStartAddress + numBytes); - // Fire the workers off - for (let i = opcodeSize / 8 - 1; i >= 0; i--) { - memoryView[i] = memoryView[kSequenceStartAddress + i]; - } + let module = new WebAssembly.Module(builder.toBuffer()); + let workers = + spawnWorker(module, memory, kMemoryAddress, kSequenceStartAddress); waitForWorkers(workers); diff --git a/deps/v8/test/mjsunit/wasm/compiled-module-serialization.js b/deps/v8/test/mjsunit/wasm/compiled-module-serialization.js index 859a3095ae..63568fe657 100644 --- a/deps/v8/test/mjsunit/wasm/compiled-module-serialization.js +++ b/deps/v8/test/mjsunit/wasm/compiled-module-serialization.js @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --expose-wasm --allow-natives-syntax --expose-gc +// The test needs --wasm-tier-up because we can't serialize and deserialize +// Liftoff code. +// Flags: --expose-wasm --allow-natives-syntax --expose-gc --wasm-tier-up load("test/mjsunit/wasm/wasm-module-builder.js"); diff --git a/deps/v8/test/mjsunit/wasm/errors.js b/deps/v8/test/mjsunit/wasm/errors.js index 4304e54588..4362895d62 100644 --- a/deps/v8/test/mjsunit/wasm/errors.js +++ b/deps/v8/test/mjsunit/wasm/errors.js @@ -155,27 +155,6 @@ function import_error(index, module, func, msg) { assertTraps(kTrapUnreachable, () => b.instantiate()); })(); -(function TestConversionError() { - print(arguments.callee.name); - let b = builder(); - b.addImport('foo', 'bar', kSig_v_l); - let buffer = b.addFunction('run', kSig_v_v) - .addBody([kExprI64Const, 0, kExprCallFunction, 0]) - .exportFunc() - .end() - .toBuffer(); - assertConversionError( - buffer, {foo: {bar: (l) => {}}}, kTrapMsgs[kTrapTypeError]); - - buffer = builder() - .addFunction('run', kSig_l_v) - .addBody([kExprI64Const, 0]) - .exportFunc() - .end() - .toBuffer(); - assertConversionError(buffer, {}, kTrapMsgs[kTrapTypeError]); -})(); - (function InternalDebugTrace() { print(arguments.callee.name); var builder = new WasmModuleBuilder(); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-anyref.js b/deps/v8/test/mjsunit/wasm/exceptions-externref.js index 93bb68d6f6..b405be80a8 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-anyref.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-externref.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: --experimental-wasm-eh --experimental-wasm-anyref --allow-natives-syntax +// Flags: --experimental-wasm-eh --experimental-wasm-reftypes --allow-natives-syntax load("test/mjsunit/wasm/wasm-module-builder.js"); load("test/mjsunit/wasm/exceptions-utils.js"); @@ -14,7 +14,7 @@ load("test/mjsunit/wasm/exceptions-utils.js"); let except = builder.addException(kSig_v_r); builder.addFunction("throw_null", kSig_v_v) .addBody([ - kExprRefNull, + kExprRefNull, kWasmExternRef, kExprThrow, except, ]).exportFunc(); let instance = builder.instantiate(); @@ -29,11 +29,11 @@ load("test/mjsunit/wasm/exceptions-utils.js"); let except = builder.addException(kSig_v_r); builder.addFunction("throw_catch_null", kSig_i_i) .addBody([ - kExprTry, kWasmAnyRef, + kExprTry, kWasmExternRef, kExprLocalGet, 0, kExprI32Eqz, - kExprIf, kWasmAnyRef, - kExprRefNull, + kExprIf, kWasmExternRef, + kExprRefNull, kWasmExternRef, kExprThrow, except, kExprElse, kExprI32Const, 42, @@ -82,7 +82,7 @@ load("test/mjsunit/wasm/exceptions-utils.js"); let except = builder.addException(kSig_v_r); builder.addFunction("throw_catch_param", kSig_r_r) .addBody([ - kExprTry, kWasmAnyRef, + kExprTry, kWasmExternRef, kExprLocalGet, 0, kExprThrow, except, kExprCatch, @@ -104,7 +104,7 @@ load("test/mjsunit/wasm/exceptions-utils.js"); print(arguments.callee.name); let builder = new WasmModuleBuilder(); let except = builder.addException(kSig_v_a); - builder.addFunction("throw_catch_local", kSig_r_v) + builder.addFunction("throw_catch_local", kSig_a_v) .addLocals({anyfunc_count: 1}) .addBody([ kExprTry, kWasmAnyFunc, @@ -185,22 +185,22 @@ load("test/mjsunit/wasm/exceptions-utils.js"); })(); // 'br_on_exn' on a null-ref value should trap. -(function TestBrOnExnNullRefSimple() { +(function TestBrOnExnNullSimple() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); let except = builder.addException(kSig_v_r); - builder.addFunction('br_on_exn_nullref', kSig_v_v) + builder.addFunction('br_on_exn_null', kSig_v_v) .addBody([ - kExprRefNull, + kExprRefNull, kWasmExnRef, kExprBrOnExn, 0, except, kExprDrop ]).exportFunc(); let instance = builder.instantiate(); - assertTraps(kTrapBrOnExnNullRef, () => instance.exports.br_on_exn_nullref()); + assertTraps(kTrapBrOnExnNull, () => instance.exports.br_on_exn_null()); })(); -(function TestBrOnExnNullRefFromJS() { +(function TestBrOnExnNullFromJS() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); let except = builder.addException(kSig_v_i); @@ -229,26 +229,26 @@ load("test/mjsunit/wasm/exceptions-utils.js"); assertEquals(kConstant0, instance.exports.call_import(0)); assertEquals(kNoMatch, instance.exports.call_import(1)); - assertTraps(kTrapBrOnExnNullRef, () => instance.exports.call_import(2)); + assertTraps(kTrapBrOnExnNull, () => instance.exports.call_import(2)); assertEquals(kNoMatch, instance.exports.call_import(3)); })(); // 'rethrow' on a null-ref value should trap. -(function TestRethrowNullRefSimple() { +(function TestRethrowNullSimple() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); let except = builder.addException(kSig_v_r); - builder.addFunction('rethrow_nullref', kSig_v_v) + builder.addFunction('rethrow_null', kSig_v_v) .addBody([ - kExprRefNull, + kExprRefNull, kWasmExnRef, kExprRethrow ]).exportFunc(); let instance = builder.instantiate(); - assertTraps(kTrapRethrowNullRef, () => instance.exports.rethrow_nullref()); + assertTraps(kTrapRethrowNull, () => instance.exports.rethrow_null()); })(); -(function TestRethrowNullRefFromJS() { +(function TestRethrowNullFromJS() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); let except = builder.addException(kSig_v_i); @@ -274,6 +274,6 @@ load("test/mjsunit/wasm/exceptions-utils.js"); assertEquals(kSuccess, instance.exports.call_import(0)); assertThrows(() => instance.exports.call_import(1), Error, '1'); - assertTraps(kTrapRethrowNullRef, () => instance.exports.call_import(2)); + assertTraps(kTrapRethrowNull, () => instance.exports.call_import(2)); assertThrowsEquals(() => instance.exports.call_import(3), undefined); })(); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-global.js b/deps/v8/test/mjsunit/wasm/exceptions-global.js index 80af193c3e..e7b24e19b9 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-global.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-global.js @@ -4,7 +4,7 @@ // Flags: --expose-wasm --experimental-wasm-eh --allow-natives-syntax -// Note that this test does not pass --experimental-wasm-anyref on purpose so +// Note that this test does not pass --experimental-wasm-reftypes on purpose so // that we make sure the two flags can be controlled separately/independently. load("test/mjsunit/wasm/wasm-module-builder.js"); diff --git a/deps/v8/test/mjsunit/wasm/exceptions-simd.js b/deps/v8/test/mjsunit/wasm/exceptions-simd.js index 8a8638f81f..0b407af5c0 100644 --- a/deps/v8/test/mjsunit/wasm/exceptions-simd.js +++ b/deps/v8/test/mjsunit/wasm/exceptions-simd.js @@ -42,7 +42,7 @@ load("test/mjsunit/wasm/exceptions-utils.js"); kExprEnd, kExprLocalGet, 0, kSimdPrefix, kExprI32x4Eq, - kSimdPrefix, kExprS1x16AllTrue, + kSimdPrefix, kExprV8x16AllTrue, ]) .exportFunc(); var instance = builder.instantiate(); diff --git a/deps/v8/test/mjsunit/wasm/anyref-globals.js b/deps/v8/test/mjsunit/wasm/externref-globals.js index ae99044a9c..ce89cf73db 100644 --- a/deps/v8/test/mjsunit/wasm/anyref-globals.js +++ b/deps/v8/test/mjsunit/wasm/externref-globals.js @@ -2,41 +2,41 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --experimental-wasm-anyref --expose-gc +// Flags: --experimental-wasm-reftypes --expose-gc load("test/mjsunit/wasm/wasm-module-builder.js"); (function TestDefaultValue() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - const g_nullref = builder.addGlobal(kWasmAnyRef, true).index; + const g_null = builder.addGlobal(kWasmExternRef, true).index; const g_nullfunc = builder.addGlobal(kWasmAnyFunc, true).index; - builder.addFunction("get_anyref_global", kSig_r_v) - .addBody([kExprGlobalGet, g_nullref]) - .exportAs("get_anyref_global"); + builder.addFunction("get_externref_global", kSig_r_v) + .addBody([kExprGlobalGet, g_null]) + .exportAs("get_externref_global"); builder.addFunction("get_anyfunc_global", kSig_a_v) .addBody([kExprGlobalGet, g_nullfunc]) .exportAs("get_anyfunc_global"); const instance = builder.instantiate(); - assertEquals(null, instance.exports.get_anyref_global()); + assertEquals(null, instance.exports.get_externref_global()); assertEquals(null, instance.exports.get_anyfunc_global()); })(); (function TestDefaultValueSecondGlobal() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - const g_setref = builder.addGlobal(kWasmAnyRef, true); + const g_setref = builder.addGlobal(kWasmExternRef, true); const g_setfunc = builder.addGlobal(kWasmAnyFunc, true); - const g_nullref = builder.addGlobal(kWasmAnyRef, true); + const g_null = builder.addGlobal(kWasmExternRef, true); const g_nullfunc = builder.addGlobal(kWasmAnyFunc, true); - builder.addFunction("get_anyref_global", kSig_r_r) + builder.addFunction("get_externref_global", kSig_r_r) .addBody([ kExprLocalGet, 0, kExprGlobalSet, g_setref.index, - kExprGlobalGet, g_nullref.index + kExprGlobalGet, g_null.index ]) - .exportAs("get_anyref_global"); + .exportAs("get_externref_global"); builder.addFunction("get_anyfunc_global", kSig_a_a) .addBody([ kExprLocalGet, 0, @@ -46,17 +46,17 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); .exportAs("get_anyfunc_global"); const instance = builder.instantiate(); - assertEquals(null, instance.exports.get_anyref_global({})); + assertEquals(null, instance.exports.get_externref_global({})); assertEquals(null, instance.exports.get_anyfunc_global( - instance.exports.get_anyref_global)); + instance.exports.get_externref_global)); })(); -(function TestAnyRefGlobalChangeValue() { +(function TestExternRefGlobalChangeValue() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); // Dummy global for offset. - builder.addGlobal(kWasmAnyRef, true); - const g = builder.addGlobal(kWasmAnyRef, true); + builder.addGlobal(kWasmExternRef, true); + const g = builder.addGlobal(kWasmExternRef, true); builder.addFunction("main", kSig_r_r) .addBody([ kExprLocalGet, 0, @@ -96,8 +96,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); let builder = new WasmModuleBuilder(); const gc_index = builder.addImport("q", "gc", kSig_v_v); // Dummy global for offset. - builder.addGlobal(kWasmAnyRef, true); - const g = builder.addGlobal(kWasmAnyRef, true); + builder.addGlobal(kWasmExternRef, true); + const g = builder.addGlobal(kWasmExternRef, true); builder.addFunction("main", kSig_r_r) .addBody([ kExprLocalGet, 0, @@ -118,7 +118,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); (function TestGlobalAsRoot() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - const g = builder.addGlobal(kWasmAnyRef, true); + const g = builder.addGlobal(kWasmExternRef, true); builder.addFunction("get_global", kSig_r_v) .addBody([ kExprGlobalGet, g.index @@ -144,11 +144,11 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals('world', result.hello); })(); -(function TestImportedAnyRef() { +(function TestImportedExternRef() { print(arguments.callee.name); function Test(obj) { let builder = new WasmModuleBuilder(); - const g = builder.addImportedGlobal('m', 'val', kWasmAnyRef); + const g = builder.addImportedGlobal('m', 'val', kWasmExternRef); builder.addFunction('main', kSig_r_v) .addBody([kExprGlobalGet, g]) .exportAs('main'); @@ -193,9 +193,9 @@ function dummy_func() { WebAssembly.LinkError); })(); -(function TestAnyRefGlobalObjectDefaultValue() { +(function TestExternRefGlobalObjectDefaultValue() { print(arguments.callee.name); - let default_init = new WebAssembly.Global({ value: 'anyref', mutable: true }); + let default_init = new WebAssembly.Global({ value: 'externref', mutable: true }); assertSame(null, default_init.value); assertSame(null, default_init.valueOf()); })(); @@ -207,10 +207,10 @@ function dummy_func() { assertSame(null, default_init.valueOf()); })(); -(function TestAnyRefGlobalObject() { +(function TestExternRefGlobalObject() { print(arguments.callee.name); function TestGlobal(obj) { - const global = new WebAssembly.Global({ value: 'anyref' }, obj); + const global = new WebAssembly.Global({ value: 'externref' }, obj); assertSame(obj, global.value); assertSame(obj, global.valueOf()); } @@ -238,9 +238,9 @@ function dummy_func() { assertThrows(() => new WebAssembly.Global({ value: 'anyfunc' }, {}), TypeError); })(); -(function TestAnyRefGlobalObjectSetValue() { +(function TestExternRefGlobalObjectSetValue() { print(arguments.callee.name); - let global = new WebAssembly.Global({ value: 'anyref', mutable: true }); + let global = new WebAssembly.Global({ value: 'externref', mutable: true }); function TestGlobal(obj) { global.value = obj; @@ -276,14 +276,14 @@ function dummy_func() { (function TestExportMutableRefGlobal() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - const g1 = builder.addGlobal(kWasmAnyRef, true).exportAs("global1"); + const g1 = builder.addGlobal(kWasmExternRef, true).exportAs("global1"); const g2 = builder.addGlobal(kWasmAnyFunc, true).exportAs("global2"); builder.addGlobal(kWasmI32, true); // Dummy. - builder.addGlobal(kWasmAnyRef, true); // Dummy. - const g3 = builder.addGlobal(kWasmAnyRef, true).exportAs("global3"); + builder.addGlobal(kWasmExternRef, true); // Dummy. + const g3 = builder.addGlobal(kWasmExternRef, true).exportAs("global3"); const g4 = builder.addGlobal(kWasmAnyFunc, true).exportAs("global4"); builder.addFunction("main", - makeSig([kWasmAnyRef, kWasmAnyFunc, kWasmAnyRef, kWasmAnyFunc], [])) + makeSig([kWasmExternRef, kWasmAnyFunc, kWasmExternRef, kWasmAnyFunc], [])) .addBody([ kExprLocalGet, 0, kExprGlobalSet, g1.index, @@ -308,16 +308,16 @@ function dummy_func() { assertSame(func4, instance.exports.global4.value); })(); -(function TestImportMutableAnyRefGlobal() { +(function TestImportMutableExternRefGlobal() { print(arguments.callee.name); function Test(obj) { let builder = new WasmModuleBuilder(); - const g = builder.addImportedGlobal('m', 'val', kWasmAnyRef, true); + const g = builder.addImportedGlobal('m', 'val', kWasmExternRef, true); builder.addFunction('main', kSig_r_v) .addBody([kExprGlobalGet, g]) .exportAs('main'); - const global = new WebAssembly.Global({ value: 'anyref', mutable: 'true' }, obj); + const global = new WebAssembly.Global({ value: 'externref', mutable: 'true' }, obj); const instance = builder.instantiate({ m: { val: global } }); assertSame(obj, instance.exports.main()); } @@ -346,15 +346,15 @@ function dummy_func() { Test(null); })(); -(function TestImportMutableAnyRefGlobalFromOtherInstance() { +(function TestImportMutableExternRefGlobalFromOtherInstance() { print(arguments.callee.name); // Create an instance which exports globals. let builder1 = new WasmModuleBuilder(); - const g3 = builder1.addGlobal(kWasmAnyRef, true).exportAs("e3"); + const g3 = builder1.addGlobal(kWasmExternRef, true).exportAs("e3"); builder1.addGlobal(kWasmI32, true).exportAs("e1"); // Dummy. - builder1.addGlobal(kWasmAnyRef, true).exportAs("e4"); // Dummy. - const g2 = builder1.addGlobal(kWasmAnyRef, true).exportAs("e2"); + builder1.addGlobal(kWasmExternRef, true).exportAs("e4"); // Dummy. + const g2 = builder1.addGlobal(kWasmExternRef, true).exportAs("e2"); builder1.addFunction("set_globals", kSig_v_rr) .addBody([ @@ -381,9 +381,9 @@ function dummy_func() { // Create an instance which imports the globals of the other instance. let builder2 = new WasmModuleBuilder(); const i1 = builder2.addImportedGlobal('exports', 'e1', kWasmI32, true); - const i2 = builder2.addImportedGlobal('exports', 'e2', kWasmAnyRef, true); - const i3 = builder2.addImportedGlobal('exports', 'e3', kWasmAnyRef, true); - const i4 = builder2.addImportedGlobal('exports', 'e4', kWasmAnyRef, true); + const i2 = builder2.addImportedGlobal('exports', 'e2', kWasmExternRef, true); + const i3 = builder2.addImportedGlobal('exports', 'e3', kWasmExternRef, true); + const i4 = builder2.addImportedGlobal('exports', 'e4', kWasmExternRef, true); builder2.addExportOfKind("reexport1", kExternalGlobal, i1); builder2.addExportOfKind("reexport2", kExternalGlobal, i2); @@ -529,69 +529,36 @@ function dummy_func() { assertEquals(obj3, instance2.exports.reexport3.value); })(); -(function TestImportImmutableAnyFuncGlobalAsAnyRef() { +(function TestImportMutableAnyFuncGlobalAsExternRefFails() { print(arguments.callee.name); let builder1 = new WasmModuleBuilder(); const g3 = builder1.addGlobal(kWasmAnyFunc, true).exportAs("e3"); - builder1.addGlobal(kWasmAnyRef, false).exportAs("e1"); // Dummy. - builder1.addGlobal(kWasmAnyFunc, false).exportAs("e2"); // Dummy. - const instance1 = builder1.instantiate(); - - let builder2 = new WasmModuleBuilder(); - const i1 = builder2.addImportedGlobal('exports', 'e1', kWasmAnyRef, false); - const i2 = builder2.addImportedGlobal('exports', 'e2', kWasmAnyRef, false); - builder2.instantiate(instance1); -})(); - -(function TestImportMutableAnyFuncGlobalAsAnyRefFails() { - print(arguments.callee.name); - let builder1 = new WasmModuleBuilder(); - const g3 = builder1.addGlobal(kWasmAnyFunc, true).exportAs("e3"); - builder1.addGlobal(kWasmAnyRef, true).exportAs("e1"); // Dummy. + builder1.addGlobal(kWasmExternRef, true).exportAs("e1"); // Dummy. builder1.addGlobal(kWasmAnyFunc, true).exportAs("e2"); // Dummy. const instance1 = builder1.instantiate(); let builder2 = new WasmModuleBuilder(); - const i1 = builder2.addImportedGlobal('exports', 'e1', kWasmAnyRef, true); - const i2 = builder2.addImportedGlobal('exports', 'e2', kWasmAnyRef, true); + const i1 = builder2.addImportedGlobal('exports', 'e1', kWasmExternRef, true); + const i2 = builder2.addImportedGlobal('exports', 'e2', kWasmExternRef, true); assertThrows(() => builder2.instantiate(instance1), WebAssembly.LinkError); })(); (function TestRefFuncGlobalInit() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); - const g_ref = builder.addGlobal(kWasmAnyRef, true); const g_func = builder.addGlobal(kWasmAnyFunc, true); - const f_ref = builder.addFunction('get_anyref_global', kSig_r_v) - .addBody([kExprGlobalGet, g_ref.index]) - .exportAs('get_anyref_global'); const f_func = builder.addFunction('get_anyfunc_global', kSig_a_v) .addBody([kExprGlobalGet, g_func.index]) .exportAs('get_anyfunc_global'); - builder.addDeclarativeElementSegment([f_ref.index, f_func.index]); - g_ref.function_index = f_ref.index; + builder.addDeclarativeElementSegment([f_func.index]); g_func.function_index = f_func.index; const instance = builder.instantiate(); assertEquals( - instance.exports.get_anyref_global, instance.exports.get_anyref_global()); - assertEquals( instance.exports.get_anyfunc_global, instance.exports.get_anyfunc_global()); })(); -(function TestRefFuncGlobalInitUndeclared() { - print(arguments.callee.name); - let builder = new WasmModuleBuilder(); - const global_func = builder.addGlobal(kWasmAnyFunc, true); - const func = builder.addFunction('get_anyfunc_global', kSig_v_v).addBody([]); - global_func.function_index = func.index; - - assertThrows( - () => builder.toModule(), WebAssembly.CompileError, - /undeclared reference to function/); -})(); - (function TestRefFuncGlobalInitWithImport() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); diff --git a/deps/v8/test/mjsunit/wasm/anyref-table.js b/deps/v8/test/mjsunit/wasm/externref-table.js index a7a82099d6..69c00279ca 100644 --- a/deps/v8/test/mjsunit/wasm/anyref-table.js +++ b/deps/v8/test/mjsunit/wasm/externref-table.js @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --experimental-wasm-anyref --experimental-wasm-bulk-memory +// Flags: --experimental-wasm-reftypes --experimental-wasm-bulk-memory load("test/mjsunit/wasm/wasm-module-builder.js"); -(function TestAnyRefTableSetWithMultipleTypes() { +(function TestExternRefTableSetWithMultipleTypes() { print(arguments.callee.name); - let table = new WebAssembly.Table({element: "anyref", initial: 10}); + let table = new WebAssembly.Table({element: "externref", initial: 10}); // Table should be initialized with null. assertEquals(null, table.get(1)); @@ -30,15 +30,15 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertThrows(() => table.set(12), RangeError); })(); -(function TestImportAnyRefTable() { +(function TestImportExternRefTable() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); - const table_index = builder.addImportedTable("imp", "table", 3, 10, kWasmAnyRef); + const table_index = builder.addImportedTable("imp", "table", 3, 10, kWasmExternRef); builder.addFunction('get', kSig_r_v) .addBody([kExprI32Const, 0, kExprTableGet, table_index]); - let table_ref = new WebAssembly.Table({element: "anyref", initial: 3, maximum: 10}); + let table_ref = new WebAssembly.Table({element: "externref", initial: 3, maximum: 10}); builder.instantiate({imp:{table: table_ref}}); let table_func = new WebAssembly.Table({ element: "anyfunc", initial: 3, maximum: 10 }); @@ -46,7 +46,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); WebAssembly.LinkError, /imported table does not match the expected type/); })(); -(function TestAnyRefDropDeclarativeElementSegment() { +(function TestExternRefDropDeclarativeElementSegment() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); @@ -61,7 +61,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); instance.exports.drop(); })(); -(function TestAnyRefTableInitFromDeclarativeElementSegment() { +(function TestExternRefTableInitFromDeclarativeElementSegment() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); diff --git a/deps/v8/test/mjsunit/wasm/anyref.js b/deps/v8/test/mjsunit/wasm/externref.js index cdb4742776..3b6b563731 100644 --- a/deps/v8/test/mjsunit/wasm/anyref.js +++ b/deps/v8/test/mjsunit/wasm/externref.js @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --expose-wasm --experimental-wasm-anyref --expose-gc +// Flags: --expose-wasm --experimental-wasm-reftypes --expose-gc load("test/mjsunit/wasm/wasm-module-builder.js"); -(function testAnyRefIdentityFunction() { +(function testExternRefIdentityFunction() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); builder.addFunction('main', kSig_r_r) @@ -25,7 +25,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(print, instance.exports.main(print)); })(); -(function testPassAnyRefToImportedFunction() { +(function testPassExternRefToImportedFunction() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_v_r); @@ -44,7 +44,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); instance.exports.main({hello: 'world'}); })(); -(function testPassAnyRefWithGCWithLocals() { +(function testPassExternRefWithGCWithLocals() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); const ref_sig = builder.addType(kSig_v_r); @@ -53,7 +53,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); const gc_index = builder.addImport("q", "gc", void_sig); // First call the gc, then check if the object still exists. builder.addFunction('main', ref_sig) - .addLocals({anyref_count: 10}) + .addLocals({externref_count: 10}) .addBody([ kExprLocalGet, 0, kExprLocalSet, 1, // Set local kExprLocalGet, 0, kExprLocalSet, 2, // Set local @@ -79,7 +79,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); instance.exports.main({hello: 'world'}); })(); -(function testPassAnyRefWithGC() { +(function testPassExternRefWithGC() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); const ref_sig = builder.addType(kSig_v_r); @@ -103,13 +103,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); instance.exports.main({hello: 'world'}); })(); -(function testPassAnyRefWithGCWithStackParameters() { +(function testPassExternRefWithGCWithStackParameters() { print(arguments.callee.name); const num_params = 15; for (let index = 0; index < num_params; index++) { const builder = new WasmModuleBuilder(); - // Make a signature with {num_params} many anyref parameters. - const mysig = makeSig(Array(num_params).fill(kWasmAnyRef), []); + // Make a signature with {num_params} many externref parameters. + const mysig = makeSig(Array(num_params).fill(kWasmExternRef), []); const main_sig = builder.addType(mysig); const ref_sig = builder.addType(kSig_v_r); const void_sig = builder.addType(kSig_v_v); @@ -139,10 +139,10 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); } })(); -(function testPassAnyRefWithGCInWrapper() { +(function testPassExternRefWithGCInWrapper() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); - const kSig_r_iri = makeSig([kWasmI32, kWasmAnyRef, kWasmI32], [kWasmAnyRef]); + const kSig_r_iri = makeSig([kWasmI32, kWasmExternRef, kWasmI32], [kWasmExternRef]); const sig_index = builder.addType(kSig_r_iri); builder.addFunction('main', sig_index) .addBody([kExprLocalGet, 1]) @@ -161,11 +161,11 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals('world', result.hello); })(); -(function testAnyRefNull() { +(function testExternRefNull() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); builder.addFunction('main', kSig_r_v) - .addBody([kExprRefNull]) + .addBody([kExprRefNull, kWasmExternRef]) .exportFunc(); const instance = builder.instantiate(); @@ -173,7 +173,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(null, instance.exports.main()); })(); -(function testAnyRefIsNull() { +(function testExternRefIsNull() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); builder.addFunction('main', kSig_i_r) @@ -191,12 +191,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(0, instance.exports.main(print)); })(); -(function testAnyRefNullIsNull() { +(function testExternRefNullIsNull() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); builder.addFunction('main', kSig_i_v) - .addBody([kExprRefNull, kExprRefIsNull]) + .addBody([kExprRefNull, kWasmExternRef, kExprRefIsNull]) .exportFunc(); const instance = builder.instantiate(); @@ -204,12 +204,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(1, instance.exports.main()); })(); -(function testAnyRefLocalDefaultValue() { +(function testExternRefLocalDefaultValue() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); builder.addFunction('main', kSig_r_v) .addBody([kExprLocalGet, 0]) - .addLocals({anyref_count: 1}) + .addLocals({externref_count: 1}) .exportFunc(); const instance = builder.instantiate(); @@ -217,24 +217,24 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(null, instance.exports.main()); })(); -(function testImplicitReturnNullRefAsAnyRef() { +(function testImplicitReturnNullAsExternRef() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_r_v); builder.addFunction('main', sig_index) - .addBody([kExprRefNull]) + .addBody([kExprRefNull, kWasmExternRef]) .exportFunc(); const main = builder.instantiate().exports.main; assertEquals(null, main()); })(); -(function testExplicitReturnNullRefAsAnyRef() { +(function testExplicitReturnNullAsExternRef() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_r_v); builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kExprReturn]) + .addBody([kExprRefNull, kWasmExternRef, kExprReturn]) .exportFunc(); const main = builder.instantiate().exports.main; diff --git a/deps/v8/test/mjsunit/wasm/ffi-error.js b/deps/v8/test/mjsunit/wasm/ffi-error.js index 217d7f3fd2..40d5aa5481 100644 --- a/deps/v8/test/mjsunit/wasm/ffi-error.js +++ b/deps/v8/test/mjsunit/wasm/ffi-error.js @@ -119,7 +119,7 @@ function checkFailingInstantiation( instance => assertEquals(33, instance.exports.main())); })(); -(function I64InSignatureThrows() { +(function I64InSignature() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); @@ -133,12 +133,11 @@ function checkFailingInstantiation( checkSuccessfulInstantiation( builder, undefined, - instance => assertThrows(function() { - instance.exports.function_with_invalid_signature(33, 88); - }, TypeError, 'wasm function signature contains illegal type')); + instance => assertEquals( + instance.exports.function_with_invalid_signature(33n, 88n), -55n)); })(); -(function I64ParamsInSignatureThrows() { +(function I64ParamsInSignature() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); @@ -149,13 +148,12 @@ function checkFailingInstantiation( checkSuccessfulInstantiation( builder, undefined, - instance => assertThrows( - _ => instance.exports.function_with_invalid_signature(12), TypeError, - 'wasm function signature contains illegal type')); + instance => assertEquals(12, + instance.exports.function_with_invalid_signature(12n))); })(); -(function I64JSImportThrows() { +(function I64JSImport() { print(arguments.callee.name); let builder = new WasmModuleBuilder(); let sig_index = builder.addType(kSig_i_i); @@ -169,13 +167,11 @@ function checkFailingInstantiation( checkSuccessfulInstantiation( builder, {'': {func: _ => {}}}, - instance => assertThrows( - instance.exports.main, TypeError, - 'wasm function signature contains illegal type')); + instance => assertEquals(0, instance.exports.main(1))); })(); -(function ImportI64ParamWithF64ReturnThrows() { +(function ImportI64ParamWithF64Return() { print(arguments.callee.name); // This tests that we generate correct code by using the correct return // register. See bug 6096. @@ -186,11 +182,8 @@ function checkFailingInstantiation( .exportFunc(); checkSuccessfulInstantiation( - builder, {'': {f: i => i}}, - instance => assertThrows( - instance.exports.main, TypeError, - 'wasm function signature contains illegal type')); - + builder, {'': {f: i => Number(i)}}, + instance => assertDoesNotThrow(instance.exports.main)); })(); (function ImportI64Return() { @@ -204,11 +197,8 @@ function checkFailingInstantiation( .exportFunc(); checkSuccessfulInstantiation( - builder, {'': {f: _ => 1}}, - instance => assertThrows( - instance.exports.main, TypeError, - 'wasm function signature contains illegal type')); - + builder, {'': {f: _ => 1n}}, + instance => assertDoesNotThrow(instance.exports.main)); })(); (function ImportSymbolToNumberThrows() { diff --git a/deps/v8/test/mjsunit/wasm/futex.js b/deps/v8/test/mjsunit/wasm/futex.js index d5bbf9ff1a..8f5dce943a 100644 --- a/deps/v8/test/mjsunit/wasm/futex.js +++ b/deps/v8/test/mjsunit/wasm/futex.js @@ -282,12 +282,12 @@ if (this.Worker) { if (num >= numWorkers) { // if numWorkers or more is passed to wake, numWorkers workers should be // woken. - assertEquals(numWorkers, Atomics.wake(i32a, indexJs, num)); + assertEquals(numWorkers, Atomics.notify(i32a, indexJs, num)); } else { // if num < numWorkers is passed to wake, num workers should be woken. // Then the remaining workers are woken for the next part - assertEquals(num, Atomics.wake(i32a, indexJs, num)); - assertEquals(numWorkers-num, Atomics.wake(i32a, indexJs, numWorkers)); + assertEquals(num, Atomics.notify(i32a, indexJs, num)); + assertEquals(numWorkers-num, Atomics.notify(i32a, indexJs, numWorkers)); } for (let id = 0; id < numWorkers; id++) { assertEquals(msg, workers[id].getMessage()); diff --git a/deps/v8/test/mjsunit/wasm/generic-wrapper.js b/deps/v8/test/mjsunit/wasm/generic-wrapper.js new file mode 100644 index 0000000000..e8bafcd7ae --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/generic-wrapper.js @@ -0,0 +1,102 @@ +// Copyright 2020 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: --wasm-generic-wrapper --expose-gc + +load("test/mjsunit/wasm/wasm-module-builder.js"); + +(function testGenericWrapper0Param() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + let sig_index = builder.addType(kSig_v_v); + let func_index = builder.addImport("mod", "func", sig_index); + builder.addFunction("main", sig_index) + .addBody([ + kExprCallFunction, func_index + ]) + .exportFunc(); + + let x = 12; + function import_func() { + gc(); + x = 20; + } + + let instance = builder.instantiate({ mod: { func: import_func } }); + assertEquals(undefined, instance.exports.main()); + assertEquals(x, 20); +})(); + +(function testGenericWrapper0ParamTraps() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + let sig_index = builder.addType(kSig_v_v); + builder.addFunction("main", sig_index) + .addBody([ + kExprUnreachable + ]) + .exportFunc(); + + let instance = builder.instantiate(); + assertTraps(kTrapUnreachable, instance.exports.main); +})(); + +(function testGenericWrapper1ParamTrap() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + let sig_index = builder.addType(kSig_v_i); + builder.addFunction("main", sig_index) + .addBody([ + kExprLocalGet, 0, kExprUnreachable + ]) + .exportFunc(); + + let instance = builder.instantiate(); + assertTraps(kTrapUnreachable, () => instance.exports.main(1)); +})(); + +(function testGenericWrapper1ParamGeneral() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + let sig_index = builder.addType(kSig_v_i); + let func_index = builder.addImport("mod", "func", sig_index); + builder.addFunction("main", sig_index) + .addBody([ + kExprLocalGet, 0, kExprCallFunction, func_index + ]) + .exportFunc(); + + let x = 12; + function import_func(param) { + gc(); + x += param; + } + + let instance = builder.instantiate({ mod: { func: import_func } }); + instance.exports.main(5); + assertEquals(17, x); +})(); + +(function testGenericWrapper1ParamNotSmi() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + let sig_index = builder.addType(kSig_v_i); + let func_index = builder.addImport("mod", "func", sig_index); + builder.addFunction("main", sig_index) + .addBody([ + kExprLocalGet, 0, kExprCallFunction, func_index + ]) + .exportFunc(); + + let x = 12; + function import_func(param) { + gc(); + x += param; + } + + let y = { valueOf: () => { print("Hello!"); gc(); return 24; } }; + let instance = builder.instantiate({ mod: { func: import_func } }); + instance.exports.main(y); + assertEquals(36, x); +})(); diff --git a/deps/v8/test/mjsunit/wasm/globals-import-export-identity.js b/deps/v8/test/mjsunit/wasm/globals-import-export-identity.js new file mode 100644 index 0000000000..f7b664d526 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/globals-import-export-identity.js @@ -0,0 +1,31 @@ +// Copyright 2020 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. + +load('test/mjsunit/wasm/wasm-module-builder.js'); + +const global1 = new WebAssembly.Global({value: 'i32', mutable: true}, 14); +const global2 = new WebAssembly.Global({value: 'i32', mutable: true}, 15); +const global3 = new WebAssembly.Global({value: 'i32', mutable: true}, 32); + +const builder = new WasmModuleBuilder(); + +// Two additional globals, so that global-index != export-index. +builder.addImportedGlobal('module', 'global1', kWasmI32, true); +builder.addImportedGlobal('module', 'global2', kWasmI32, true); +const globalIndex = + builder.addImportedGlobal('module', 'global3', kWasmI32, true); +builder.addExportOfKind('exportedGlobal', kExternalGlobal, globalIndex); + +const buffer = builder.toBuffer(); + +const module = new WebAssembly.Module(buffer); +const instance = new WebAssembly.Instance(module, { + 'module': { + 'global1': global1, + 'global2': global2, + 'global3': global3, + } +}); + +assertEquals(global3, instance.exports.exportedGlobal); diff --git a/deps/v8/test/mjsunit/wasm/globals.js b/deps/v8/test/mjsunit/wasm/globals.js index a72bc118c7..ba7bef301c 100644 --- a/deps/v8/test/mjsunit/wasm/globals.js +++ b/deps/v8/test/mjsunit/wasm/globals.js @@ -119,7 +119,7 @@ TestExported(kWasmF64, 87347.66666, 87347.66666); var instance = builder.instantiate(); assertTrue(instance.exports.foo instanceof WebAssembly.Global); - assertThrows(() => {instance.exports.foo.value}, TypeError); + assertEquals(instance.exports.foo.value, 1234n); })(); function TestImportedExported(type, val, expected) { diff --git a/deps/v8/test/mjsunit/wasm/graceful_shutdown.js b/deps/v8/test/mjsunit/wasm/graceful_shutdown.js index 0f55b795c1..0e4e1d1c77 100644 --- a/deps/v8/test/mjsunit/wasm/graceful_shutdown.js +++ b/deps/v8/test/mjsunit/wasm/graceful_shutdown.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 --no-wait-for-wasm +// Flags: --expose-wasm --no-wait-for-background-tasks load("test/mjsunit/wasm/wasm-module-builder.js"); diff --git a/deps/v8/test/mjsunit/wasm/graceful_shutdown_during_tierup.js b/deps/v8/test/mjsunit/wasm/graceful_shutdown_during_tierup.js index f615602a8e..e7dafc5239 100644 --- a/deps/v8/test/mjsunit/wasm/graceful_shutdown_during_tierup.js +++ b/deps/v8/test/mjsunit/wasm/graceful_shutdown_during_tierup.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: --no-wait-for-wasm --wasm-tier-up +// Flags: --no-wait-for-background-tasks --wasm-tier-up load("test/mjsunit/wasm/wasm-module-builder.js"); diff --git a/deps/v8/test/mjsunit/wasm/indirect-call-non-zero-table.js b/deps/v8/test/mjsunit/wasm/indirect-call-non-zero-table.js index 69fb4dcf43..8102ca188e 100644 --- a/deps/v8/test/mjsunit/wasm/indirect-call-non-zero-table.js +++ b/deps/v8/test/mjsunit/wasm/indirect-call-non-zero-table.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 --experimental-wasm-anyref --experimental-wasm-return-call +// Flags: --expose-wasm --experimental-wasm-reftypes --experimental-wasm-return-call load("test/mjsunit/wasm/wasm-module-builder.js"); diff --git a/deps/v8/test/mjsunit/wasm/js-api.js b/deps/v8/test/mjsunit/wasm/js-api.js index bf9eb39781..1151be4489 100644 --- a/deps/v8/test/mjsunit/wasm/js-api.js +++ b/deps/v8/test/mjsunit/wasm/js-api.js @@ -582,13 +582,13 @@ assertThrows( assertThrows( () => new Table(1), TypeError, 'WebAssembly.Module(): Argument 0 must be a table descriptor'); assertThrows( - () => new Table({initial: 1, element: 1}), TypeError, /must be 'anyfunc'/); + () => new Table({initial: 1, element: 1}), TypeError, /must be a WebAssembly reference type/); assertThrows( () => new Table({initial: 1, element: 'any'}), TypeError, - /must be 'anyfunc'/); + /must be a WebAssembly reference type/); assertThrows( () => new Table({initial: 1, element: {valueOf() { return 'anyfunc' }}}), - TypeError, /must be 'anyfunc'/); + TypeError, /must be a WebAssembly reference type/); assertThrows( () => new Table( {initial: {valueOf() { throw new Error('here') }}, element: 'anyfunc'}), @@ -609,9 +609,9 @@ assertTrue(new Table({initial: 1, element: 'anyfunc'}) instanceof Table); assertTrue(new Table({initial: 1.5, element: 'anyfunc'}) instanceof Table); assertTrue( new Table({initial: 1, maximum: 1.5, element: 'anyfunc'}) instanceof Table); -assertThrows( - () => new Table({initial: 1, maximum: Math.pow(2, 32) - 1, element: 'anyfunc'}), - RangeError, /above the upper bound/); +assertTrue( + new Table({initial: 1, maximum: Math.pow(2, 32) - 1, element: 'anyfunc'}) + instanceof Table); // 'WebAssembly.Table.prototype' data property let tableProtoDesc = Object.getOwnPropertyDescriptor(Table, 'prototype'); @@ -943,13 +943,6 @@ assertInstantiateSuccess( assertTrue(instance instanceof Instance); })(); -(function TestPassBigIntInGlobalWhenNotEnabled() { - assertThrows(() => new WebAssembly.Global({ value: "i64" }, 1), TypeError, - /Can't set the value/); - assertThrows(() => new WebAssembly.Global({ value: "i64" }, 1n), TypeError, - /Can't set the value/); -})(); - (function TestAccessorFunctions() { function testAccessorFunction(obj, prop, accessor) { var desc = Object.getOwnPropertyDescriptor(obj, prop); diff --git a/deps/v8/test/mjsunit/wasm/memory-size.js b/deps/v8/test/mjsunit/wasm/memory-size.js index b83a424285..29b28a12a2 100644 --- a/deps/v8/test/mjsunit/wasm/memory-size.js +++ b/deps/v8/test/mjsunit/wasm/memory-size.js @@ -6,7 +6,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); -var kV8MaxWasmMemoryPages = 32767; // ~ 2 GiB +var kV8MaxWasmMemoryPages = 65536; // 4 GiB var kSpecMaxWasmMemoryPages = 65536; // 4 GiB (function testMemorySizeZero() { diff --git a/deps/v8/test/mjsunit/wasm/multi-table-element-section.js b/deps/v8/test/mjsunit/wasm/multi-table-element-section.js index 59a21efc18..8e099c4ed3 100644 --- a/deps/v8/test/mjsunit/wasm/multi-table-element-section.js +++ b/deps/v8/test/mjsunit/wasm/multi-table-element-section.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 --experimental-wasm-anyref +// Flags: --expose-wasm --experimental-wasm-reftypes load("test/mjsunit/wasm/wasm-module-builder.js"); @@ -78,21 +78,3 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(value4, table4.get(offset4 + 1)()); assertEquals(value3, table4.get(offset4 + 2)()); })(); - -(function TestAnyRefTableWithAnyFuncInit() { - print(arguments.callee.name); - let builder = new WasmModuleBuilder(); - const table = builder.addTable(kWasmAnyRef, 5).index; - builder.addExportOfKind("table", kExternalTable, table); - const f1 = builder.addFunction('f1', kSig_i_v) - .addBody([kExprI32Const, 11]) - .exportFunc().index; - const f2 = builder.addFunction('f2', kSig_i_v) - .addBody([kExprI32Const, 22]) - .exportFunc().index; - - builder.addElementSegment(table, 1, false, [f1, f2]); - const instance = builder.instantiate(); - assertEquals(instance.exports.table.get(1)(), 11); - assertEquals(instance.exports.table.get(2)(), 22); -})(); diff --git a/deps/v8/test/mjsunit/wasm/multi-value-simd.js b/deps/v8/test/mjsunit/wasm/multi-value-simd.js new file mode 100644 index 0000000000..4c4f5f754d --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/multi-value-simd.js @@ -0,0 +1,92 @@ +// Copyright 2017 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-simd --experimental-wasm-mv + +load("test/mjsunit/wasm/wasm-module-builder.js"); + +(function MultiReturnS128Test() { + print("MultiReturnS128Test"); + // Most backends only support 2 fp return registers, so the third v128 + // onwards here will written to caller stack slot. + let builder = new WasmModuleBuilder(); + let sig_v_sssss = builder.addType( + makeSig([], [kWasmS128, kWasmS128, kWasmS128, kWasmS128, kWasmS128])); + let sig_iiiiiiiiii_v = builder.addType( + makeSig([], [kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, + kWasmI32, kWasmI32, kWasmI32, kWasmI32] )); + + let callee = builder.addFunction("callee", sig_v_sssss) + .addBody([ + kExprI32Const, 0, + kSimdPrefix, kExprI32x4Splat, + kExprI32Const, 1, + kSimdPrefix, kExprI32x4Splat, + kExprI32Const, 2, + kSimdPrefix, kExprI32x4Splat, + kExprI32Const, 3, + kSimdPrefix, kExprI32x4Splat, + kExprI32Const, 4, + kSimdPrefix, kExprI32x4Splat, + kExprReturn]); + // For each v128 on the stack, we return the first and last lane. This help + // catch bugs with reading/writing the wrong stack slots. + builder.addFunction("main", sig_iiiiiiiiii_v) + .addLocals({"i32_count": 10, "s128_count": 1}) + .addBody([ + kExprCallFunction, callee.index, + + kExprLocalTee, 10, + kSimdPrefix, kExprI32x4ExtractLane, 0, + kExprLocalSet, 0, + kExprLocalGet, 10, + kSimdPrefix, kExprI32x4ExtractLane, 3, + kExprLocalSet, 1, + + kExprLocalTee, 10, + kSimdPrefix, kExprI32x4ExtractLane, 0, + kExprLocalSet, 2, + kExprLocalGet, 10, + kSimdPrefix, kExprI32x4ExtractLane, 3, + kExprLocalSet, 3, + + kExprLocalTee, 10, + kSimdPrefix, kExprI32x4ExtractLane, 0, + kExprLocalSet, 4, + kExprLocalGet, 10, + kSimdPrefix, kExprI32x4ExtractLane, 3, + kExprLocalSet, 5, + + kExprLocalTee, 10, + kSimdPrefix, kExprI32x4ExtractLane, 0, + kExprLocalSet, 6, + kExprLocalGet, 10, + kSimdPrefix, kExprI32x4ExtractLane, 3, + kExprLocalSet, 7, + + kExprLocalTee, 10, + kSimdPrefix, kExprI32x4ExtractLane, 0, + kExprLocalSet, 8, + kExprLocalGet, 10, + kSimdPrefix, kExprI32x4ExtractLane, 3, + kExprLocalSet, 9, + + // Return all the stored locals. + kExprLocalGet, 0, + kExprLocalGet, 1, + kExprLocalGet, 2, + kExprLocalGet, 3, + kExprLocalGet, 4, + kExprLocalGet, 5, + kExprLocalGet, 6, + kExprLocalGet, 7, + kExprLocalGet, 8, + kExprLocalGet, 9, + ]) + .exportAs("main"); + + let module = new WebAssembly.Module(builder.toBuffer()); + let instance = new WebAssembly.Instance(module); + assertEquals(instance.exports.main(), [4, 4, 3, 3, 2, 2, 1, 1, 0, 0]); +})(); diff --git a/deps/v8/test/mjsunit/wasm/multiple-code-spaces.js b/deps/v8/test/mjsunit/wasm/multiple-code-spaces.js index 2c1a1bd08e..9e786bed23 100644 --- a/deps/v8/test/mjsunit/wasm/multiple-code-spaces.js +++ b/deps/v8/test/mjsunit/wasm/multiple-code-spaces.js @@ -5,6 +5,10 @@ // Flags: --allow-natives-syntax --randomize-all-allocations // Flags: --wasm-max-initial-code-space-reservation=1 +// Disable tier-up, to reduce execution time of this test (Liftoff generates +// much bigger code, thus reaches the four code spaces much faster). +// Flags: --no-wasm-tier-up + load('test/mjsunit/wasm/wasm-module-builder.js'); // Instantiate bigger modules, until at least four separate code spaces have diff --git a/deps/v8/test/mjsunit/wasm/mutable-globals.js b/deps/v8/test/mjsunit/wasm/mutable-globals.js index 261da5669d..e16d318d84 100644 --- a/deps/v8/test/mjsunit/wasm/mutable-globals.js +++ b/deps/v8/test/mjsunit/wasm/mutable-globals.js @@ -21,9 +21,9 @@ function assertGlobalIsValid(global) { assertThrows(() => new WebAssembly.Global({}), TypeError); assertThrows(() => new WebAssembly.Global({value: 'foo'}), TypeError); assertThrows(() => new WebAssembly.Global({value: 'i128'}), TypeError); - // Without --experimental-wasm-anyref, globals of type {anyref} and {anyfunc} + // Without --experimental-wasm-reftypes, globals of type {externref} and {anyfunc} // are not allowed. - assertThrows(() => new WebAssembly.Global({value: 'anyref'}), TypeError); + assertThrows(() => new WebAssembly.Global({value: 'externref'}), TypeError); assertThrows(() => new WebAssembly.Global({value: 'anyfunc'}), TypeError); for (let type of ['i32', 'f32', 'f64', 'i64']) { diff --git a/deps/v8/test/mjsunit/wasm/nullref.js b/deps/v8/test/mjsunit/wasm/nullref.js deleted file mode 100644 index 49017bfbf5..0000000000 --- a/deps/v8/test/mjsunit/wasm/nullref.js +++ /dev/null @@ -1,400 +0,0 @@ -// Copyright 2020 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-anyref --experimental-wasm-eh - -load('test/mjsunit/wasm/wasm-module-builder.js'); - -let kSig_n_n = makeSig([kWasmNullRef], [kWasmNullRef]); -let kSig_r_n = makeSig([kWasmNullRef], [kWasmAnyRef]); -let kSig_a_n = makeSig([kWasmNullRef], [kWasmAnyFunc]); -let kSig_e_n = makeSig([kWasmNullRef], [kWasmExnRef]); -let kSig_n_v = makeSig([], [kWasmNullRef]); -let kSig_n_r = makeSig([kWasmAnyRef], [kWasmNullRef]); -let kSig_n_a = makeSig([kWasmAnyFunc], [kWasmNullRef]); -let kSig_n_e = makeSig([kWasmExnRef], [kWasmNullRef]); -let kSig_v_n = makeSig([kWasmNullRef], []); -let kSig_v_in = makeSig([kWasmI32, kWasmNullRef], []); -let kSig_n_i = makeSig([kWasmI32], [kWasmNullRef]); -let kSig_r_i = makeSig([kWasmI32], [kWasmAnyRef]); -let kSig_e_i = makeSig([kWasmI32], [kWasmExnRef]); -let kSig_n_nni = makeSig([kWasmNullRef, kWasmNullRef, kWasmI32], [kWasmNullRef]); -let kSig_r_nni = makeSig([kWasmNullRef, kWasmNullRef, kWasmI32], [kWasmAnyRef]); -let kSig_a_nni = makeSig([kWasmNullRef, kWasmNullRef, kWasmI32], [kWasmAnyFunc]); -let kSig_e_nni = makeSig([kWasmNullRef, kWasmNullRef, kWasmI32], [kWasmExnRef]); - -(function testNullRefIdentityFunction() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - builder.addFunction('nullRef', kSig_n_n) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - builder.addFunction('anyRef', kSig_r_n) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - builder.addFunction('funcRef', kSig_a_n) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - builder.addFunction('exnRef', kSig_e_n) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - const instance = builder.instantiate(); - - assertThrows(() => instance.exports.nullRef(a => a), TypeError); - assertThrows(() => instance.exports.nullRef(print), TypeError); - assertThrows(() => instance.exports.nullRef({'hello': 'world'}), TypeError); - assertEquals(null, instance.exports.nullRef(null)); - assertEquals(null, instance.exports.anyRef(null)); - assertEquals(null, instance.exports.funcRef(null)); - assertEquals(null, instance.exports.exnRef(null)); -})(); - -(function testNullRefFromAnyRefFail() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_r); - builder.addFunction('main', sig_index) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - assertThrows(() => builder.instantiate(), WebAssembly.CompileError); -})(); - -(function testNullRefFromFuncRefFail() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_a); - builder.addFunction('main', sig_index) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - assertThrows(() => builder.instantiate(), WebAssembly.CompileError); -})(); - -(function testNullRefFromExnRefFail() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_e); - builder.addFunction('main', sig_index) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - assertThrows(() => builder.instantiate(), WebAssembly.CompileError); -})(); - -(function testNullRefDefaultValue() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_v); - builder.addFunction('main', sig_index) - .addLocals({nullref_count: 1}) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - const main = builder.instantiate().exports.main; - assertEquals(null, main()); -})(); - -(function testNullRefFromAnyRefFail() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_v); - builder.addFunction('main', sig_index) - .addLocals({anyref_count: 1}) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - assertThrows(() => builder.instantiate(), WebAssembly.CompileError); -})(); - -(function testNullRefFromFuncRefFail() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_v); - builder.addFunction('main', sig_index) - .addLocals({anyfunc_count: 1}) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - assertThrows(() => builder.instantiate(), WebAssembly.CompileError); -})(); - -(function testNullRefFromExnRefFail() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_v); - builder.addFunction('main', sig_index) - .addLocals({exnref_count: 1}) - .addBody([kExprLocalGet, 0]) - .exportFunc(); - - assertThrows(() => builder.instantiate(), WebAssembly.CompileError); -})(); - -(function testAssignNullRefToNullRefLocal() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_n); - builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kExprLocalSet, 0, kExprLocalGet, 0]) - .exportFunc(); - - const main = builder.instantiate().exports.main; - assertEquals(null, main(null)); -})(); - -(function testImplicitReturnNullRefAsNullRef() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_v); - builder.addFunction('main', sig_index) - .addBody([kExprRefNull]) - .exportFunc(); - - const main = builder.instantiate().exports.main; - assertEquals(null, main()); -})(); - -(function testExplicitReturnNullRefAsNullRef() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const sig_index = builder.addType(kSig_n_v); - builder.addFunction('main', sig_index) - .addBody([kExprRefNull, kExprReturn]) - .exportFunc(); - - const main = builder.instantiate().exports.main; - assertEquals(null, main()); -})(); - -(function testGetNullRefGlobal() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const initialized = builder.addGlobal(kWasmNullRef, true) - .exportAs('initialized'); - initialized.init = null; - const uninitialized = builder.addGlobal(kWasmNullRef, true) - .exportAs('uninitialized'); - const sig_n_v = builder.addType(kSig_n_v); - const sig_v_n = builder.addType(kSig_v_n); - const sig_v_v = builder.addType(kSig_v_v); - builder.addFunction('get_initialized', sig_n_v) - .addBody([kExprGlobalGet, initialized.index]) - .exportFunc(); - builder.addFunction('get_uninitialized', sig_n_v) - .addBody([kExprGlobalGet, initialized.index]) - .exportFunc(); - builder.addFunction('set_initialized', sig_v_n) - .addBody([kExprLocalGet, 0, kExprGlobalSet, initialized.index]) - .exportFunc(); - builder.addFunction('reset_initialized', sig_v_v) - .addBody([kExprRefNull, kExprGlobalSet, initialized.index]) - .exportFunc(); - - const instance = builder.instantiate(); - assertTrue(instance.exports.initialized instanceof WebAssembly.Global); - assertTrue(instance.exports.uninitialized instanceof WebAssembly.Global); - assertEquals(instance.exports.initialized.value, null); - assertEquals(instance.exports.uninitialized.value, null); - assertEquals(null, instance.exports.get_initialized()); - assertEquals(null, instance.exports.get_uninitialized()); - - instance.exports.set_initialized(null); - assertEquals(instance.exports.initialized.value, null); - assertEquals(null, instance.exports.get_initialized()); - - instance.exports.reset_initialized(); - assertEquals(instance.exports.initialized.value, null); - assertEquals(null, instance.exports.get_initialized()); -})(); - -(function testGetNullRefImportedGlobal() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const global_index = builder.addImportedGlobal("foo", "bar", - kWasmNullRef); - const sig_n_v = builder.addType(kSig_n_v); - const sig_v_n = builder.addType(kSig_v_n); - const sig_v_v = builder.addType(kSig_v_v); - builder.addFunction('get', sig_n_v) - .addBody([kExprGlobalGet, global_index]) - .exportFunc(); - - assertThrows(() => builder.instantiate(), TypeError); - assertThrows(() => builder.instantiate({foo: {}}), WebAssembly.LinkError); - assertThrows(() => builder.instantiate({foo: {bar: {}}}), - WebAssembly.LinkError); - assertThrows(() => builder.instantiate({foo: {bar: a => a}}), - WebAssembly.LinkError); - - const instance = builder.instantiate({foo: {bar: null}}); - assertEquals(null, instance.exports.get()); -})(); - -(function testNullRefTable() { - print(arguments.callee.name); - let table = new WebAssembly.Table({element: "nullref", initial: 2}); - - assertEquals(null, table.get(0)); - table.set(1, null); - assertEquals(null, table.get(1)); - assertThrows(() => table.set(2, null), RangeError); - - table.grow(2); - - assertEquals(null, table.get(2)); - table.set(3, null); - assertEquals(null, table.get(3)); - assertThrows(() => table.set(4, null), RangeError); - - assertThrows(() => table.set(0, {}), TypeError); - assertThrows(() => table.set(0, a => a), TypeError); -})(); - -(function testAddNullRefTable() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const table = builder.addTable(kWasmNullRef, 3, 10); - builder.addFunction('set_null', kSig_v_i) - .addBody([kExprLocalGet, 0, kExprRefNull, kExprTableSet, table.index]) - .exportFunc(); - builder.addFunction('set', kSig_v_in) - .addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprTableSet, table.index]) - .exportFunc(); - builder.addFunction('get_null', kSig_n_i) - .addBody([kExprLocalGet, 0, kExprTableGet, table.index]) - .exportFunc(); - builder.addFunction('get_any', kSig_r_i) - .addBody([kExprLocalGet, 0, kExprTableGet, table.index]) - .exportFunc(); - builder.addFunction('get_func', kSig_a_i) - .addBody([kExprLocalGet, 0, kExprTableGet, table.index]) - .exportFunc(); - builder.addFunction('get_exn', kSig_e_i) - .addBody([kExprLocalGet, 0, kExprTableGet, table.index]) - .exportFunc(); - - const instance = builder.instantiate(); - instance.exports.set_null(1); - instance.exports.set(2, null); - - assertEquals(null, instance.exports.get_null(0)); - assertEquals(null, instance.exports.get_null(1)); - assertEquals(null, instance.exports.get_null(2)); - assertEquals(null, instance.exports.get_any(0)); - assertEquals(null, instance.exports.get_any(1)); - assertEquals(null, instance.exports.get_any(2)); - assertEquals(null, instance.exports.get_func(0)); - assertEquals(null, instance.exports.get_func(1)); - assertEquals(null, instance.exports.get_func(2)); - assertEquals(null, instance.exports.get_exn(0)); - assertEquals(null, instance.exports.get_exn(1)); - assertEquals(null, instance.exports.get_exn(2)); -})(); - -(function testImportNullRefTable() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const table_index = builder.addImportedTable("imp", "table", 2, 10, - kWasmNullRef); - builder.addFunction('get_null', kSig_n_i) - .addBody([kExprLocalGet, 0, kExprTableGet, table_index]) - .exportFunc(); - builder.addFunction('get_any', kSig_r_i) - .addBody([kExprLocalGet, 0, kExprTableGet, table_index]) - .exportFunc(); - builder.addFunction('get_func', kSig_a_i) - .addBody([kExprLocalGet, 0, kExprTableGet, table_index]) - .exportFunc(); - builder.addFunction('get_exn', kSig_e_i) - .addBody([kExprLocalGet, 0, kExprTableGet, table_index]) - .exportFunc(); - - let table_func = new WebAssembly.Table({element: "anyfunc", initial: 2, - maximum: 10}); - assertThrows(() => builder.instantiate({imp: {table: table_func}}), - WebAssembly.LinkError, /imported table does not match the expected type/); - - let table_any = new WebAssembly.Table({element: "anyref", initial: 2, - maximum: 10}); - assertThrows(() => builder.instantiate({imp: {table: table_any}}), - WebAssembly.LinkError, /imported table does not match the expected type/); - - let table_null = new WebAssembly.Table({element: "nullref", initial: 2, - maximum: 10}); - table_null.set(1, null); - const instance = builder.instantiate({imp: {table: table_null}}); - - assertEquals(null, instance.exports.get_null(0)); - assertEquals(null, instance.exports.get_null(1)); - assertEquals(null, instance.exports.get_any(0)); - assertEquals(null, instance.exports.get_any(1)); - assertEquals(null, instance.exports.get_func(0)); - assertEquals(null, instance.exports.get_func(1)); - assertEquals(null, instance.exports.get_exn(0)); - assertEquals(null, instance.exports.get_exn(1)); - - assertThrows(() => instance.exports.get_null(2), WebAssembly.RuntimeError); - table_null.grow(1); - assertEquals(null, instance.exports.get_null(2)); -})(); - -(function testImportNullRefTableIntoAnyRefTable() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - const table_index = builder.addImportedTable("imp", "table", 2, 10, - kWasmAnyRef); - builder.addFunction('get', kSig_r_v) - .addBody([kExprI32Const, 0, kExprTableGet, table_index]) - .exportFunc(); - - let table_null = new WebAssembly.Table({element: "nullref", initial: 2, - maximum: 10}); - assertThrows(() => builder.instantiate({imp: {table: table_null}}), - WebAssembly.LinkError, /imported table does not match the expected type/); -})(); - -(function testSelectNullRef() { - print(arguments.callee.name); - const builder = new WasmModuleBuilder(); - builder.addFunction('select_null', kSig_n_nni) - .addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 2, - kExprSelectWithType, 1, kWasmNullRef]) - .exportFunc(); - builder.addFunction('select_any', kSig_r_nni) - .addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 2, - kExprSelectWithType, 1, kWasmAnyRef]) - .exportFunc(); - builder.addFunction('select_func', kSig_a_nni) - .addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 2, - kExprSelectWithType, 1, kWasmAnyFunc]) - .exportFunc(); - builder.addFunction('select_exn', kSig_e_nni) - .addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 2, - kExprSelectWithType, 1, kWasmExnRef]) - .exportFunc(); - builder.addFunction('select_null_as_any', kSig_r_nni) - .addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 2, - kExprSelectWithType, 1, kWasmNullRef]) - .exportFunc(); - builder.addFunction('select_null_as_func', kSig_a_nni) - .addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 2, - kExprSelectWithType, 1, kWasmNullRef]) - .exportFunc(); - builder.addFunction('select_null_as_exn', kSig_e_nni) - .addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 2, - kExprSelectWithType, 1, kWasmNullRef]) - .exportFunc(); - - const instance = builder.instantiate(); - - assertEquals(null, instance.exports.select_null(null, null, 0)); - assertEquals(null, instance.exports.select_any(null, null, 0)); - assertEquals(null, instance.exports.select_func(null, null, 0)); - assertEquals(null, instance.exports.select_exn(null, null, 0)); - assertEquals(null, instance.exports.select_null_as_any(null, null, 0)); - assertEquals(null, instance.exports.select_null_as_func(null, null, 0)); - assertEquals(null, instance.exports.select_null_as_exn(null, null, 0)); -})(); diff --git a/deps/v8/test/mjsunit/wasm/print-code.js b/deps/v8/test/mjsunit/wasm/print-code.js index c604ca75f0..876a545846 100644 --- a/deps/v8/test/mjsunit/wasm/print-code.js +++ b/deps/v8/test/mjsunit/wasm/print-code.js @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --allow-natives-syntax --print-wasm-code +// The test needs --wasm-tier-up because we can't serialize and deserialize +// Liftoff code. +// Flags: --allow-natives-syntax --print-wasm-code --wasm-tier-up // Just test that printing the code of the following wasm modules does not // crash. diff --git a/deps/v8/test/mjsunit/wasm/return-calls.js b/deps/v8/test/mjsunit/wasm/return-calls.js index 7dd56ef02f..f7a90d2678 100644 --- a/deps/v8/test/mjsunit/wasm/return-calls.js +++ b/deps/v8/test/mjsunit/wasm/return-calls.js @@ -159,3 +159,46 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); print(" --right--"); assertEquals(3, module.exports.main(0, -2, 3)); })(); + +(function TestMultiReturnCallWithLongSig() { + print(arguments.callee.name); + const callee_inputs = 10; + // Tail call from a function with less, as many, or more parameters than the + // callee. + for (caller_inputs = 9; caller_inputs <= 11; ++caller_inputs) { + let builder = new WasmModuleBuilder(); + + // f just returns its arguments in reverse order. + const f_params = new Array(callee_inputs).fill(kWasmI32); + const f_returns = f_params; + const f_sig = builder.addType(makeSig(f_params, f_returns)); + let f_body = []; + for (i = 0; i < callee_inputs; ++i) { + f_body.push(kExprLocalGet, callee_inputs - i - 1); + } + const f = builder.addFunction("f", f_sig).addBody(f_body); + + // Slice or pad the caller inputs to match the callee. + const main_params = new Array(caller_inputs).fill(kWasmI32); + const main_sig = builder.addType(makeSig(main_params, f_returns)); + let main_body = []; + for (i = 0; i < callee_inputs; ++i) { + main_body.push(kExprLocalGet, Math.min(caller_inputs - 1, i)); + } + main_body.push(kExprReturnCall, f.index); + builder.addFunction("main", main_sig).addBody(main_body).exportFunc(); + + let module = builder.instantiate(); + + inputs = []; + for (i = 0; i < caller_inputs; ++i) { + inputs.push(i); + } + let expect = inputs.slice(0, callee_inputs); + while (expect.length < callee_inputs) { + expect.push(inputs[inputs.length - 1]); + } + expect.reverse(); + assertEquals(expect, module.exports.main(...inputs)); + } +})(); diff --git a/deps/v8/test/mjsunit/wasm/simd-errors.js b/deps/v8/test/mjsunit/wasm/simd-errors.js new file mode 100644 index 0000000000..75c427026d --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/simd-errors.js @@ -0,0 +1,65 @@ +// Copyright 2020 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-simd + +load("test/mjsunit/wasm/wasm-module-builder.js"); + +(function TestS128InSignatureThrows() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + builder.addFunction('foo', kSig_s_i) + .addBody([ + kExprLocalGet, 0, + kSimdPrefix, + kExprI32x4Splat]) + .exportFunc() + const instance = builder.instantiate(); + assertThrows(() => instance.exports.foo(33), TypeError); +})(); + +(function TestS128ParamInSignatureThrows() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + builder.addFunction('foo', kSig_i_s) + .addBody([ + kExprLocalGet, 0, + kSimdPrefix, + kExprI32x4ExtractLane, 1]) + .exportFunc(); + const instance = builder.instantiate(); + assertThrows(() => instance.exports.foo(10), TypeError); +})(); + +(function TestImportS128Return() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + builder.addImport('', 'f', makeSig([], [kWasmS128])); + builder.addFunction('foo', kSig_v_v) + .addBody([kExprCallFunction, 0, kExprDrop]) + .exportFunc(); + const instance = builder.instantiate({'': {f: _ => 1}}); + assertThrows(() => instance.exports.foo(), TypeError); +})(); + +(function TestS128ImportThrows() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + let sig_index = builder.addType(kSig_i_i); + let sig_s128_index = builder.addType(kSig_i_s); + let index = builder.addImport('', 'func', sig_s128_index); + builder.addFunction('foo', sig_index) + .addBody([ + kExprLocalGet, 0, + kSimdPrefix, + kExprI32x4Splat, + kExprCallFunction, index]) + .exportFunc(); + const instance = builder.instantiate({'': {func: _ => {}}}); + assertThrows(() => instance.exports.foo(14), TypeError); +})(); + +(function TestS128GlobalConstructor() { + assertThrows(() => new WebAssembly.Global({value: 'i128'}), TypeError); +})(); diff --git a/deps/v8/test/mjsunit/wasm/simd-globals.js b/deps/v8/test/mjsunit/wasm/simd-globals.js new file mode 100644 index 0000000000..dce1337ec6 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/simd-globals.js @@ -0,0 +1,37 @@ +// Copyright 2020 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-simd + +load("test/mjsunit/wasm/wasm-module-builder.js"); + +// Test for S128 global with initialization. +// This checks for a bug in copying the immediate values from the +// initialization expression into the globals area of the module. +(function TestS128() { + var builder = new WasmModuleBuilder(); + var g = builder.addGlobal(kWasmS128); + g.init = [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]; + + // Check that all lanes have the right values by creating 4 functions that + // extract each lane. + function addGetFunction(i) { + builder.addFunction(`get${i}`, kSig_i_v) + .addBody([ + kExprGlobalGet, g.index, + kSimdPrefix, kExprI32x4ExtractLane, i]) + .exportAs(`get${i}`); + } + + for (let i = 0; i < 4; i++) { + addGetFunction(i); + } + + var instance = builder.instantiate(); + + for (let i = 0; i < 4; i++) { + // get0 will get lane0, which has value 1 + assertEquals(i+1, instance.exports[`get${i}`]()); + } +})(); diff --git a/deps/v8/test/mjsunit/wasm/table-access.js b/deps/v8/test/mjsunit/wasm/table-access.js index 7c1bf1eb19..bde5793acc 100644 --- a/deps/v8/test/mjsunit/wasm/table-access.js +++ b/deps/v8/test/mjsunit/wasm/table-access.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 --experimental-wasm-anyref +// Flags: --expose-wasm --experimental-wasm-reftypes load("test/mjsunit/wasm/wasm-module-builder.js"); @@ -25,8 +25,8 @@ function addTableWithAccessors(builder, type, size, name) { const builder = new WasmModuleBuilder(); addTableWithAccessors(builder, kWasmAnyFunc, 10, 'table_func1'); -addTableWithAccessors(builder, kWasmAnyRef, 20, 'table_ref1'); -addTableWithAccessors(builder, kWasmAnyRef, 9, 'table_ref2'); +addTableWithAccessors(builder, kWasmExternRef, 20, 'table_ref1'); +addTableWithAccessors(builder, kWasmExternRef, 9, 'table_ref2'); addTableWithAccessors(builder, kWasmAnyFunc, 12, 'table_func2'); let exports = builder.instantiate().exports; diff --git a/deps/v8/test/mjsunit/wasm/table-copy-anyref.js b/deps/v8/test/mjsunit/wasm/table-copy-externref.js index 5fe9c24d55..391fb606bd 100644 --- a/deps/v8/test/mjsunit/wasm/table-copy-anyref.js +++ b/deps/v8/test/mjsunit/wasm/table-copy-externref.js @@ -2,17 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --experimental-wasm-bulk-memory --experimental-wasm-anyref +// Flags: --experimental-wasm-bulk-memory --experimental-wasm-reftypes load('test/mjsunit/wasm/wasm-module-builder.js'); let kTableSize = 5; let table = new WebAssembly.Table( - {element: 'anyref', initial: kTableSize, maximum: kTableSize}); + {element: 'externref', initial: kTableSize, maximum: kTableSize}); let builder = new WasmModuleBuilder(); -builder.addImportedTable('m', 'table', kTableSize, kTableSize, kWasmAnyRef); +builder.addImportedTable('m', 'table', kTableSize, kTableSize, kWasmExternRef); builder.addTable(kWasmAnyFunc, 1000); builder.addFunction('copy', kSig_v_iii) diff --git a/deps/v8/test/mjsunit/wasm/table-fill.js b/deps/v8/test/mjsunit/wasm/table-fill.js index 760c662c7f..86b0630042 100644 --- a/deps/v8/test/mjsunit/wasm/table-fill.js +++ b/deps/v8/test/mjsunit/wasm/table-fill.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 --experimental-wasm-anyref +// Flags: --expose-wasm --experimental-wasm-reftypes load('test/mjsunit/wasm/wasm-module-builder.js'); @@ -14,21 +14,21 @@ function dummy_func(val) { return builder.instantiate().exports.dummy; } -let kSig_v_iri = makeSig([kWasmI32, kWasmAnyRef, kWasmI32], []); +let kSig_v_iri = makeSig([kWasmI32, kWasmExternRef, kWasmI32], []); let kSig_v_iai = makeSig([kWasmI32, kWasmAnyFunc, kWasmI32], []); -let kSig_r_i = makeSig([kWasmI32], [kWasmAnyRef]); +let kSig_r_i = makeSig([kWasmI32], [kWasmExternRef]); const builder = new WasmModuleBuilder(); const size = 10; const maximum = size; const import_ref = - builder.addImportedTable('imp', 'table_ref', size, maximum, kWasmAnyRef); + builder.addImportedTable('imp', 'table_ref', size, maximum, kWasmExternRef); const import_func = builder.addImportedTable('imp', 'table_func', size, maximum, kWasmAnyFunc); -const internal_ref = builder.addTable(kWasmAnyRef, size, maximum).index; +const internal_ref = builder.addTable(kWasmExternRef, size, maximum).index; const internal_func = builder.addTable(kWasmAnyFunc, size, maximum).index; -// Add fill and get functions for the anyref tables. +// Add fill and get functions for the externref tables. for (index of [import_ref, internal_ref]) { builder.addFunction(`fill${index}`, kSig_v_iri) .addBody([ @@ -58,40 +58,40 @@ for (index of [import_func, internal_func]) { } const table_ref = - new WebAssembly.Table({element: 'anyref', initial: size, maximum: maximum}); + new WebAssembly.Table({element: 'externref', initial: size, maximum: maximum}); const table_func = new WebAssembly.Table( {element: 'anyfunc', initial: size, maximum: maximum}); const instance = builder.instantiate({imp: {table_ref: table_ref, table_func: table_func}}); -function checkAnyRefTable(getter, start, count, value) { +function checkExternRefTable(getter, start, count, value) { for (i = 0; i < count; ++i) { assertEquals(value, getter(start + i)); } } -(function testAnyRefTableIsUninitialized() { +(function testExternRefTableIsUninitialized() { print(arguments.callee.name); - checkAnyRefTable(instance.exports[`get${import_ref}`], 0, size, null); - checkAnyRefTable(instance.exports[`get${internal_ref}`], 0, size, null); + checkExternRefTable(instance.exports[`get${import_ref}`], 0, size, null); + checkExternRefTable(instance.exports[`get${internal_ref}`], 0, size, null); })(); -(function testAnyRefTableFill() { +(function testExternRefTableFill() { print(arguments.callee.name); // Fill table and check the content. let start = 1; let value = {foo: 23}; let count = 3; instance.exports[`fill${import_ref}`](start, value, count); - checkAnyRefTable(instance.exports[`get${import_ref}`], start, count, value); + checkExternRefTable(instance.exports[`get${import_ref}`], start, count, value); value = 'foo'; instance.exports[`fill${internal_ref}`](start, value, count); - checkAnyRefTable(instance.exports[`get${internal_ref}`], start, count, value); + checkExternRefTable(instance.exports[`get${internal_ref}`], start, count, value); })(); -(function testAnyRefTableFillOOB() { +(function testExternRefTableFillOOB() { print(arguments.callee.name); // Fill table out-of-bounds, check if the table wasn't altered. let start = 7; @@ -101,18 +101,18 @@ function checkAnyRefTable(getter, start, count, value) { assertTraps( kTrapTableOutOfBounds, () => instance.exports[`fill${import_ref}`](start, value, count)); - checkAnyRefTable( + checkExternRefTable( instance.exports[`get${import_ref}`], start, size - start, null); value = 45; assertTraps( kTrapTableOutOfBounds, () => instance.exports[`fill${internal_ref}`](start, value, count)); - checkAnyRefTable( + checkExternRefTable( instance.exports[`get${internal_ref}`], start, size - start, null); })(); -(function testAnyRefTableFillOOBCountZero() { +(function testExternRefTableFillOOBCountZero() { print(arguments.callee.name); // Fill 0 elements at an oob position. This should trap. let start = size + 32; @@ -135,7 +135,7 @@ function checkAnyFuncTable(call, start, count, value) { } } -(function testAnyRefTableIsUninitialized() { +(function testExternRefTableIsUninitialized() { print(arguments.callee.name); // Check that the table is uninitialized. checkAnyFuncTable(instance.exports[`call${import_func}`], 0, size); diff --git a/deps/v8/test/mjsunit/wasm/table-grow-from-wasm.js b/deps/v8/test/mjsunit/wasm/table-grow-from-wasm.js index 8018407348..797edad88a 100644 --- a/deps/v8/test/mjsunit/wasm/table-grow-from-wasm.js +++ b/deps/v8/test/mjsunit/wasm/table-grow-from-wasm.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 --experimental-wasm-anyref +// Flags: --expose-wasm --experimental-wasm-reftypes load("test/mjsunit/wasm/wasm-module-builder.js"); @@ -14,18 +14,18 @@ function dummy_func(val) { return builder.instantiate().exports.dummy; } -let kSig_i_ri = makeSig([kWasmAnyRef, kWasmI32], [kWasmI32]); -let kSig_r_i = makeSig([kWasmI32], [kWasmAnyRef]); +let kSig_i_ri = makeSig([kWasmExternRef, kWasmI32], [kWasmI32]); +let kSig_r_i = makeSig([kWasmI32], [kWasmExternRef]); let kSig_i_ai = makeSig([kWasmAnyFunc, kWasmI32], [kWasmI32]); -function testGrowInternalAnyRefTable(table_index) { +function testGrowInternalExternRefTable(table_index) { print(arguments.callee.name, table_index); const builder = new WasmModuleBuilder(); const initial_size = 5; // Add 10 tables, we only test one. for (let i = 0; i < 10; ++i) { - builder.addTable(kWasmAnyRef, initial_size).index; + builder.addTable(kWasmExternRef, initial_size).index; } builder.addFunction('grow', kSig_i_ri) .addBody([kExprLocalGet, 0, @@ -62,9 +62,9 @@ function testGrowInternalAnyRefTable(table_index) { growAndCheck(null, 2); } -testGrowInternalAnyRefTable(0); -testGrowInternalAnyRefTable(7); -testGrowInternalAnyRefTable(9); +testGrowInternalExternRefTable(0); +testGrowInternalExternRefTable(7); +testGrowInternalExternRefTable(9); function testGrowInternalAnyFuncTable(table_index) { print(arguments.callee.name, table_index); @@ -116,7 +116,7 @@ testGrowInternalAnyFuncTable(9); let size = 3; const builder = new WasmModuleBuilder(); - const table_index = builder.addImportedTable("imp", "table", size, undefined, kWasmAnyRef); + const table_index = builder.addImportedTable("imp", "table", size, undefined, kWasmExternRef); builder.addFunction('grow', kSig_i_ri) .addBody([kExprLocalGet, 0, kExprLocalGet, 1, @@ -127,7 +127,7 @@ testGrowInternalAnyFuncTable(9); .addBody([kNumericPrefix, kExprTableSize, table_index]) .exportFunc(); - const table = new WebAssembly.Table({element: "anyref", initial: size}); + const table = new WebAssembly.Table({element: "externref", initial: size}); const instance = builder.instantiate({imp: {table: table}}); assertEquals(null, table.get(size - 2)); @@ -157,10 +157,10 @@ testGrowInternalAnyFuncTable(9); const builder = new WasmModuleBuilder(); const import_ref = builder.addImportedTable( - "imp", "table_ref", initial, maximum, kWasmAnyRef); + "imp", "table_ref", initial, maximum, kWasmExternRef); const import_func = builder.addImportedTable( "imp", "table_func", initial, maximum, kWasmAnyFunc); - const internal_ref = builder.addTable(kWasmAnyRef, initial, maximum).index; + const internal_ref = builder.addTable(kWasmExternRef, initial, maximum).index; const internal_func = builder.addTable(kWasmAnyFunc, initial, maximum).index; builder.addFunction('grow_imported_ref', kSig_i_ri) @@ -204,7 +204,7 @@ testGrowInternalAnyFuncTable(9); .exportFunc(); const table_ref = new WebAssembly.Table( - { element: "anyref", initial: initial, maximum: maximum }); + { element: "externref", initial: initial, maximum: maximum }); const table_func = new WebAssembly.Table( {element: "anyfunc", initial: initial, maximum: maximum}); diff --git a/deps/v8/test/mjsunit/wasm/table-grow.js b/deps/v8/test/mjsunit/wasm/table-grow.js index d2b7970bfa..85b43db0d7 100644 --- a/deps/v8/test/mjsunit/wasm/table-grow.js +++ b/deps/v8/test/mjsunit/wasm/table-grow.js @@ -283,7 +283,7 @@ let id = (() => { // identity exported function print("Verifying bounds for size = " + size); assertEquals(size, table.length); for (let i = 0; i < 5; i++) { - // Sanity check for indirect call + // Validity check for indirect call assertEquals(10, instances[i].exports.main(0)); // Bounds check at different out of bounds indices assertInvalidFunction = function(s) { diff --git a/deps/v8/test/mjsunit/wasm/table-limits.js b/deps/v8/test/mjsunit/wasm/table-limits.js index 7e31bf1f5b..f8364cd8fd 100644 --- a/deps/v8/test/mjsunit/wasm/table-limits.js +++ b/deps/v8/test/mjsunit/wasm/table-limits.js @@ -18,9 +18,9 @@ const oob = 11; (function TestJSTableMaximumAboveTheLimit() { print(arguments.callee.name); - assertThrows( - () => new WebAssembly.Table({ initial: 1, maximum: oob, element: "anyfunc" }), - RangeError, /above the upper bound/); + let table = + new WebAssembly.Table({initial: 1, maximum: oob, element: 'anyfunc'}); + assertThrows(() => table.grow(oob - 1), RangeError, /failed to grow table/); })(); (function TestDecodeTableInitialAboveTheLimit() { @@ -29,14 +29,14 @@ const oob = 11; builder.setTableBounds(oob); assertThrows( () => builder.instantiate(), - WebAssembly.CompileError, /is larger than implementation limit/); + RangeError, /is larger than implementation limit/); })(); (function TestDecodeTableMaximumAboveTheLimit() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); builder.setTableBounds(1, oob); - assertThrows( - () => builder.instantiate(), - WebAssembly.CompileError, /is larger than implementation limit/); + // Should not throw, as the table does not exceed the limit at instantiation + // time. + builder.instantiate(); })(); diff --git a/deps/v8/test/mjsunit/wasm/table.js b/deps/v8/test/mjsunit/wasm/table.js index 3ee33be688..377194b302 100644 --- a/deps/v8/test/mjsunit/wasm/table.js +++ b/deps/v8/test/mjsunit/wasm/table.js @@ -89,9 +89,12 @@ function assertTableIsValid(table, length) { table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: kV8MaxWasmTableSize}); assertTableIsValid(table, 0); + table = new WebAssembly.Table({element: "anyfunc", initial: 0, maximum: kV8MaxWasmTableSize + 1}); + assertTableIsValid(table, 0); + assertThrows( () => new WebAssembly.Table( - {element: "anyfunc", initial: 0, maximum: kV8MaxWasmTableSize + 1}), + {element: "anyfunc", initial: kV8MaxWasmTableSize + 1}), RangeError, /above the upper bound/); })(); diff --git a/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js b/deps/v8/test/mjsunit/wasm/type-reflection-with-externref.js index 98e7b8fb85..0312c828b0 100644 --- a/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js +++ b/deps/v8/test/mjsunit/wasm/type-reflection-with-externref.js @@ -2,35 +2,35 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --experimental-wasm-type-reflection --experimental-wasm-anyref +// Flags: --experimental-wasm-type-reflection --experimental-wasm-reftypes load('test/mjsunit/wasm/wasm-module-builder.js'); (function TestTableType() { - let table = new WebAssembly.Table({initial: 1, element: "anyref"}); + let table = new WebAssembly.Table({initial: 1, element: "externref"}); let type = WebAssembly.Table.type(table); assertEquals(1, type.minimum); - assertEquals("anyref", type.element); + assertEquals("externref", type.element); assertEquals(2, Object.getOwnPropertyNames(type).length); - table = new WebAssembly.Table({initial: 2, maximum: 15, element: "anyref"}); + table = new WebAssembly.Table({initial: 2, maximum: 15, element: "externref"}); type = WebAssembly.Table.type(table); assertEquals(2, type.minimum); assertEquals(15, type.maximum); - assertEquals("anyref", type.element); + assertEquals("externref", type.element); assertEquals(3, Object.getOwnPropertyNames(type).length); })(); (function TestGlobalType() { - let global = new WebAssembly.Global({value: "anyref", mutable: true}); + let global = new WebAssembly.Global({value: "externref", mutable: true}); let type = WebAssembly.Global.type(global); - assertEquals("anyref", type.value); + assertEquals("externref", type.value); assertEquals(true, type.mutable); assertEquals(2, Object.getOwnPropertyNames(type).length); - global = new WebAssembly.Global({value: "anyref"}); + global = new WebAssembly.Global({value: "externref"}); type = WebAssembly.Global.type(global); - assertEquals("anyref", type.value); + assertEquals("externref", type.value); assertEquals(false, type.mutable); assertEquals(2, Object.getOwnPropertyNames(type).length); @@ -74,7 +74,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); })(); // This is an extension of "type-reflection.js/TestFunctionTableSetAndCall" to -// multiple table indexes. If --experimental-wasm-anyref is enabled by default +// multiple table indexes. If --experimental-wasm-reftypes is enabled by default // this test case can supersede the other one. (function TestFunctionMultiTableSetAndCall() { let builder = new WasmModuleBuilder(); diff --git a/deps/v8/test/mjsunit/wasm/type-reflection.js b/deps/v8/test/mjsunit/wasm/type-reflection.js index c0dfd8b26b..ca3c99db73 100644 --- a/deps/v8/test/mjsunit/wasm/type-reflection.js +++ b/deps/v8/test/mjsunit/wasm/type-reflection.js @@ -549,12 +549,6 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); }); })(); -(function TestFunctionConstructedIncompatibleSig() { - let fun = new WebAssembly.Function({parameters:["i64"], results:[]}, _ => 0); - assertThrows(() => fun(), TypeError, - /wasm function signature contains illegal type/); -})(); - (function TestFunctionTableSetAndCall() { let builder = new WasmModuleBuilder(); let fun1 = new WebAssembly.Function({parameters:[], results:["i32"]}, _ => 7); @@ -578,9 +572,9 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); assertTraps(kTrapFuncSigMismatch, () => instance.exports.main(1)); })(); -(function TestFunctionTableSetIncompatibleSig() { +(function TestFunctionTableSetI64() { let builder = new WasmModuleBuilder(); - let fun = new WebAssembly.Function({parameters:[], results:["i64"]}, _ => 0); + let fun = new WebAssembly.Function({parameters:[], results:["i64"]}, _ => 0n); let table = new WebAssembly.Table({element: "anyfunc", initial: 2}); let table_index = builder.addImportedTable("m", "table", 2); let sig_index = builder.addType(kSig_l_v); @@ -593,14 +587,10 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ]) .exportFunc(); let instance = builder.instantiate({ m: { table: table }}); - assertThrows( - () => instance.exports.main(0), TypeError, - /wasm function signature contains illegal type/); + assertDoesNotThrow(() => instance.exports.main(0)); assertTraps(kTrapFuncSigMismatch, () => instance.exports.main(1)); table.set(1, fun); - assertThrows( - () => instance.exports.main(1), TypeError, - /wasm function signature contains illegal type/); + assertDoesNotThrow(() => instance.exports.main(1)); })(); (function TestFunctionModuleImportMatchingSig() { diff --git a/deps/v8/test/mjsunit/wasm/typed-funcref.js b/deps/v8/test/mjsunit/wasm/typed-funcref.js new file mode 100644 index 0000000000..b7e16d6bc9 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/typed-funcref.js @@ -0,0 +1,38 @@ +// Copyright 2020 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-typed-funcref + +load('test/mjsunit/wasm/wasm-module-builder.js'); + +// Export an arbitrary function from a Wasm module (identity). +let foo = (() => { + let builder = new WasmModuleBuilder(); + builder.addFunction('foo', kSig_i_i) + .addBody([kExprLocalGet, 0]) + .exportAs('foo'); + let module = new WebAssembly.Module(builder.toBuffer()); + return (new WebAssembly.Instance(builder.toModule())).exports.foo; +})(); + +(function TableGrowWithInitializer() { + print(arguments.callee.name); + var table = + new WebAssembly.Table({element: 'anyfunc', initial: 0, maximum: 100}); + + table.grow(10); + table.grow(10, foo); + table.grow(10, null); + table.grow(10, undefined); + + for (let i = 0; i < 10; i++) { + assertNull(table.get(i)); + } + for (let i = 10; i < 20; i++) { + assertEquals(foo, table.get(i)); + } + for (let i = 20; i < 40; i++) { + assertNull(table.get(i)); + } +})(); diff --git a/deps/v8/test/mjsunit/wasm/unicode-validation.js b/deps/v8/test/mjsunit/wasm/unicode-validation.js index e331c00a6a..83371db3df 100644 --- a/deps/v8/test/mjsunit/wasm/unicode-validation.js +++ b/deps/v8/test/mjsunit/wasm/unicode-validation.js @@ -51,7 +51,7 @@ function checkImportsAndExports(imported_module_name, imported_function_name, .addBody([kExprCallFunction, 0]) .exportAs(exported_function_name); - // sanity check: does javascript agree with out shouldThrow annotation? + // Consistency check: does javascript agree with our shouldThrow annotation? assertEquals(shouldThrow, !isValidUtf8(imported_module_name) || !isValidUtf8(imported_function_name) || diff --git a/deps/v8/test/mjsunit/wasm/unicode.js b/deps/v8/test/mjsunit/wasm/unicode.js index 73dc0608c6..618618de8a 100644 --- a/deps/v8/test/mjsunit/wasm/unicode.js +++ b/deps/v8/test/mjsunit/wasm/unicode.js @@ -19,7 +19,7 @@ function checkImport( assertEquals(imp(4), instance.exports.call_imp(4)); } -checkImport('mod', 'foo'); // sanity check +checkImport('mod', 'foo'); // Base check. checkImport('mod', '☺☺happy☺☺'); checkImport('☺☺happy☺☺', 'foo'); checkImport('☺☺happy☺☺', '☼+☃=☹'); @@ -42,7 +42,7 @@ function checkExports( assertEquals(-6, instance.exports[exported_name_mul](-3, 2)); } -checkExports('mul', 'mul', 'add', 'add'); // sanity check +checkExports('mul', 'mul', 'add', 'add'); // Base check. checkExports('☺☺mul☺☺', 'mul', '☺☺add☺☺', 'add'); checkExports('☺☺mul☺☺', '☺☺mul☺☺', '☺☺add☺☺', '☺☺add☺☺'); diff --git a/deps/v8/test/mjsunit/wasm/wasm-dynamic-tiering.js b/deps/v8/test/mjsunit/wasm/wasm-dynamic-tiering.js new file mode 100644 index 0000000000..b93df3ff9e --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/wasm-dynamic-tiering.js @@ -0,0 +1,38 @@ +// Copyright 2019 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-dynamic-tiering --liftoff +// Flags: --no-wasm-tier-up --no-stress-opt + +load('test/mjsunit/wasm/wasm-module-builder.js'); + +const num_iterations = 5; +const num_functions = 2; + +const builder = new WasmModuleBuilder(); +for (let i = 0; i < num_functions; ++i) { + let kFunction = builder.addFunction('f' + i, kSig_i_v) + .addBody(wasmI32Const(i)) + .exportAs('f' + i) +} + +let instance = builder.instantiate(); + +for (let i = 0; i < num_iterations - 1; ++i) { + instance.exports.f0(); + instance.exports.f1(); +} + +assertTrue(%IsLiftoffFunction(instance.exports.f0)); +assertTrue(%IsLiftoffFunction(instance.exports.f1)); + +instance.exports.f1(); + +// Busy waiting until the function is tiered up. +while (true) { + if (!%IsLiftoffFunction(instance.exports.f1)) { + break; + } +} +assertTrue(%IsLiftoffFunction(instance.exports.f0)); diff --git a/deps/v8/test/mjsunit/wasm/wasm-module-builder.js b/deps/v8/test/mjsunit/wasm/wasm-module-builder.js index fc6ce9724c..3c62ed9646 100644 --- a/deps/v8/test/mjsunit/wasm/wasm-module-builder.js +++ b/deps/v8/test/mjsunit/wasm/wasm-module-builder.js @@ -99,9 +99,8 @@ let kWasmI64 = 0x7e; let kWasmF32 = 0x7d; let kWasmF64 = 0x7c; let kWasmS128 = 0x7b; -let kWasmAnyRef = 0x6f; +let kWasmExternRef = 0x6f; let kWasmAnyFunc = 0x70; -let kWasmNullRef = 0x6e; let kWasmExnRef = 0x68; let kExternalFunction = 0; @@ -150,19 +149,21 @@ let kSig_v_f = makeSig([kWasmF32], []); let kSig_f_f = makeSig([kWasmF32], [kWasmF32]); let kSig_f_d = makeSig([kWasmF64], [kWasmF32]); let kSig_d_d = makeSig([kWasmF64], [kWasmF64]); -let kSig_r_r = makeSig([kWasmAnyRef], [kWasmAnyRef]); +let kSig_r_r = makeSig([kWasmExternRef], [kWasmExternRef]); let kSig_a_a = makeSig([kWasmAnyFunc], [kWasmAnyFunc]); let kSig_e_e = makeSig([kWasmExnRef], [kWasmExnRef]); -let kSig_i_r = makeSig([kWasmAnyRef], [kWasmI32]); -let kSig_v_r = makeSig([kWasmAnyRef], []); +let kSig_i_r = makeSig([kWasmExternRef], [kWasmI32]); +let kSig_v_r = makeSig([kWasmExternRef], []); let kSig_v_a = makeSig([kWasmAnyFunc], []); let kSig_v_e = makeSig([kWasmExnRef], []); -let kSig_v_rr = makeSig([kWasmAnyRef, kWasmAnyRef], []); +let kSig_v_rr = makeSig([kWasmExternRef, kWasmExternRef], []); let kSig_v_aa = makeSig([kWasmAnyFunc, kWasmAnyFunc], []); -let kSig_r_v = makeSig([], [kWasmAnyRef]); +let kSig_r_v = makeSig([], [kWasmExternRef]); let kSig_a_v = makeSig([], [kWasmAnyFunc]); let kSig_a_i = makeSig([kWasmI32], [kWasmAnyFunc]); let kSig_e_v = makeSig([], [kWasmExnRef]); +let kSig_s_i = makeSig([kWasmI32], [kWasmS128]); +let kSig_i_s = makeSig([kWasmS128], [kWasmI32]); function makeSig(params, results) { return {params: params, results: results}; @@ -209,6 +210,8 @@ let kExprCallFunction = 0x10; let kExprCallIndirect = 0x11; let kExprReturnCall = 0x12; let kExprReturnCallIndirect = 0x13; +let kExprCallRef = 0x14; +let kExprReturnCallRef = 0x15; let kExprDrop = 0x1a; let kExprSelect = 0x1b; let kExprSelectWithType = 0x1c; @@ -381,10 +384,15 @@ let kExprRefIsNull = 0xd1; let kExprRefFunc = 0xd2; // Prefix opcodes +let kGCPrefix = 0xfb; let kNumericPrefix = 0xfc; let kSimdPrefix = 0xfd; let kAtomicPrefix = 0xfe; +// GC opcodes +let kExprRttCanon = 0x30; +let kExprRefCast = 0x41; + // Numeric opcodes. let kExprMemoryInit = 0x08; let kExprDataDrop = 0x09; @@ -468,21 +476,176 @@ let kExprI64AtomicCompareExchange32U = 0x4e; // Simd opcodes. let kExprS128LoadMem = 0x00; +let kExprI16x8Load8x8S = 0x01; +let kExprI16x8Load8x8U = 0x02; +let kExprI32x4Load16x4S = 0x03; +let kExprI32x4Load16x4U = 0x04; +let kExprI64x2Load32x2S = 0x05; +let kExprI64x2Load32x2U = 0x06; +let kExprS8x16LoadSplat = 0x07; +let kExprS16x8LoadSplat = 0x08; +let kExprS32x4LoadSplat = 0x09; +let kExprS64x2LoadSplat = 0x0a; let kExprS128StoreMem = 0x0b; + +let kExprS128Const = 0x0c; let kExprS8x16Shuffle = 0x0d; + +let kExprS8x16Swizzle = 0x0e; let kExprI8x16Splat = 0x0f; let kExprI16x8Splat = 0x10; let kExprI32x4Splat = 0x11; +let kExprI64x2Splat = 0x12; let kExprF32x4Splat = 0x13; +let kExprF64x2Splat = 0x14; +let kExprI8x16ReplaceLane = 0x17; +let kExprI16x8ExtractLaneS = 0x18; +let kExprI16x8ReplaceLane = 0x1a; +let kExprI32x4ExtractLane = 0x1b; +let kExprI32x4ReplaceLane = 0x1c; +let kExprI64x2ReplaceLane = 0x1e; +let kExprF32x4ReplaceLane = 0x20; +let kExprF64x2ReplaceLane = 0x22; +let kExprI8x16Eq = 0x23; +let kExprI8x16Ne = 0x24; +let kExprI8x16LtS = 0x25; let kExprI8x16LtU = 0x26; +let kExprI8x16GtS = 0x27; +let kExprI8x16GtU = 0x28; +let kExprI8x16LeS = 0x29; let kExprI8x16LeU = 0x2a; +let kExprI8x16GeS = 0x2b; +let kExprI8x16GeU = 0x2c; +let kExprI16x8Eq = 0x2d; +let kExprI16x8Ne = 0x2e; +let kExprI16x8LtS = 0x2f; +let kExprI16x8LtU = 0x30; +let kExprI16x8GtS = 0x31; +let kExprI16x8GtU = 0x32; +let kExprI16x8LeS = 0x33; +let kExprI16x8LeU = 0x34; +let kExprI16x8GeS = 0x35; +let kExprI16x8GeU = 0x36; let kExprI32x4Eq = 0x37; -let kExprS1x16AnyTrue = 0x62; -let kExprS1x16AllTrue = 0x63; +let kExprI32x4Ne = 0x38; +let kExprI32x4LtS = 0x39; +let kExprI32x4LtU = 0x3a; +let kExprI32x4GtS = 0x3b; +let kExprI32x4GtU = 0x3c; +let kExprI32x4LeS = 0x3d; +let kExprI32x4LeU = 0x3e; +let kExprI32x4GeS = 0x3f; +let kExprI32x4GeU = 0x40; +let kExprF32x4Eq = 0x41; +let kExprF32x4Ne = 0x42; +let kExprF32x4Lt = 0x43; +let kExprF32x4Gt = 0x44; +let kExprF32x4Le = 0x45; +let kExprF32x4Ge = 0x46; +let kExprF64x2Eq = 0x47; +let kExprF64x2Ne = 0x48; +let kExprF64x2Lt = 0x49; +let kExprF64x2Gt = 0x4a; +let kExprF64x2Le = 0x4b; +let kExprF64x2Ge = 0x4c; +let kExprS128Not = 0x4d; +let kExprS128And = 0x4e; +let kExprS128AndNot = 0x4f; +let kExprS128Or = 0x50; +let kExprS128Xor = 0x51; +let kExprS128Select = 0x52; +let kExprI8x16Abs = 0x60; +let kExprI8x16Neg = 0x61; +let kExprV8x16AnyTrue = 0x62; +let kExprV8x16AllTrue = 0x63; +let kExprI8x16SConvertI16x8 = 0x65; +let kExprI8x16UConvertI16x8 = 0x66; +let kExprI8x16Shl = 0x6b; +let kExprI8x16ShrS = 0x6c; +let kExprI8x16ShrU = 0x6d; let kExprI8x16Add = 0x6e; -let kExprI16x8ShrS = [0x8c, 01]; -let kExprS1x4AnyTrue = 0xa2; +let kExprI8x16AddSaturateS = 0x6f; +let kExprI8x16AddSaturateU = 0x70; +let kExprI8x16Sub = 0x71; +let kExprI8x16SubSaturateS = 0x72; +let kExprI8x16SubSaturateU = 0x73; +let kExprI8x16MinS = 0x76; +let kExprI8x16MinU = 0x77; +let kExprI8x16MaxS = 0x78; +let kExprI8x16MaxU = 0x79; +let kExprI8x16RoundingAverageU = 0x7b; +let kExprI16x8Abs = 0x80; +let kExprI16x8Neg = 0x81; +let kExprV16x8AnyTrue = 0x82; +let kExprV16x8AllTrue = 0x83; +let kExprI16x8SConvertI32x4 = 0x85; +let kExprI16x8UConvertI32x4 = 0x86; +let kExprI16x8SConvertI8x16Low = 0x87; +let kExprI16x8SConvertI8x16High = 0x88; +let kExprI16x8UConvertI8x16Low = 0x89; +let kExprI16x8UConvertI8x16High = 0x8a; +let kExprI16x8Shl = 0x8b; +let kExprI16x8ShrS = 0x8c; +let kExprI16x8ShrU = 0x8d; +let kExprI16x8Add = 0x8e; +let kExprI16x8AddSaturateS = 0x8f; +let kExprI16x8AddSaturateU = 0x90; +let kExprI16x8Sub = 0x91; +let kExprI16x8SubSaturateS = 0x92; +let kExprI16x8SubSaturateU = 0x93; +let kExprI16x8Mul = 0x95; +let kExprI16x8MinS = 0x96; +let kExprI16x8MinU = 0x97; +let kExprI16x8MaxS = 0x98; +let kExprI16x8MaxU = 0x99; +let kExprI16x8RoundingAverageU = 0x9b; +let kExprI32x4Abs = 0xa0; +let kExprI32x4Neg = 0xa1; +let kExprV32x4AnyTrue = 0xa2; +let kExprV32x4AllTrue = 0xa3; +let kExprI32x4SConvertI16x8Low = 0xa7; +let kExprI32x4SConvertI16x8High = 0xa8; +let kExprI32x4UConvertI16x8Low = 0xa9; +let kExprI32x4UConvertI16x8High = 0xaa; +let kExprI32x4Shl = 0xab; +let kExprI32x4ShrS = 0xac; +let kExprI32x4ShrU = 0xad; +let kExprI32x4Add = 0xae; +let kExprI32x4Sub = 0xb1; +let kExprI32x4Mul = 0xb5; +let kExprI32x4MinS = 0xb6; +let kExprI32x4MinU = 0xb7; +let kExprI32x4MaxS = 0xb8; +let kExprI32x4MaxU = 0xb9; +let kExprI64x2Neg = 0xc1; +let kExprI64x2Shl = 0xcb; +let kExprI64x2ShrS = 0xcc; +let kExprI64x2ShrU = 0xcd; +let kExprI64x2Add = 0xce; +let kExprI64x2Sub = 0xd1; +let kExprI64x2Mul = 0xd5; +let kExprF32x4Abs = 0xe0; +let kExprF32x4Neg = 0xe1; +let kExprF32x4Sqrt = 0xe3; +let kExprF32x4Add = 0xe4; +let kExprF32x4Sub = 0xe5; +let kExprF32x4Mul = 0xe6; +let kExprF32x4Div = 0xe7; let kExprF32x4Min = 0xe8; +let kExprF32x4Max = 0xe9; +let kExprF64x2Abs = 0xec; +let kExprF64x2Neg = 0xed; +let kExprF64x2Sqrt = 0xef; +let kExprF64x2Add = 0xf0; +let kExprF64x2Sub = 0xf1; +let kExprF64x2Mul = 0xf2; +let kExprF64x2Div = 0xf3; +let kExprF64x2Min = 0xf4; +let kExprF64x2Max = 0xf5; +let kExprI32x4SConvertF32x4 = 0xf8; +let kExprI32x4UConvertF32x4 = 0xf9; +let kExprF32x4SConvertI32x4 = 0xfa; +let kExprF32x4UConvertI32x4 = 0xfb; // Compilation hint constants. let kCompilationHintStrategyDefault = 0x00; @@ -506,8 +669,8 @@ let kTrapUnalignedAccess = 9; let kTrapDataSegmentDropped = 10; let kTrapElemSegmentDropped = 11; let kTrapTableOutOfBounds = 12; -let kTrapBrOnExnNullRef = 13; -let kTrapRethrowNullRef = 14; +let kTrapBrOnExnNull = 13; +let kTrapRethrowNull = 14; let kTrapMsgs = [ "unreachable", @@ -523,8 +686,8 @@ let kTrapMsgs = [ "data segment has been dropped", "element segment has been dropped", "table access out of bounds", - "br_on_exn on nullref value", - "rethrowing nullref value" + "br_on_exn on null value", + "rethrowing null value" ]; function assertTraps(trap, code) { @@ -817,9 +980,9 @@ class WasmModuleBuilder { } addTable(type, initial_size, max_size = undefined) { - if (type != kWasmAnyRef && type != kWasmAnyFunc && type != kWasmNullRef && type != kWasmExnRef) { + if (type != kWasmExternRef && type != kWasmAnyFunc && type != kWasmExnRef) { throw new Error( - 'Tables must be of type kWasmAnyRef, kWasmAnyFunc, kWasmNullRef or kWasmExnRef'); + 'Tables must be of type kWasmExternRef, kWasmAnyFunc or kWasmExnRef'); } let table = new WasmTableBuilder(this, type, initial_size, max_size); table.index = this.tables.length + this.num_imported_tables; @@ -1117,27 +1280,31 @@ class WasmModuleBuilder { section.emit_u64v(global.init); break; case kWasmF32: - section.emit_u8(kExprF32Const); - data_view.setFloat32(0, global.init, true); - section.emit_bytes(byte_view.subarray(0, 4)); + section.emit_bytes(wasmF32Const(global.init)); break; case kWasmF64: - section.emit_u8(kExprF64Const); - data_view.setFloat64(0, global.init, true); - section.emit_bytes(byte_view); + section.emit_bytes(wasmF64Const(global.init)); + break; + case kWasmS128: + section.emit_bytes(wasmS128Const(global.init)); + break; + case kWasmExternRef: + section.emit_u8(kExprRefNull); + section.emit_u8(kWasmExternRef); + assertEquals(global.function_index, undefined); break; case kWasmAnyFunc: - case kWasmAnyRef: - case kWasmNullRef: if (global.function_index !== undefined) { section.emit_u8(kExprRefFunc); section.emit_u32v(global.function_index); } else { section.emit_u8(kExprRefNull); + section.emit_u8(kWasmAnyFunc); } break; case kWasmExnRef: section.emit_u8(kExprRefNull); + section.emit_u8(kWasmExnRef); break; } } else { @@ -1227,6 +1394,7 @@ class WasmModuleBuilder { for (let index of init.array) { if (index === null) { section.emit_u8(kExprRefNull); + section.emit_u8(kWasmAnyFunc); section.emit_u8(kExprEnd); } else { section.emit_u8(kExprRefFunc); @@ -1308,15 +1476,12 @@ class WasmModuleBuilder { if (l.s128_count > 0) { local_decls.push({count: l.s128_count, type: kWasmS128}); } - if (l.anyref_count > 0) { - local_decls.push({count: l.anyref_count, type: kWasmAnyRef}); + if (l.externref_count > 0) { + local_decls.push({count: l.externref_count, type: kWasmExternRef}); } if (l.anyfunc_count > 0) { local_decls.push({count: l.anyfunc_count, type: kWasmAnyFunc}); } - if (l.nullref_count > 0) { - local_decls.push({count: l.nullref_count, type: kWasmNullRef}); - } if (l.except_count > 0) { local_decls.push({count: l.except_count, type: kWasmExnRef}); } @@ -1481,3 +1646,8 @@ function wasmF64Const(f) { byte_view[3], byte_view[4], byte_view[5], byte_view[6], byte_view[7] ]; } + +function wasmS128Const(f) { + // Write in little-endian order at offset 0. + return [kSimdPrefix, kExprS128Const, ...f]; +} |