diff options
Diffstat (limited to 'deps/v8/test/mjsunit/wasm/anyfunc.js')
-rw-r--r-- | deps/v8/test/mjsunit/wasm/anyfunc.js | 101 |
1 files changed, 74 insertions, 27 deletions
diff --git a/deps/v8/test/mjsunit/wasm/anyfunc.js b/deps/v8/test/mjsunit/wasm/anyfunc.js index 19415fe2b8..f0d587b25a 100644 --- a/deps/v8/test/mjsunit/wasm/anyfunc.js +++ b/deps/v8/test/mjsunit/wasm/anyfunc.js @@ -4,7 +4,7 @@ // Flags: --expose-wasm --experimental-wasm-anyref --expose-gc -load("test/mjsunit/wasm/wasm-module-builder.js"); +load('test/mjsunit/wasm/wasm-module-builder.js'); (function testAnyFuncIdentityFunction() { print(arguments.callee.name); @@ -13,11 +13,10 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); .addBody([kExprGetLocal, 0]) .exportFunc(); - const instance = builder.instantiate(); assertThrows(() => instance.exports.main(print), TypeError); - assertThrows(() => instance.exports.main({'hello' : 'world'}), TypeError); + assertThrows(() => instance.exports.main({'hello': 'world'}), TypeError); assertSame( instance.exports.main, instance.exports.main(instance.exports.main)); })(); @@ -26,10 +25,9 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); print(arguments.callee.name); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_v_a); - const imp_index = builder.addImport("q", "func", sig_index); + const imp_index = builder.addImport('q', 'func', sig_index); builder.addFunction('main', sig_index) - .addBody([kExprGetLocal, 0, - kExprCallFunction, imp_index]) + .addBody([kExprGetLocal, 0, kExprCallFunction, imp_index]) .exportFunc(); const main = builder.instantiate({q: {func: checkFunction}}).exports.main; @@ -46,24 +44,35 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); const builder = new WasmModuleBuilder(); const ref_sig = builder.addType(kSig_v_a); const void_sig = builder.addType(kSig_v_v); - const imp_index = builder.addImport("q", "func", ref_sig); - const gc_index = builder.addImport("q", "gc", void_sig); + const imp_index = builder.addImport('q', 'func', ref_sig); + 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({anyfunc_count: 10}) .addBody([ - kExprGetLocal, 0, kExprSetLocal, 1, // Set local - kExprGetLocal, 0, kExprSetLocal, 2, // Set local - kExprGetLocal, 0, kExprSetLocal, 3, // Set local - kExprGetLocal, 0, kExprSetLocal, 4, // Set local - kExprGetLocal, 0, kExprSetLocal, 5, // Set local - kExprGetLocal, 0, kExprSetLocal, 6, // Set local - kExprGetLocal, 0, kExprSetLocal, 7, // Set local - kExprGetLocal, 0, kExprSetLocal, 8, // Set local - kExprGetLocal, 0, kExprSetLocal, 9, // Set local - kExprGetLocal, 0, kExprSetLocal, 10, // Set local - kExprCallFunction, gc_index, // call gc - kExprGetLocal, 9, kExprCallFunction, imp_index // call import + kExprGetLocal, 0, + kExprSetLocal, 1, // Set local + kExprGetLocal, 0, + kExprSetLocal, 2, // Set local + kExprGetLocal, 0, + kExprSetLocal, 3, // Set local + kExprGetLocal, 0, + kExprSetLocal, 4, // Set local + kExprGetLocal, 0, + kExprSetLocal, 5, // Set local + kExprGetLocal, 0, + kExprSetLocal, 6, // Set local + kExprGetLocal, 0, + kExprSetLocal, 7, // Set local + kExprGetLocal, 0, + kExprSetLocal, 8, // Set local + kExprGetLocal, 0, + kExprSetLocal, 9, // Set local + kExprGetLocal, 0, + kExprSetLocal, 10, // Set local + kExprCallFunction, gc_index, // call gc + kExprGetLocal, 9, + kExprCallFunction, imp_index // call import ]) .exportFunc(); @@ -82,8 +91,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); const builder = new WasmModuleBuilder(); const ref_sig = builder.addType(kSig_v_a); const void_sig = builder.addType(kSig_v_v); - const imp_index = builder.addImport("q", "func", ref_sig); - const gc_index = builder.addImport("q", "gc", void_sig); + const imp_index = builder.addImport('q', 'func', ref_sig); + 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) .addBody([ @@ -96,7 +105,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertSame(main, value); } - const main = builder.instantiate({q: {func: checkFunction, gc: gc}}).exports.main; + const main = + builder.instantiate({q: {func: checkFunction, gc: gc}}).exports.main; main(main); })(); @@ -104,7 +114,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); (function testPassAnyFuncWithGCInWrapper() { print(arguments.callee.name); const builder = new WasmModuleBuilder(); - const kSig_a_iai = makeSig([kWasmI32, kWasmAnyFunc, kWasmI32], [kWasmAnyFunc]); + const kSig_a_iai = + makeSig([kWasmI32, kWasmAnyFunc, kWasmI32], [kWasmAnyFunc]); const sig_index = builder.addType(kSig_a_iai); builder.addFunction('main', sig_index) .addBody([kExprGetLocal, 1]) @@ -152,9 +163,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); print(arguments.callee.name); const builder = new WasmModuleBuilder(); const sig_index = builder.addType(kSig_a_v); - builder.addFunction('main', sig_index) - .addBody([kExprRefNull]) - .exportFunc(); + builder.addFunction('main', sig_index).addBody([kExprRefNull]).exportFunc(); const main = builder.instantiate().exports.main; assertEquals(null, main()); @@ -197,3 +206,41 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); const main = builder.instantiate().exports.main; assertEquals(null, main()); })(); + +(function testRefFuncOutOfBounds() { + print(arguments.callee.name); + const builder = new WasmModuleBuilder(); + builder.addFunction('main', kSig_a_v).addBody([kExprRefFunc, 10]); + + assertThrows(() => builder.toModule(), WebAssembly.CompileError); +})(); + +(function testRefFuncIsCallable() { + print(arguments.callee.name); + const expected = 54; + const builder = new WasmModuleBuilder(); + const function_index = builder.addFunction('hidden', kSig_i_v) + .addBody([kExprI32Const, expected]) + .index; + builder.addFunction('main', kSig_a_v) + .addBody([kExprRefFunc, function_index]) + .exportFunc(); + + const instance = builder.instantiate(); + assertEquals(expected, instance.exports.main()()); +})(); + +(function testRefFuncPreservesIdentity() { + print(arguments.callee.name); + const expected = 54; + const builder = new WasmModuleBuilder(); + const foo = builder.addFunction('foo', kSig_i_v) + .addBody([kExprI32Const, expected]) + .exportFunc(); + builder.addFunction('main', kSig_a_v) + .addBody([kExprRefFunc, foo.index]) + .exportFunc(); + + const instance = builder.instantiate(); + assertSame(instance.exports.foo, instance.exports.main()); +})(); |