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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 501 |
502 assertEquals(24, Wasm.instantiateModuleFromAsm( | 502 assertEquals(24, Wasm.instantiateModuleFromAsm( |
503 TestConvertI32.toString()).caller()); | 503 TestConvertI32.toString()).caller()); |
504 | 504 |
505 | 505 |
506 function TestConvertF64FromInt() { | 506 function TestConvertF64FromInt() { |
507 "use asm"; | 507 "use asm"; |
508 | 508 |
509 function caller() { | 509 function caller() { |
510 var a = 1; | 510 var a = 1; |
511 if ((+(a + a)) > 1.5) { | 511 if ((+((a + a)|0)) > 1.5) { |
512 return 25; | 512 return 25; |
513 } | 513 } |
514 return 0; | 514 return 0; |
515 } | 515 } |
516 | 516 |
517 return {caller:caller}; | 517 return {caller:caller}; |
518 } | 518 } |
519 | 519 |
520 assertEquals(25, Wasm.instantiateModuleFromAsm( | 520 assertEquals(25, Wasm.instantiateModuleFromAsm( |
521 TestConvertF64FromInt.toString()).caller()); | 521 TestConvertF64FromInt.toString()).caller()); |
522 | 522 |
523 | 523 |
524 function TestConvertF64FromUnsigned() { | 524 function TestConvertF64FromUnsigned() { |
525 "use asm"; | 525 "use asm"; |
526 | 526 |
527 function caller() { | 527 function caller() { |
528 var a = 0xffffffff; | 528 var a = 0xffffffff; |
529 if ((+(a>>>0)) > 0.0) { | 529 if ((+(a>>>0)) > 0.0) { |
530 if((+a) < 0.0) { | 530 if((+(a|0)) < 0.0) { |
531 return 26; | 531 return 26; |
532 } | 532 } |
533 } | 533 } |
534 return 0; | 534 return 0; |
535 } | 535 } |
536 | 536 |
537 return {caller:caller}; | 537 return {caller:caller}; |
538 } | 538 } |
539 | 539 |
540 assertEquals(26, Wasm.instantiateModuleFromAsm( | 540 assertEquals(26, Wasm.instantiateModuleFromAsm( |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 return ((a + a) * 4) | 0; | 1397 return ((a + a) * 4) | 0; |
1398 } | 1398 } |
1399 return {func: func}; | 1399 return {func: func}; |
1400 } | 1400 } |
1401 assertThrows(function() { | 1401 assertThrows(function() { |
1402 Wasm.instantiateModuleFromAsm(Module.toString()); | 1402 Wasm.instantiateModuleFromAsm(Module.toString()); |
1403 }); | 1403 }); |
1404 })(); | 1404 })(); |
1405 | 1405 |
1406 | 1406 |
| 1407 (function TestBadCastFromInt() { |
| 1408 function Module(stdlib, foreign, heap) { |
| 1409 "use asm"; |
| 1410 function func() { |
| 1411 var a = 1; |
| 1412 return +a; |
| 1413 } |
| 1414 return {func: func}; |
| 1415 } |
| 1416 assertThrows(function() { |
| 1417 Wasm.instantiateModuleFromAsm(Module.toString()); |
| 1418 }); |
| 1419 })(); |
| 1420 |
| 1421 |
1407 (function TestAndNegative() { | 1422 (function TestAndNegative() { |
1408 function Module() { | 1423 function Module() { |
1409 "use asm"; | 1424 "use asm"; |
1410 function func() { | 1425 function func() { |
1411 var x = 1; | 1426 var x = 1; |
1412 var y = 2; | 1427 var y = 2; |
1413 var z = 0; | 1428 var z = 0; |
1414 z = x + y & -1; | 1429 z = x + y & -1; |
1415 return z | 0; | 1430 return z | 0; |
1416 } | 1431 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 var a = 0; | 1493 var a = 0; |
1479 f = 5616315000.000001; | 1494 f = 5616315000.000001; |
1480 a = ~~f >>>0; | 1495 a = ~~f >>>0; |
1481 return a | 0; | 1496 return a | 0; |
1482 } | 1497 } |
1483 return { main : aaa }; | 1498 return { main : aaa }; |
1484 } | 1499 } |
1485 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); | 1500 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); |
1486 assertEquals(1321347704, wasm.main()); | 1501 assertEquals(1321347704, wasm.main()); |
1487 })(); | 1502 })(); |
| 1503 |
| 1504 (function TestUnsignedLiterals() { |
| 1505 function asmModule() { |
| 1506 "use asm"; |
| 1507 function u0xffffffff() { |
| 1508 var f = 0xffffffff; |
| 1509 return +(f >>> 0); |
| 1510 } |
| 1511 function u0x80000000() { |
| 1512 var f = 0x80000000; |
| 1513 return +(f >>> 0); |
| 1514 } |
| 1515 function u0x87654321() { |
| 1516 var f = 0x87654321; |
| 1517 return +(f >>> 0); |
| 1518 } |
| 1519 return { |
| 1520 u0xffffffff: u0xffffffff, |
| 1521 u0x80000000: u0x80000000, |
| 1522 u0x87654321: u0x87654321, |
| 1523 }; |
| 1524 } |
| 1525 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); |
| 1526 assertEquals(0xffffffff, wasm.u0xffffffff()); |
| 1527 assertEquals(0x80000000, wasm.u0x80000000()); |
| 1528 assertEquals(0x87654321, wasm.u0x87654321()); |
| 1529 })(); |
OLD | NEW |