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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return (a + c + 1)|0; | 104 return (a + c + 1)|0; |
105 } | 105 } |
106 | 106 |
107 function caller() { | 107 function caller() { |
108 return call(1, 2)|0; | 108 return call(1, 2)|0; |
109 } | 109 } |
110 | 110 |
111 return {caller: caller}; | 111 return {caller: caller}; |
112 } | 112 } |
113 | 113 |
114 assertTrue(%IsNotAsmWasmCode(BadModule)); | 114 assertFalse(%IsAsmWasmCode(BadModule)); |
115 | 115 |
116 | 116 |
117 function TestReturnInBlock() { | 117 function TestReturnInBlock() { |
118 "use asm"; | 118 "use asm"; |
119 | 119 |
120 function caller() { | 120 function caller() { |
121 if(1) { | 121 if(1) { |
122 { | 122 { |
123 { | 123 { |
124 return 1; | 124 return 1; |
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 "use asm"; | 1383 "use asm"; |
1384 function func() { | 1384 function func() { |
1385 var a = 1; | 1385 var a = 1; |
1386 var b = 3.0; | 1386 var b = 3.0; |
1387 b = a; | 1387 b = a; |
1388 } | 1388 } |
1389 return {func: func}; | 1389 return {func: func}; |
1390 } | 1390 } |
1391 print("TestBadAssignDoubleFromIntish..."); | 1391 print("TestBadAssignDoubleFromIntish..."); |
1392 Module(stdlib); | 1392 Module(stdlib); |
1393 assertTrue(%IsNotAsmWasmCode(Module)); | 1393 assertFalse(%IsAsmWasmCode(Module)); |
1394 })(); | 1394 })(); |
1395 | 1395 |
1396 | 1396 |
1397 (function TestBadAssignIntFromDouble() { | 1397 (function TestBadAssignIntFromDouble() { |
1398 function Module(stdlib, foreign, heap) { | 1398 function Module(stdlib, foreign, heap) { |
1399 "use asm"; | 1399 "use asm"; |
1400 function func() { | 1400 function func() { |
1401 var a = 1; | 1401 var a = 1; |
1402 var b = 3.0; | 1402 var b = 3.0; |
1403 a = b; | 1403 a = b; |
1404 } | 1404 } |
1405 return {func: func}; | 1405 return {func: func}; |
1406 } | 1406 } |
1407 print("TestBadAssignIntFromDouble..."); | 1407 print("TestBadAssignIntFromDouble..."); |
1408 Module(stdlib); | 1408 Module(stdlib); |
1409 assertTrue(%IsNotAsmWasmCode(Module)); | 1409 assertFalse(%IsAsmWasmCode(Module)); |
1410 })(); | 1410 })(); |
1411 | 1411 |
1412 | 1412 |
1413 (function TestBadMultiplyIntish() { | 1413 (function TestBadMultiplyIntish() { |
1414 function Module(stdlib, foreign, heap) { | 1414 function Module(stdlib, foreign, heap) { |
1415 "use asm"; | 1415 "use asm"; |
1416 function func() { | 1416 function func() { |
1417 var a = 1; | 1417 var a = 1; |
1418 return ((a + a) * 4) | 0; | 1418 return ((a + a) * 4) | 0; |
1419 } | 1419 } |
1420 return {func: func}; | 1420 return {func: func}; |
1421 } | 1421 } |
1422 print("TestBadMultiplyIntish..."); | 1422 print("TestBadMultiplyIntish..."); |
1423 Module(stdlib); | 1423 Module(stdlib); |
1424 assertTrue(%IsNotAsmWasmCode(Module)); | 1424 assertFalse(%IsAsmWasmCode(Module)); |
1425 })(); | 1425 })(); |
1426 | 1426 |
1427 | 1427 |
1428 (function TestBadCastFromInt() { | 1428 (function TestBadCastFromInt() { |
1429 function Module(stdlib, foreign, heap) { | 1429 function Module(stdlib, foreign, heap) { |
1430 "use asm"; | 1430 "use asm"; |
1431 function func() { | 1431 function func() { |
1432 var a = 1; | 1432 var a = 1; |
1433 return +a; | 1433 return +a; |
1434 } | 1434 } |
1435 return {func: func}; | 1435 return {func: func}; |
1436 } | 1436 } |
1437 print("TestBadCastFromInt..."); | 1437 print("TestBadCastFromInt..."); |
1438 Module(stdlib); | 1438 Module(stdlib); |
1439 assertTrue(%IsNotAsmWasmCode(Module)); | 1439 assertFalse(%IsAsmWasmCode(Module)); |
1440 })(); | 1440 })(); |
1441 | 1441 |
1442 | 1442 |
1443 function TestAndNegative() { | 1443 function TestAndNegative() { |
1444 "use asm"; | 1444 "use asm"; |
1445 function func() { | 1445 function func() { |
1446 var x = 1; | 1446 var x = 1; |
1447 var y = 2; | 1447 var y = 2; |
1448 var z = 0; | 1448 var z = 0; |
1449 z = x + y & -1; | 1449 z = x + y & -1; |
(...skipping 23 matching lines...) Expand all Loading... |
1473 "use asm"; | 1473 "use asm"; |
1474 function func() { | 1474 function func() { |
1475 var x = 1.0; | 1475 var x = 1.0; |
1476 var y = 2.0; | 1476 var y = 2.0; |
1477 return (x & y) | 0; | 1477 return (x & y) | 0; |
1478 } | 1478 } |
1479 return {func: func}; | 1479 return {func: func}; |
1480 } | 1480 } |
1481 | 1481 |
1482 Module(stdlib); | 1482 Module(stdlib); |
1483 assertTrue(%IsNotAsmWasmCode(Module)); | 1483 assertFalse(%IsAsmWasmCode(Module)); |
1484 })(); | 1484 })(); |
1485 | 1485 |
1486 | 1486 |
1487 (function TestBadExportKey() { | 1487 (function TestBadExportKey() { |
1488 function Module() { | 1488 function Module() { |
1489 "use asm"; | 1489 "use asm"; |
1490 function func() { | 1490 function func() { |
1491 } | 1491 } |
1492 return {123: func}; | 1492 return {123: func}; |
1493 } | 1493 } |
1494 | 1494 |
1495 Module(stdlib); | 1495 Module(stdlib); |
1496 assertTrue(%IsNotAsmWasmCode(Module)); | 1496 assertFalse(%IsAsmWasmCode(Module)); |
1497 })(); | 1497 })(); |
1498 | 1498 |
1499 | 1499 |
1500 (function TestUnicodeExportKey() { | 1500 (function TestUnicodeExportKey() { |
1501 function Module() { | 1501 function Module() { |
1502 "use asm"; | 1502 "use asm"; |
1503 function func() { | 1503 function func() { |
1504 return 42; | 1504 return 42; |
1505 } | 1505 } |
1506 return {"\u00d1\u00e6": func}; | 1506 return {"\u00d1\u00e6": func}; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 "use asm"; | 1736 "use asm"; |
1737 function foo() { | 1737 function foo() { |
1738 return 42; | 1738 return 42; |
1739 } | 1739 } |
1740 return {bar: foo, baz: foo}; | 1740 return {bar: foo, baz: foo}; |
1741 } | 1741 } |
1742 var m = asmModule(); | 1742 var m = asmModule(); |
1743 assertEquals(42, m.bar()); | 1743 assertEquals(42, m.bar()); |
1744 assertEquals(42, m.baz()); | 1744 assertEquals(42, m.baz()); |
1745 })(); | 1745 })(); |
OLD | NEW |