OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 function EmptyTest() { | 7 function EmptyTest() { |
8 "use asm"; | 8 "use asm"; |
9 function caller() { | 9 function caller() { |
10 empty(); | 10 empty(); |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 function caller() { | 851 function caller() { |
852 return 55; | 852 return 55; |
853 } | 853 } |
854 return {alt_caller:caller}; | 854 return {alt_caller:caller}; |
855 } | 855 } |
856 | 856 |
857 var module = _WASMEXP_.instantiateModuleFromAsm( | 857 var module = _WASMEXP_.instantiateModuleFromAsm( |
858 TestExportNameDifferentFromFunctionName.toString()); | 858 TestExportNameDifferentFromFunctionName.toString()); |
859 module.__init__(); | 859 module.__init__(); |
860 assertEquals(55, module.alt_caller()); | 860 assertEquals(55, module.alt_caller()); |
| 861 |
| 862 |
| 863 function TestFunctionTable() { |
| 864 "use asm"; |
| 865 |
| 866 function add(a, b) { |
| 867 a = a|0; |
| 868 b = b|0; |
| 869 return (a+b)|0; |
| 870 } |
| 871 |
| 872 function sub(a, b) { |
| 873 a = a|0; |
| 874 b = b|0; |
| 875 return (a-b)|0; |
| 876 } |
| 877 |
| 878 function inc(a) { |
| 879 a = a|0; |
| 880 return (a+1)|0; |
| 881 } |
| 882 |
| 883 function caller(table_id, fun_id, arg1, arg2) { |
| 884 table_id = table_id|0; |
| 885 fun_id = fun_id|0; |
| 886 arg1 = arg1|0; |
| 887 arg2 = arg2|0; |
| 888 if (table_id == 0) { |
| 889 return funBin[fun_id&3](arg1, arg2)|0; |
| 890 } else if (table_id == 1) { |
| 891 return fun[fun_id&0](arg1)|0; |
| 892 } |
| 893 return 0; |
| 894 } |
| 895 |
| 896 var funBin = [add, sub, sub, add]; |
| 897 var fun = [inc]; |
| 898 |
| 899 return {caller:caller}; |
| 900 } |
| 901 |
| 902 var module = _WASMEXP_.instantiateModuleFromAsm(TestFunctionTable.toString()); |
| 903 module.__init__(); |
| 904 assertEquals(55, module.caller(0, 0, 33, 22)); |
| 905 assertEquals(11, module.caller(0, 1, 33, 22)); |
| 906 assertEquals(9, module.caller(0, 2, 54, 45)); |
| 907 assertEquals(99, module.caller(0, 3, 54, 45)); |
| 908 assertEquals(23, module.caller(0, 4, 12, 11)); |
| 909 assertEquals(31, module.caller(1, 0, 30, 11)); |
OLD | NEW |