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: --validate-asm --allow-natives-syntax | 5 // Flags: --validate-asm --allow-natives-syntax |
6 | 6 |
7 var stdlib = this; | 7 var stdlib = this; |
8 | 8 |
9 function assertValidAsm(func) { | 9 function assertValidAsm(func) { |
10 assertTrue(%IsAsmWasmCode(func)); | 10 assertTrue(%IsAsmWasmCode(func)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 function Float64Test() { | 71 function Float64Test() { |
72 "use asm"; | 72 "use asm"; |
73 function sum(a, b) { | 73 function sum(a, b) { |
74 a = +a; | 74 a = +a; |
75 b = +b; | 75 b = +b; |
76 return +(a + b); | 76 return +(a + b); |
77 } | 77 } |
78 | 78 |
79 function caller() { | 79 function caller() { |
80 var a = 0.0; | 80 var a = 0.0; |
81 var ret = 0|0; | 81 var ret = 0; |
82 a = +sum(70.1,10.2); | 82 a = +sum(70.1,10.2); |
83 if (a == 80.3) { | 83 if (a == 80.3) { |
84 ret = 1|0; | 84 ret = 1|0; |
85 } else { | 85 } else { |
86 ret = 0|0; | 86 ret = 0|0; |
87 } | 87 } |
88 return ret|0; | 88 return ret|0; |
89 } | 89 } |
90 | 90 |
91 return {caller: caller}; | 91 return {caller: caller}; |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 409 |
410 assertWasm(20, TestContinueInNamedWhile); | 410 assertWasm(20, TestContinueInNamedWhile); |
411 | 411 |
412 | 412 |
413 function TestContinueInDoWhileFalse() { | 413 function TestContinueInDoWhileFalse() { |
414 "use asm"; | 414 "use asm"; |
415 | 415 |
416 function caller() { | 416 function caller() { |
417 do { | 417 do { |
418 continue; | 418 continue; |
419 } while (false); | 419 } while (0); |
420 return 47; | 420 return 47; |
421 } | 421 } |
422 | 422 |
423 return {caller: caller}; | 423 return {caller: caller}; |
424 } | 424 } |
425 | 425 |
426 assertWasm(47, TestContinueInDoWhileFalse); | 426 assertWasm(47, TestContinueInDoWhileFalse); |
427 | 427 |
428 | 428 |
429 function TestNot() { | 429 function TestNot() { |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 } | 882 } |
883 | 883 |
884 assertWasm(41, TestConditional); | 884 assertWasm(41, TestConditional); |
885 | 885 |
886 | 886 |
887 function TestInitFunctionWithNoGlobals() { | 887 function TestInitFunctionWithNoGlobals() { |
888 "use asm"; | 888 "use asm"; |
889 function caller() { | 889 function caller() { |
890 return 51; | 890 return 51; |
891 } | 891 } |
892 return {caller}; | 892 return {caller:caller}; |
893 } | 893 } |
894 | 894 |
895 assertWasm(51, TestInitFunctionWithNoGlobals); | 895 assertWasm(51, TestInitFunctionWithNoGlobals); |
896 | 896 |
897 | 897 |
898 (function () { | 898 (function () { |
899 function TestExportNameDifferentFromFunctionName() { | 899 function TestExportNameDifferentFromFunctionName() { |
900 "use asm"; | 900 "use asm"; |
901 function caller() { | 901 function caller() { |
902 return 55; | 902 return 55; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 var module_decl = eval('(' + AsmModule.toString() + ')'); | 1094 var module_decl = eval('(' + AsmModule.toString() + ')'); |
1095 var module = module_decl(stdlib, foreign, null); | 1095 var module = module_decl(stdlib, foreign, null); |
1096 assertValidAsm(module_decl); | 1096 assertValidAsm(module_decl); |
1097 | 1097 |
1098 assertEquals(89, module.caller(83, 83.25)); | 1098 assertEquals(89, module.caller(83, 83.25)); |
1099 } | 1099 } |
1100 | 1100 |
1101 print("TestForeignFunctionMultipleUse..."); | 1101 print("TestForeignFunctionMultipleUse..."); |
1102 TestForeignFunctionMultipleUse(); | 1102 TestForeignFunctionMultipleUse(); |
1103 | 1103 |
1104 | |
1105 function TestForeignVariables() { | 1104 function TestForeignVariables() { |
1106 function AsmModule(stdlib, foreign, buffer) { | 1105 function AsmModule(stdlib, foreign, buffer) { |
1107 "use asm"; | 1106 "use asm"; |
1108 | 1107 |
1109 var i1 = foreign.foo | 0; | 1108 var i1 = foreign.foo | 0; |
1110 var f1 = +foreign.bar; | 1109 var f1 = +foreign.bar; |
1111 var i2 = foreign.baz | 0; | 1110 var i2 = foreign.baz | 0; |
1112 var f2 = +foreign.baz; | 1111 var f2 = +foreign.baz; |
1113 | 1112 |
1114 function geti1() { | 1113 function geti1() { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 } | 1466 } |
1468 return {caller: func}; | 1467 return {caller: func}; |
1469 } | 1468 } |
1470 | 1469 |
1471 assertWasm(3, TestAndNegative); | 1470 assertWasm(3, TestAndNegative); |
1472 | 1471 |
1473 | 1472 |
1474 function TestNegativeDouble() { | 1473 function TestNegativeDouble() { |
1475 "use asm"; | 1474 "use asm"; |
1476 function func() { | 1475 function func() { |
1477 var x = -(34359738368.25); | 1476 var x = -34359738368.25; |
1478 var y = -2.5; | 1477 var y = -2.5; |
1479 return +(x + y); | 1478 return +(x + y); |
1480 } | 1479 } |
1481 return {caller: func}; | 1480 return {caller: func}; |
1482 } | 1481 } |
1483 | 1482 |
1484 assertWasm(-34359738370.75, TestNegativeDouble); | 1483 assertWasm(-34359738370.75, TestNegativeDouble); |
1485 | 1484 |
1486 | 1485 |
1487 (function TestBadAndDouble() { | 1486 (function TestBadAndDouble() { |
(...skipping 18 matching lines...) Expand all Loading... |
1506 function func() { | 1505 function func() { |
1507 } | 1506 } |
1508 return {123: func}; | 1507 return {123: func}; |
1509 } | 1508 } |
1510 | 1509 |
1511 Module(stdlib); | 1510 Module(stdlib); |
1512 assertFalse(%IsAsmWasmCode(Module)); | 1511 assertFalse(%IsAsmWasmCode(Module)); |
1513 })(); | 1512 })(); |
1514 | 1513 |
1515 | 1514 |
| 1515 /* |
| 1516 // TODO(bradnelson): Technically invalid, but useful to cover unicode, revises |
| 1517 // and re-enable. |
1516 (function TestUnicodeExportKey() { | 1518 (function TestUnicodeExportKey() { |
1517 function Module() { | 1519 function Module() { |
1518 "use asm"; | 1520 "use asm"; |
1519 function func() { | 1521 function func() { |
1520 return 42; | 1522 return 42; |
1521 } | 1523 } |
1522 return {"\u00d1\u00e6": func}; | 1524 return {"\u00d1\u00e6": func}; |
1523 } | 1525 } |
1524 | 1526 |
1525 var m = Module(stdlib); | 1527 var m = Module(stdlib); |
1526 assertEquals(42, m.Ñæ()); | 1528 assertEquals(42, m.Ñæ()); |
1527 assertValidAsm(Module); | 1529 assertValidAsm(Module); |
1528 })(); | 1530 })(); |
| 1531 */ |
1529 | 1532 |
1530 | 1533 |
1531 function TestAndIntAndHeapValue(stdlib, foreign, buffer) { | 1534 function TestAndIntAndHeapValue(stdlib, foreign, buffer) { |
1532 "use asm"; | 1535 "use asm"; |
1533 var HEAP32 = new stdlib.Int32Array(buffer); | 1536 var HEAP32 = new stdlib.Int32Array(buffer); |
1534 function func() { | 1537 function func() { |
1535 var x = 0; | 1538 var x = 0; |
1536 x = HEAP32[0] & -1; | 1539 x = HEAP32[0] & -1; |
1537 return x | 0; | 1540 return x | 0; |
1538 } | 1541 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 "use asm"; | 1755 "use asm"; |
1753 function foo() { | 1756 function foo() { |
1754 return 42; | 1757 return 42; |
1755 } | 1758 } |
1756 return {bar: foo, baz: foo}; | 1759 return {bar: foo, baz: foo}; |
1757 } | 1760 } |
1758 var m = asmModule(); | 1761 var m = asmModule(); |
1759 assertEquals(42, m.bar()); | 1762 assertEquals(42, m.bar()); |
1760 assertEquals(42, m.baz()); | 1763 assertEquals(42, m.baz()); |
1761 })(); | 1764 })(); |
OLD | NEW |