| 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   408  |   408  | 
|   409 assertEquals(7, _WASMEXP_.instantiateModuleFromAsm( |   409 assertEquals(7, _WASMEXP_.instantiateModuleFromAsm( | 
|   410       TestInt32HeapAccess.toString()).caller()); |   410       TestInt32HeapAccess.toString()).caller()); | 
|   411  |   411  | 
|   412  |   412  | 
|   413 function TestInt32HeapAccessExternal() { |   413 function TestInt32HeapAccessExternal() { | 
|   414   var memory = new ArrayBuffer(1024); |   414   var memory = new ArrayBuffer(1024); | 
|   415   var memory_int32 = new Int32Array(memory); |   415   var memory_int32 = new Int32Array(memory); | 
|   416   var module = _WASMEXP_.instantiateModuleFromAsm( |   416   var module = _WASMEXP_.instantiateModuleFromAsm( | 
|   417       TestInt32HeapAccess.toString(), null, memory); |   417       TestInt32HeapAccess.toString(), null, memory); | 
|   418   module.__init__(); |  | 
|   419   assertEquals(7, module.caller()); |   418   assertEquals(7, module.caller()); | 
|   420   assertEquals(7, memory_int32[2]); |   419   assertEquals(7, memory_int32[2]); | 
|   421 } |   420 } | 
|   422  |   421  | 
|   423 TestInt32HeapAccessExternal(); |   422 TestInt32HeapAccessExternal(); | 
|   424  |   423  | 
|   425  |   424  | 
|   426 function TestHeapAccessIntTypes() { |   425 function TestHeapAccessIntTypes() { | 
|   427   var types = [ |   426   var types = [ | 
|   428     [Int8Array, 'Int8Array', '>> 0'], |   427     [Int8Array, 'Int8Array', '>> 0'], | 
|   429     [Uint8Array, 'Uint8Array', '>> 0'], |   428     [Uint8Array, 'Uint8Array', '>> 0'], | 
|   430     [Int16Array, 'Int16Array', '>> 1'], |   429     [Int16Array, 'Int16Array', '>> 1'], | 
|   431     [Uint16Array, 'Uint16Array', '>> 1'], |   430     [Uint16Array, 'Uint16Array', '>> 1'], | 
|   432     [Int32Array, 'Int32Array', '>> 2'], |   431     [Int32Array, 'Int32Array', '>> 2'], | 
|   433     [Uint32Array, 'Uint32Array', '>> 2'], |   432     [Uint32Array, 'Uint32Array', '>> 2'], | 
|   434   ]; |   433   ]; | 
|   435   for (var i = 0; i < types.length; i++) { |   434   for (var i = 0; i < types.length; i++) { | 
|   436     var code = TestInt32HeapAccess.toString(); |   435     var code = TestInt32HeapAccess.toString(); | 
|   437     code = code.replace('Int32Array', types[i][1]); |   436     code = code.replace('Int32Array', types[i][1]); | 
|   438     code = code.replace(/>> 2/g, types[i][2]); |   437     code = code.replace(/>> 2/g, types[i][2]); | 
|   439     var memory = new ArrayBuffer(1024); |   438     var memory = new ArrayBuffer(1024); | 
|   440     var memory_view = new types[i][0](memory); |   439     var memory_view = new types[i][0](memory); | 
|   441     var module = _WASMEXP_.instantiateModuleFromAsm(code, null, memory); |   440     var module = _WASMEXP_.instantiateModuleFromAsm(code, null, memory); | 
|   442     module.__init__(); |  | 
|   443     assertEquals(7, module.caller()); |   441     assertEquals(7, module.caller()); | 
|   444     assertEquals(7, memory_view[2]); |   442     assertEquals(7, memory_view[2]); | 
|   445     assertEquals(7, _WASMEXP_.instantiateModuleFromAsm(code).caller()); |   443     assertEquals(7, _WASMEXP_.instantiateModuleFromAsm(code).caller()); | 
|   446   } |   444   } | 
|   447 } |   445 } | 
|   448  |   446  | 
|   449 TestHeapAccessIntTypes(); |   447 TestHeapAccessIntTypes(); | 
|   450  |   448  | 
|   451  |   449  | 
|   452 function TestFloatHeapAccess(stdlib, foreign, buffer) { |   450 function TestFloatHeapAccess(stdlib, foreign, buffer) { | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|   473  |   471  | 
|   474 assertEquals(1, _WASMEXP_.instantiateModuleFromAsm( |   472 assertEquals(1, _WASMEXP_.instantiateModuleFromAsm( | 
|   475       TestFloatHeapAccess.toString()).caller()); |   473       TestFloatHeapAccess.toString()).caller()); | 
|   476  |   474  | 
|   477  |   475  | 
|   478 function TestFloatHeapAccessExternal() { |   476 function TestFloatHeapAccessExternal() { | 
|   479   var memory = new ArrayBuffer(1024); |   477   var memory = new ArrayBuffer(1024); | 
|   480   var memory_float64 = new Float64Array(memory); |   478   var memory_float64 = new Float64Array(memory); | 
|   481   var module = _WASMEXP_.instantiateModuleFromAsm( |   479   var module = _WASMEXP_.instantiateModuleFromAsm( | 
|   482       TestFloatHeapAccess.toString(), null, memory); |   480       TestFloatHeapAccess.toString(), null, memory); | 
|   483   module.__init__(); |  | 
|   484   assertEquals(1, module.caller()); |   481   assertEquals(1, module.caller()); | 
|   485   assertEquals(9.0, memory_float64[1]); |   482   assertEquals(9.0, memory_float64[1]); | 
|   486 } |   483 } | 
|   487  |   484  | 
|   488 TestFloatHeapAccessExternal(); |   485 TestFloatHeapAccessExternal(); | 
|   489  |   486  | 
|   490  |   487  | 
|   491 function TestConvertI32() { |   488 function TestConvertI32() { | 
|   492   "use asm"; |   489   "use asm"; | 
|   493  |   490  | 
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   649   var b = 34.25; |   646   var b = 34.25; | 
|   650  |   647  | 
|   651   function add() { |   648   function add() { | 
|   652     return +(a + b); |   649     return +(a + b); | 
|   653   } |   650   } | 
|   654  |   651  | 
|   655   return {add:add}; |   652   return {add:add}; | 
|   656 } |   653 } | 
|   657  |   654  | 
|   658 var module = _WASMEXP_.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); |   655 var module = _WASMEXP_.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); | 
|   659 module.__init__(); |  | 
|   660 assertEquals(77.5, module.add()); |   656 assertEquals(77.5, module.add()); | 
|   661  |   657  | 
|   662  |   658  | 
|   663 function TestForLoop() { |   659 function TestForLoop() { | 
|   664   "use asm" |   660   "use asm" | 
|   665  |   661  | 
|   666   function caller() { |   662   function caller() { | 
|   667     var ret = 0; |   663     var ret = 0; | 
|   668     var i = 0; |   664     var i = 0; | 
|   669     for (i = 2; i <= 10; i = (i+1)|0) { |   665     for (i = 2; i <= 10; i = (i+1)|0) { | 
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   872 function TestInitFunctionWithNoGlobals() { |   868 function TestInitFunctionWithNoGlobals() { | 
|   873   "use asm"; |   869   "use asm"; | 
|   874   function caller() { |   870   function caller() { | 
|   875     return 51; |   871     return 51; | 
|   876   } |   872   } | 
|   877   return {caller}; |   873   return {caller}; | 
|   878 } |   874 } | 
|   879  |   875  | 
|   880 var module = _WASMEXP_.instantiateModuleFromAsm( |   876 var module = _WASMEXP_.instantiateModuleFromAsm( | 
|   881     TestInitFunctionWithNoGlobals.toString()); |   877     TestInitFunctionWithNoGlobals.toString()); | 
|   882 module.__init__(); |  | 
|   883 assertEquals(51, module.caller()); |   878 assertEquals(51, module.caller()); | 
|   884  |   879  | 
|   885  |   880  | 
|   886 function TestExportNameDifferentFromFunctionName() { |   881 function TestExportNameDifferentFromFunctionName() { | 
|   887   "use asm"; |   882   "use asm"; | 
|   888   function caller() { |   883   function caller() { | 
|   889     return 55; |   884     return 55; | 
|   890   } |   885   } | 
|   891   return {alt_caller:caller}; |   886   return {alt_caller:caller}; | 
|   892 } |   887 } | 
|   893  |   888  | 
|   894 var module = _WASMEXP_.instantiateModuleFromAsm( |   889 var module = _WASMEXP_.instantiateModuleFromAsm( | 
|   895     TestExportNameDifferentFromFunctionName.toString()); |   890     TestExportNameDifferentFromFunctionName.toString()); | 
|   896 module.__init__(); |  | 
|   897 assertEquals(55, module.alt_caller()); |   891 assertEquals(55, module.alt_caller()); | 
|   898  |   892  | 
|   899  |   893  | 
|   900 function TestFunctionTableSingleFunction() { |   894 function TestFunctionTableSingleFunction() { | 
|   901   "use asm"; |   895   "use asm"; | 
|   902  |   896  | 
|   903   function dummy() { |   897   function dummy() { | 
|   904     return 71; |   898     return 71; | 
|   905   } |   899   } | 
|   906  |   900  | 
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   981     return 0; |   975     return 0; | 
|   982   } |   976   } | 
|   983  |   977  | 
|   984   var funBin = [add, sub, sub, add]; |   978   var funBin = [add, sub, sub, add]; | 
|   985   var fun = [inc]; |   979   var fun = [inc]; | 
|   986  |   980  | 
|   987   return {caller:caller}; |   981   return {caller:caller}; | 
|   988 } |   982 } | 
|   989  |   983  | 
|   990 var module = _WASMEXP_.instantiateModuleFromAsm(TestFunctionTable.toString()); |   984 var module = _WASMEXP_.instantiateModuleFromAsm(TestFunctionTable.toString()); | 
|   991 module.__init__(); |  | 
|   992 assertEquals(55, module.caller(0, 0, 33, 22)); |   985 assertEquals(55, module.caller(0, 0, 33, 22)); | 
|   993 assertEquals(11, module.caller(0, 1, 33, 22)); |   986 assertEquals(11, module.caller(0, 1, 33, 22)); | 
|   994 assertEquals(9, module.caller(0, 2, 54, 45)); |   987 assertEquals(9, module.caller(0, 2, 54, 45)); | 
|   995 assertEquals(99, module.caller(0, 3, 54, 45)); |   988 assertEquals(99, module.caller(0, 3, 54, 45)); | 
|   996 assertEquals(23, module.caller(0, 4, 12, 11)); |   989 assertEquals(23, module.caller(0, 4, 12, 11)); | 
|   997 assertEquals(31, module.caller(1, 0, 30, 11)); |   990 assertEquals(31, module.caller(1, 0, 30, 11)); | 
|   998  |   991  | 
|   999  |   992  | 
|  1000 function TestForeignFunctions() { |   993 function TestForeignFunctions() { | 
|  1001   function AsmModule(stdlib, foreign, buffer) { |   994   function AsmModule(stdlib, foreign, buffer) { | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|  1029     } |  1022     } | 
|  1030  |  1023  | 
|  1031     return {getVal:getVal, setVal:setVal}; |  1024     return {getVal:getVal, setVal:setVal}; | 
|  1032   } |  1025   } | 
|  1033  |  1026  | 
|  1034   var foreign = new ffi(23); |  1027   var foreign = new ffi(23); | 
|  1035  |  1028  | 
|  1036   var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), |  1029   var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), | 
|  1037                                                   foreign, null); |  1030                                                   foreign, null); | 
|  1038  |  1031  | 
|  1039   module.__init__(); |  | 
|  1040   assertEquals(103, module.caller(23, 103)); |  1032   assertEquals(103, module.caller(23, 103)); | 
|  1041 } |  1033 } | 
|  1042  |  1034  | 
|  1043 TestForeignFunctions(); |  1035 TestForeignFunctions(); | 
|  1044  |  1036  | 
|  1045  |  1037  | 
|  1046 function TestForeignFunctionMultipleUse() { |  1038 function TestForeignFunctionMultipleUse() { | 
|  1047   function AsmModule(stdlib, foreign, buffer) { |  1039   function AsmModule(stdlib, foreign, buffer) { | 
|  1048     "use asm"; |  1040     "use asm"; | 
|  1049  |  1041  | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  1069     } |  1061     } | 
|  1070  |  1062  | 
|  1071     return {getVal:getVal}; |  1063     return {getVal:getVal}; | 
|  1072   } |  1064   } | 
|  1073  |  1065  | 
|  1074   var foreign = new ffi(); |  1066   var foreign = new ffi(); | 
|  1075  |  1067  | 
|  1076   var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), |  1068   var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), | 
|  1077                                                   foreign, null); |  1069                                                   foreign, null); | 
|  1078  |  1070  | 
|  1079   module.__init__(); |  | 
|  1080   assertEquals(89, module.caller(83, 83.25)); |  1071   assertEquals(89, module.caller(83, 83.25)); | 
|  1081 } |  1072 } | 
|  1082  |  1073  | 
|  1083 TestForeignFunctionMultipleUse(); |  1074 TestForeignFunctionMultipleUse(); | 
|  1084  |  1075  | 
|  1085  |  1076  | 
|  1086 function TestForeignVariables() { |  1077 function TestForeignVariables() { | 
|  1087   function AsmModule(stdlib, foreign, buffer) { |  1078   function AsmModule(stdlib, foreign, buffer) { | 
|  1088     "use asm"; |  1079     "use asm"; | 
|  1089  |  1080  | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
|  1107     function getf2() { |  1098     function getf2() { | 
|  1108       return +f2; |  1099       return +f2; | 
|  1109     } |  1100     } | 
|  1110  |  1101  | 
|  1111     return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2}; |  1102     return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2}; | 
|  1112   } |  1103   } | 
|  1113  |  1104  | 
|  1114   function TestCase(env, i1, f1, i2, f2) { |  1105   function TestCase(env, i1, f1, i2, f2) { | 
|  1115     var module = _WASMEXP_.instantiateModuleFromAsm( |  1106     var module = _WASMEXP_.instantiateModuleFromAsm( | 
|  1116         AsmModule.toString(), env); |  1107         AsmModule.toString(), env); | 
|  1117     module.__init__(); |  | 
|  1118     assertEquals(i1, module.geti1()); |  1108     assertEquals(i1, module.geti1()); | 
|  1119     assertEquals(f1, module.getf1()); |  1109     assertEquals(f1, module.getf1()); | 
|  1120     assertEquals(i2, module.geti2()); |  1110     assertEquals(i2, module.geti2()); | 
|  1121     assertEquals(f2, module.getf2()); |  1111     assertEquals(f2, module.getf2()); | 
|  1122   } |  1112   } | 
|  1123  |  1113  | 
|  1124   // Check normal operation. |  1114   // Check normal operation. | 
|  1125   TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7); |  1115   TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7); | 
|  1126   // Check partial operation. |  1116   // Check partial operation. | 
|  1127   TestCase({baz: 345.7}, 0, NaN, 345, 345.7); |  1117   TestCase({baz: 345.7}, 0, NaN, 345, 345.7); | 
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1230  |  1220  | 
|  1231     function test() { |  1221     function test() { | 
|  1232       return (x + y) | 0; |  1222       return (x + y) | 0; | 
|  1233     } |  1223     } | 
|  1234  |  1224  | 
|  1235     return {test: test}; |  1225     return {test: test}; | 
|  1236   } |  1226   } | 
|  1237  |  1227  | 
|  1238   var m = _WASMEXP_.instantiateModuleFromAsm( |  1228   var m = _WASMEXP_.instantiateModuleFromAsm( | 
|  1239       Module.toString(), { x: 4, y: 11 }); |  1229       Module.toString(), { x: 4, y: 11 }); | 
|  1240   m.__init__(); |  | 
|  1241   assertEquals(15, m.test()); |  1230   assertEquals(15, m.test()); | 
|  1242 })(); |  1231 })(); | 
|  1243  |  1232  | 
|  1244  |  1233  | 
|  1245 (function TestComma() { |  1234 (function TestComma() { | 
|  1246   function CommaModule() { |  1235   function CommaModule() { | 
|  1247     "use asm"; |  1236     "use asm"; | 
|  1248  |  1237  | 
|  1249     function ifunc(a, b) { |  1238     function ifunc(a, b) { | 
|  1250       a = +a; |  1239       a = +a; | 
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1548       var a = 0; |  1537       var a = 0; | 
|  1549       f = 5616315000.000001; |  1538       f = 5616315000.000001; | 
|  1550       a = ~~f >>>0; |  1539       a = ~~f >>>0; | 
|  1551       return a | 0; |  1540       return a | 0; | 
|  1552     } |  1541     } | 
|  1553     return { main : aaa }; |  1542     return { main : aaa }; | 
|  1554   } |  1543   } | 
|  1555   var wasm = _WASMEXP_.instantiateModuleFromAsm(asmModule.toString()); |  1544   var wasm = _WASMEXP_.instantiateModuleFromAsm(asmModule.toString()); | 
|  1556   assertEquals(1321347704, wasm.main()); |  1545   assertEquals(1321347704, wasm.main()); | 
|  1557 })(); |  1546 })(); | 
| OLD | NEW |