aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js')
-rw-r--r--deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js b/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js
index adaf8e7185..0b857fb42f 100644
--- a/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js
+++ b/deps/v8/test/mjsunit/wasm/type-reflection-with-anyref.js
@@ -34,3 +34,48 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals(false, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
})();
+
+// This is an extension of "type-reflection.js/TestFunctionTableSetAndCall" to
+// multiple table indexes. If --experimental-wasm-anyref is enabled by default
+// this test case can supersede the other one.
+(function TestFunctionMultiTableSetAndCall() {
+ let builder = new WasmModuleBuilder();
+ let v1 = 7; let v2 = 9; let v3 = 0.0;
+ let f1 = new WebAssembly.Function({parameters:[], results:["i32"]}, _ => v1);
+ let f2 = new WebAssembly.Function({parameters:[], results:["i32"]}, _ => v2);
+ let f3 = new WebAssembly.Function({parameters:[], results:["f64"]}, _ => v3);
+ let table = new WebAssembly.Table({element: "anyfunc", initial: 2});
+ let table_index0 = builder.addImportedTable("m", "table", 2);
+ let table_index1 = builder.addTable(kWasmAnyFunc, 1).exportAs("tbl").index;
+ let sig_index = builder.addType(kSig_i_v);
+ table.set(0, f1);
+ builder.addFunction('call0', kSig_i_i)
+ .addBody([
+ kExprGetLocal, 0,
+ kExprCallIndirect, sig_index, table_index0
+ ])
+ .exportFunc();
+ builder.addFunction('call1', kSig_i_i)
+ .addBody([
+ kExprGetLocal, 0,
+ kExprCallIndirect, sig_index, table_index1
+ ])
+ .exportFunc();
+ let instance = builder.instantiate({ m: { table: table }});
+
+ // Test table #0 first.
+ assertEquals(v1, instance.exports.call0(0));
+ table.set(1, f2);
+ assertEquals(v2, instance.exports.call0(1));
+ table.set(1, f3);
+ assertTraps(kTrapFuncSigMismatch, () => instance.exports.call0(1));
+
+ // Test table #1 next.
+ assertTraps(kTrapFuncSigMismatch, () => instance.exports.call1(0));
+ instance.exports.tbl.set(0, f1);
+ assertEquals(v1, instance.exports.call1(0));
+ instance.exports.tbl.set(0, f2);
+ assertEquals(v2, instance.exports.call1(0));
+ instance.exports.tbl.set(0, f3);
+ assertTraps(kTrapFuncSigMismatch, () => instance.exports.call1(0));
+})();