Chromium Code Reviews| 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 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 var foreign = new ffi(); | 1073 var foreign = new ffi(); |
| 1074 | 1074 |
| 1075 var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), | 1075 var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), |
| 1076 foreign, null); | 1076 foreign, null); |
| 1077 | 1077 |
| 1078 module.__init__(); | 1078 module.__init__(); |
| 1079 assertEquals(89, module.caller(83, 83.25)); | 1079 assertEquals(89, module.caller(83, 83.25)); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 TestForeignFunctionMultipleUse(); | 1082 TestForeignFunctionMultipleUse(); |
| 1083 | |
| 1084 | |
| 1085 function TestForeignVariables() { | |
|
aseemgarg
2016/02/09 02:38:56
Might want to also write test that uses same forei
bradnelson
2016/02/09 04:55:23
Done.
| |
| 1086 function AsmModule(stdlib, foreign, buffer) { | |
| 1087 "use asm"; | |
| 1088 | |
| 1089 var i1 = foreign.foo | 0; | |
| 1090 var f1 = +foreign.bar; | |
| 1091 | |
| 1092 function geti() { | |
| 1093 return i1|0; | |
| 1094 } | |
| 1095 | |
| 1096 function getf() { | |
| 1097 return +f1; | |
| 1098 } | |
| 1099 | |
| 1100 return {geti:geti, getf:getf}; | |
| 1101 } | |
| 1102 | |
| 1103 // Check normal operation. | |
| 1104 var module = _WASMEXP_.instantiateModuleFromAsm( | |
| 1105 AsmModule.toString(), {foo: 123, bar: 234}, null); | |
| 1106 module.__init__(); | |
| 1107 assertEquals(123, module.geti()); | |
| 1108 assertEquals(234, module.getf()); | |
| 1109 | |
| 1110 // Check that undefined values are converted to zero. | |
|
aseemgarg
2016/02/09 02:38:56
As discussed, doubles should flow as NaNs. Please
bradnelson
2016/02/09 04:55:23
Done.
| |
| 1111 var module = _WASMEXP_.instantiateModuleFromAsm( | |
| 1112 AsmModule.toString(), {baz: 678}, null); | |
| 1113 module.__init__(); | |
| 1114 assertEquals(0, module.geti()); | |
| 1115 assertEquals(0, module.getf()); | |
| 1116 | |
| 1117 // Check that a missing ffi object is safe. | |
| 1118 var module = _WASMEXP_.instantiateModuleFromAsm( | |
| 1119 AsmModule.toString()); | |
| 1120 module.__init__(); | |
| 1121 assertEquals(0, module.geti()); | |
| 1122 assertEquals(0, module.getf()); | |
| 1123 } | |
| 1124 | |
| 1125 TestForeignVariables(); | |
| OLD | NEW |