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 TestFunctionTableSingleFunction() { |
| 864 "use asm"; |
| 865 |
| 866 function dummy() { |
| 867 return 71; |
| 868 } |
| 869 |
| 870 function caller() { |
| 871 return function_table[0&0]() | 0; |
| 872 } |
| 873 |
| 874 var function_table = [dummy] |
| 875 |
| 876 return {caller:caller}; |
| 877 } |
| 878 |
| 879 assertEquals(71, |
| 880 _WASMEXP_.asmCompileRun(TestFunctionTableSingleFunction.toString())); |
| 881 |
| 882 |
| 883 function TestFunctionTableMultipleFunctions() { |
| 884 "use asm"; |
| 885 |
| 886 function inc1(x) { |
| 887 x = x|0; |
| 888 return (x+1)|0; |
| 889 } |
| 890 |
| 891 function inc2(x) { |
| 892 x = x|0; |
| 893 return (x+2)|0; |
| 894 } |
| 895 |
| 896 function caller() { |
| 897 if (function_table[0&1](50) == 51) { |
| 898 if (function_table[1&1](60) == 62) { |
| 899 return 73; |
| 900 } |
| 901 } |
| 902 return 0; |
| 903 } |
| 904 |
| 905 var function_table = [inc1, inc2] |
| 906 |
| 907 return {caller:caller}; |
| 908 } |
| 909 |
| 910 assertEquals(73, |
| 911 _WASMEXP_.asmCompileRun(TestFunctionTableMultipleFunctions.toString())); |
| 912 |
| 913 |
| 914 function TestFunctionTable() { |
| 915 "use asm"; |
| 916 |
| 917 function add(a, b) { |
| 918 a = a|0; |
| 919 b = b|0; |
| 920 return (a+b)|0; |
| 921 } |
| 922 |
| 923 function sub(a, b) { |
| 924 a = a|0; |
| 925 b = b|0; |
| 926 return (a-b)|0; |
| 927 } |
| 928 |
| 929 function inc(a) { |
| 930 a = a|0; |
| 931 return (a+1)|0; |
| 932 } |
| 933 |
| 934 function caller(table_id, fun_id, arg1, arg2) { |
| 935 table_id = table_id|0; |
| 936 fun_id = fun_id|0; |
| 937 arg1 = arg1|0; |
| 938 arg2 = arg2|0; |
| 939 if (table_id == 0) { |
| 940 return funBin[fun_id&3](arg1, arg2)|0; |
| 941 } else if (table_id == 1) { |
| 942 return fun[fun_id&0](arg1)|0; |
| 943 } |
| 944 return 0; |
| 945 } |
| 946 |
| 947 var funBin = [add, sub, sub, add]; |
| 948 var fun = [inc]; |
| 949 |
| 950 return {caller:caller}; |
| 951 } |
| 952 |
| 953 var module = _WASMEXP_.instantiateModuleFromAsm(TestFunctionTable.toString()); |
| 954 module.__init__(); |
| 955 assertEquals(55, module.caller(0, 0, 33, 22)); |
| 956 assertEquals(11, module.caller(0, 1, 33, 22)); |
| 957 assertEquals(9, module.caller(0, 2, 54, 45)); |
| 958 assertEquals(99, module.caller(0, 3, 54, 45)); |
| 959 assertEquals(23, module.caller(0, 4, 12, 11)); |
| 960 assertEquals(31, module.caller(1, 0, 30, 11)); |
OLD | NEW |