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 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 } | 988 } |
989 | 989 |
990 var module = _WASMEXP_.instantiateModuleFromAsm(TestFunctionTable.toString()); | 990 var module = _WASMEXP_.instantiateModuleFromAsm(TestFunctionTable.toString()); |
991 module.__init__(); | 991 module.__init__(); |
992 assertEquals(55, module.caller(0, 0, 33, 22)); | 992 assertEquals(55, module.caller(0, 0, 33, 22)); |
993 assertEquals(11, module.caller(0, 1, 33, 22)); | 993 assertEquals(11, module.caller(0, 1, 33, 22)); |
994 assertEquals(9, module.caller(0, 2, 54, 45)); | 994 assertEquals(9, module.caller(0, 2, 54, 45)); |
995 assertEquals(99, module.caller(0, 3, 54, 45)); | 995 assertEquals(99, module.caller(0, 3, 54, 45)); |
996 assertEquals(23, module.caller(0, 4, 12, 11)); | 996 assertEquals(23, module.caller(0, 4, 12, 11)); |
997 assertEquals(31, module.caller(1, 0, 30, 11)); | 997 assertEquals(31, module.caller(1, 0, 30, 11)); |
| 998 |
| 999 |
| 1000 function TestForeignFunctions() { |
| 1001 function AsmModule(stdlib, foreign, buffer) { |
| 1002 "use asm"; |
| 1003 |
| 1004 var setVal = foreign.setVal; |
| 1005 var getVal = foreign.getVal; |
| 1006 |
| 1007 function caller(initial_value, new_value) { |
| 1008 initial_value = initial_value|0; |
| 1009 new_value = new_value|0; |
| 1010 if ((getVal()|0) == (initial_value|0)) { |
| 1011 setVal(new_value|0); |
| 1012 return getVal()|0; |
| 1013 } |
| 1014 return 0; |
| 1015 } |
| 1016 |
| 1017 return {caller:caller}; |
| 1018 } |
| 1019 |
| 1020 function ffi(initial_val) { |
| 1021 var val = initial_val; |
| 1022 |
| 1023 function getVal() { |
| 1024 return val; |
| 1025 } |
| 1026 |
| 1027 function setVal(new_val) { |
| 1028 val = new_val; |
| 1029 } |
| 1030 |
| 1031 return {getVal:getVal, setVal:setVal}; |
| 1032 } |
| 1033 |
| 1034 var foreign = new ffi(23); |
| 1035 |
| 1036 var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), |
| 1037 foreign, null); |
| 1038 |
| 1039 module.__init__(); |
| 1040 assertEquals(103, module.caller(23, 103)); |
| 1041 } |
| 1042 |
| 1043 TestForeignFunctions(); |
| 1044 |
| 1045 function TestForeignFunctionMultipleUse() { |
| 1046 function AsmModule(stdlib, foreign, buffer) { |
| 1047 "use asm"; |
| 1048 |
| 1049 var getVal = foreign.getVal; |
| 1050 |
| 1051 function caller(int_val, double_val) { |
| 1052 int_val = int_val|0; |
| 1053 double_val = +double_val; |
| 1054 if ((getVal()|0) == (int_val|0)) { |
| 1055 if ((+getVal()) == (+double_val)) { |
| 1056 return 89; |
| 1057 } |
| 1058 } |
| 1059 return 0; |
| 1060 } |
| 1061 |
| 1062 return {caller:caller}; |
| 1063 } |
| 1064 |
| 1065 function ffi() { |
| 1066 function getVal() { |
| 1067 return 83.25; |
| 1068 } |
| 1069 |
| 1070 return {getVal:getVal}; |
| 1071 } |
| 1072 |
| 1073 var foreign = new ffi(); |
| 1074 |
| 1075 var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), |
| 1076 foreign, null); |
| 1077 |
| 1078 module.__init__(); |
| 1079 assertEquals(89, module.caller(83, 83.25)); |
| 1080 } |
| 1081 |
| 1082 TestForeignFunctionMultipleUse(); |
OLD | NEW |