Chromium Code Reviews| Index: test/mjsunit/wasm/indirect-tables.js |
| diff --git a/test/mjsunit/wasm/indirect-tables.js b/test/mjsunit/wasm/indirect-tables.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9992f30a548a98cbf2e70d2651b2b551874e74de |
| --- /dev/null |
| +++ b/test/mjsunit/wasm/indirect-tables.js |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2016 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: --expose-wasm |
| + |
| +load("test/mjsunit/wasm/wasm-constants.js"); |
| +load("test/mjsunit/wasm/wasm-module-builder.js"); |
| + |
| +function AddFunctions(builder) { |
| + var mul = builder.addFunction("mul", kSig_i_ii) |
| + .addBody([ |
| + kExprGetLocal, 0, // -- |
| + kExprGetLocal, 1, // -- |
| + kExprI32Mul // -- |
| + ]); |
| + var add = builder.addFunction("add", kSig_i_ii) |
| + .addBody([ |
| + kExprGetLocal, 0, // -- |
| + kExprGetLocal, 1, // -- |
| + kExprI32Add // -- |
| + ]); |
| + var sub = builder.addFunction("sub", kSig_i_ii) |
| + .addBody([ |
| + kExprGetLocal, 0, // -- |
| + kExprGetLocal, 1, // -- |
| + kExprI32Sub // -- |
| + ]); |
| + return {mul: mul, add: add, sub: sub}; |
| +} |
| + |
| +(function ExportedTableTest() { |
| + print("ExportedTableTest..."); |
| + |
| + let builder = new WasmModuleBuilder(); |
| + |
| + let f = AddFunctions(builder); |
| + builder.addFunction("main", kSig_i_ii) |
| + .addBody([ |
| + kExprI32Const, 33, // -- |
| + kExprGetLocal, 0, // -- |
| + kExprGetLocal, 1, // -- |
| + kExprCallIndirect, 0]) // -- |
| + .exportAs("main"); |
| + |
| + f.add.exportAs("add"); |
| + |
| + builder.setFunctionTableLength(10); |
| + let g = builder.addImportedGlobal("base", undefined, kAstI32); |
| + builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, f.sub.index]); |
|
bradnelson
2016/10/25 07:33:39
>80
titzer
2016/10/25 08:27:37
Done.
|
| + builder.addExportOfKind("table", kExternalTable, 0); |
| + |
| + let module = new WebAssembly.Module(builder.toBuffer()); |
|
bradnelson
2016/10/25 07:33:39
What about a case for imports into a different mod
titzer
2016/10/25 08:27:37
Add a case for adding an imported function to the
|
| + |
| + for (let i = 0; i < 5; i++) { |
| + print(" base = " + i); |
| + let instance = new WebAssembly.Instance(module, {base: i}); |
| + main = instance.exports.main; |
| + let table = instance.exports.table; |
| + assertTrue(table instanceof WebAssembly.Table); |
| + assertEquals(10, table.length); |
| + for (let j = 0; j < i; j++) { |
| + assertSame(null, table.get(j)); |
| + } |
| + let mul = table.get(i+0); |
| + let add = table.get(i+1); |
| + let sub = table.get(i+2); |
| + |
| + print(" mul=" + mul); |
| + print(" add=" + add); |
| + print(" sub=" + sub); |
| + assertEquals("function", typeof mul); |
| + assertEquals("function", typeof add); |
| + assertEquals("function", typeof sub); |
| + assertEquals(2, mul.length); |
| + assertEquals(2, add.length); |
| + assertEquals(2, sub.length); |
| + |
| + assertEquals("add", add.name); |
|
bradnelson
2016/10/25 07:33:39
Do we maybe want to have export names that don't m
titzer
2016/10/25 08:27:37
Done.
|
| + |
| + for (let j = i + 3; j < 10; j++) { |
| + assertSame(null, table.get(j)); |
| + } |
| + |
| + assertEquals(-33, mul(-11, 3)); |
| + assertEquals(4444444, add(3333333, 1111111)); |
| + assertEquals(-9999, sub(1, 10000)); |
| + } |
| +})(); |