Chromium Code Reviews| Index: test/mjsunit/wasm/asm-wasm.js |
| diff --git a/test/mjsunit/wasm/asm-wasm.js b/test/mjsunit/wasm/asm-wasm.js |
| index a1feea3b2bbeeddff6f5b83fd0951af24f2888a8..03c7dcda062ab3bc1ed40c0cf39f8d9b40547131 100644 |
| --- a/test/mjsunit/wasm/asm-wasm.js |
| +++ b/test/mjsunit/wasm/asm-wasm.js |
| @@ -858,3 +858,71 @@ var module = _WASMEXP_.instantiateModuleFromAsm( |
| TestExportNameDifferentFromFunctionName.toString()); |
| module.__init__(); |
| assertEquals(55, module.alt_caller()); |
| + |
| + |
| +function TestFunctionTableSimple() { |
| + "use asm"; |
| + |
| + function dummy() { |
| + return 71; |
| + } |
| + |
| + function caller() { |
| + return function_table[0&0]() | 0; |
| + } |
| + |
| + var function_table = [dummy] |
| + |
| + return {caller:caller}; |
| +} |
| + |
| +assertEquals(71, _WASMEXP_.asmCompileRun(TestFunctionTableSimple.toString())); |
| + |
| + |
| +function TestFunctionTable() { |
| + "use asm"; |
| + |
| + function add(a, b) { |
| + a = a|0; |
| + b = b|0; |
| + return (a+b)|0; |
| + } |
| + |
| + function sub(a, b) { |
| + a = a|0; |
| + b = b|0; |
| + return (a-b)|0; |
| + } |
| + |
| + function inc(a) { |
| + a = a|0; |
| + return (a+1)|0; |
| + } |
| + |
| + function caller(table_id, fun_id, arg1, arg2) { |
| + table_id = table_id|0; |
| + fun_id = fun_id|0; |
| + arg1 = arg1|0; |
| + arg2 = arg2|0; |
| + if (table_id == 0) { |
| + return funBin[fun_id&3](arg1, arg2)|0; |
|
bradnelson
2016/01/20 00:40:52
Given the parser eats constant function indexes an
aseemgarg
2016/01/20 00:56:09
Added that above TestFunctionTableSimple
bradnelson
2016/01/20 00:57:01
Doh, missed the test above, though actually might
|
| + } else if (table_id == 1) { |
| + return fun[fun_id&0](arg1)|0; |
| + } |
| + return 0; |
| + } |
| + |
| + var funBin = [add, sub, sub, add]; |
| + var fun = [inc]; |
| + |
| + return {caller:caller}; |
| +} |
| + |
| +var module = _WASMEXP_.instantiateModuleFromAsm(TestFunctionTable.toString()); |
| +module.__init__(); |
| +assertEquals(55, module.caller(0, 0, 33, 22)); |
| +assertEquals(11, module.caller(0, 1, 33, 22)); |
| +assertEquals(9, module.caller(0, 2, 54, 45)); |
| +assertEquals(99, module.caller(0, 3, 54, 45)); |
| +assertEquals(23, module.caller(0, 4, 12, 11)); |
| +assertEquals(31, module.caller(1, 0, 30, 11)); |