Commit 7a08b033 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Test {WebAssembly.Function} in non-zero tables.

This adds a test case for using constructed {WebAssembly.Function}
objects in non-zero tables. Due to a recent refactoring that unifies
handling of dispatch tables, this works out of the box. The test
coverage however is still useful, since code paths are slightly
different for non-zero tables.

R=ahaas@chromium.org
TEST=mjsunit/wasm/type-reflection-with-anyref
BUG=v8:7742

Change-Id: I0cf4b0a8039bbef0422b06ee23744a949be8f1b1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1690821
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62555}
parent bcdf2e2a
......@@ -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));
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment