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(stdlib, foreign, buffer) { | |
1001 "use asm"; | |
1002 | |
1003 var setVal = foreign.setVal; | |
1004 var getVal = foreign.getVal; | |
1005 | |
1006 function caller(initial_value, new_value) { | |
1007 initial_value = initial_value|0; | |
1008 new_value = new_value|0; | |
1009 if ((getVal()|0) == (initial_value|0)) { | |
1010 setVal(new_value|0); | |
1011 return getVal()|0; | |
1012 } | |
1013 return 0; | |
1014 } | |
1015 | |
1016 return {caller:caller}; | |
1017 } | |
1018 | |
1019 function ffi(initial_val) { | |
1020 var val = initial_val; | |
1021 | |
1022 function getVal() { | |
1023 return val; | |
1024 } | |
1025 | |
1026 function setVal(new_val) { | |
1027 val = new_val; | |
1028 } | |
1029 | |
1030 return {getVal:getVal, setVal:setVal}; | |
1031 } | |
1032 | |
1033 var foreign = new ffi(23); | |
1034 | |
1035 var module = _WASMEXP_.instantiateModuleFromAsm(TestForeignFunctions.toString(), | |
1036 foreign, null); | |
1037 | |
1038 module.__init__(); | |
1039 assertEquals(103, module.caller(23, 103)); | |
1040 | |
1041 | |
1042 function TestForeignFunctionMultipleUse(stdlib, foreign, buffer) { | |
1043 "use asm"; | |
1044 | |
1045 var getVal = foreign.getVal; | |
1046 | |
1047 function caller(int_val, double_val) { | |
1048 int_val = int_val|0; | |
1049 double_val = +double_val; | |
1050 if ((getVal()|0) == (int_val|0)) { | |
1051 if ((+getVal()) == (+double_val)) { | |
1052 return 89; | |
1053 } | |
1054 } | |
1055 return 0; | |
1056 } | |
1057 | |
1058 return {caller:caller}; | |
1059 } | |
1060 | |
1061 function ffii() { | |
aseemgarg
2016/02/05 01:00:01
If I change the name of this to ffi, the test abov
bradnelson
2016/02/05 01:19:43
Javascript resolves scoping after parsing everythi
aseemgarg
2016/02/05 01:33:18
Done. enclosed in a function
| |
1062 function getVal() { | |
1063 return 83.25; | |
1064 } | |
1065 | |
1066 return {getVal:getVal}; | |
1067 } | |
1068 | |
1069 var foreign = new ffii(); | |
1070 | |
1071 var module = _WASMEXP_.instantiateModuleFromAsm( | |
1072 TestForeignFunctionMultipleUse.toString(), foreign, null); | |
1073 | |
1074 module.__init__(); | |
1075 assertEquals(89, module.caller(83, 83.25)); | |
OLD | NEW |