diff options
Diffstat (limited to 'deps/v8/test/mjsunit/wasm/interpreter.js')
-rw-r--r-- | deps/v8/test/mjsunit/wasm/interpreter.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/deps/v8/test/mjsunit/wasm/interpreter.js b/deps/v8/test/mjsunit/wasm/interpreter.js index 0f54dc97d3..f5697eb00f 100644 --- a/deps/v8/test/mjsunit/wasm/interpreter.js +++ b/deps/v8/test/mjsunit/wasm/interpreter.js @@ -22,6 +22,7 @@ function checkStack(stack, expected_lines) { } (function testCallImported() { + print(arguments.callee.name); var stack; let func = () => stack = new Error('test imported stack').stack; @@ -47,6 +48,7 @@ function checkStack(stack, expected_lines) { })(); (function testCallImportedWithParameters() { + print(arguments.callee.name); var stack; var passed_args = []; let func1 = (i, j) => (passed_args.push(i, j), 2 * i + j); @@ -80,6 +82,7 @@ function checkStack(stack, expected_lines) { })(); (function testTrap() { + print(arguments.callee.name); var builder = new WasmModuleBuilder(); var foo_idx = builder.addFunction('foo', kSig_v_v) .addBody([kExprNop, kExprNop, kExprUnreachable]) @@ -110,6 +113,7 @@ function checkStack(stack, expected_lines) { })(); (function testThrowFromImport() { + print(arguments.callee.name); function func() { throw new Error('thrown from imported function'); } @@ -141,6 +145,7 @@ function checkStack(stack, expected_lines) { })(); (function testGlobals() { + print(arguments.callee.name); var builder = new WasmModuleBuilder(); builder.addGlobal(kWasmI32, true); // 0 builder.addGlobal(kWasmI64, true); // 1 @@ -190,6 +195,7 @@ function checkStack(stack, expected_lines) { })(); (function testReentrantInterpreter() { + print(arguments.callee.name); var stacks; var instance; function func(i) { @@ -227,6 +233,7 @@ function checkStack(stack, expected_lines) { })(); (function testIndirectImports() { + print(arguments.callee.name); var builder = new WasmModuleBuilder(); var sig_i_ii = builder.addType(kSig_i_ii); @@ -260,6 +267,7 @@ function checkStack(stack, expected_lines) { })(); (function testIllegalImports() { + print(arguments.callee.name); var builder = new WasmModuleBuilder(); var sig_l_v = builder.addType(kSig_l_v); @@ -311,6 +319,7 @@ function checkStack(stack, expected_lines) { })(); (function testInfiniteRecursion() { + print(arguments.callee.name); var builder = new WasmModuleBuilder(); var direct = builder.addFunction('main', kSig_v_v) @@ -331,6 +340,7 @@ function checkStack(stack, expected_lines) { })(); (function testUnwindSingleActivation() { + print(arguments.callee.name); // Create two activations and unwind just the top one. var builder = new WasmModuleBuilder(); @@ -367,6 +377,7 @@ function checkStack(stack, expected_lines) { })(); (function testInterpreterGC() { + print(arguments.callee.name); function run(f) { // wrap the creation in a closure so that the only thing returned is // the module (i.e. the underlying array buffer of wasm wire bytes dies). @@ -398,3 +409,87 @@ function checkStack(stack, expected_lines) { run(x => (x - 18)); } })(); + +(function testImportThrowsOnToNumber() { + print(arguments.callee.name); + const builder = new WasmModuleBuilder(); + const imp_idx = builder.addImport('mod', 'func', kSig_i_v); + builder.addFunction('main', kSig_i_v) + .addBody([kExprCallFunction, imp_idx]) + .exportFunc(); + var num_callback_calls = 0; + const callback = () => { + ++num_callback_calls; + return Symbol() + }; + var instance = builder.instantiate({mod: {func: callback}}); + // Test that this does not mess up internal state by executing it three times. + for (var i = 0; i < 3; ++i) { + var interpreted_before = %WasmNumInterpretedCalls(instance); + assertThrows( + () => instance.exports.main(), TypeError, + 'Cannot convert a Symbol value to a number'); + assertEquals(interpreted_before + 1, %WasmNumInterpretedCalls(instance)); + assertEquals(i + 1, num_callback_calls); + } +})(); + +(function testCallWithMoreReturnsThenParams() { + print(arguments.callee.name); + const builder1 = new WasmModuleBuilder(); + builder1.addFunction('exp', kSig_l_v) + .addBody([kExprI64Const, 23]) + .exportFunc(); + const exp = builder1.instantiate().exports.exp; + const builder2 = new WasmModuleBuilder(); + const imp_idx = builder2.addImport('imp', 'func', kSig_l_v); + builder2.addFunction('main', kSig_i_v) + .addBody([kExprCallFunction, imp_idx, kExprI32ConvertI64]) + .exportFunc(); + const instance = builder2.instantiate({imp: {func: exp}}); + assertEquals(23, instance.exports.main()); +})(); + +(function testTableCall() { + print(arguments.callee.name); + const builder1 = new WasmModuleBuilder(); + builder1.addFunction('func', kSig_v_v).addBody([]).exportFunc(); + const instance1 = builder1.instantiate(); + const table = new WebAssembly.Table({element: 'anyfunc', initial: 2}); + + const builder2 = new WasmModuleBuilder() + builder2.addImportedTable('m', 'table'); + const sig = builder2.addType(kSig_v_v); + builder2.addFunction('call_func', kSig_v_v) + .addBody([kExprI32Const, 0, kExprCallIndirect, sig, kTableZero]) + .exportFunc(); + const instance2 = builder2.instantiate({m: {table: table}}); + table.set(0, instance1.exports.func); + instance2.exports.call_func(); +})(); + +(function testTableCall2() { + // See crbug.com/787910. + print(arguments.callee.name); + const builder1 = new WasmModuleBuilder(); + builder1.addFunction('exp', kSig_i_i) + .addBody([kExprI32Const, 0]) + .exportFunc(); + const instance1 = builder1.instantiate(); + const builder2 = new WasmModuleBuilder(); + const sig1 = builder2.addType(kSig_i_v); + const sig2 = builder2.addType(kSig_i_i); + builder2.addFunction('call2', kSig_i_v) + .addBody([ + kExprI32Const, 0, kExprI32Const, 0, kExprCallIndirect, sig2, kTableZero + ]) + .exportAs('call2'); + builder2.addImportedTable('imp', 'table'); + const tab = new WebAssembly.Table({ + element: 'anyfunc', + initial: 3, + }); + const instance2 = builder2.instantiate({imp: {table: tab}}); + tab.set(0, instance1.exports.exp); + instance2.exports.call2(); +})(); |