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 // TODO(rmcilroy): Remove this define after this flag is turned on globally | 5 // TODO(rmcilroy): Remove this define after this flag is turned on globally |
6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
(...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 TEST(IfConditions) { | 1598 TEST(IfConditions) { |
1599 InitializedHandleScope handle_scope; | 1599 InitializedHandleScope handle_scope; |
1600 BytecodeGeneratorHelper helper; | 1600 BytecodeGeneratorHelper helper; |
1601 | 1601 |
1602 Handle<Object> unused = helper.factory()->undefined_value(); | 1602 Handle<Object> unused = helper.factory()->undefined_value(); |
1603 | 1603 |
1604 ExpectedSnippet<Handle<Object>> snippets[] = { | 1604 ExpectedSnippet<Handle<Object>> snippets[] = { |
1605 {"function f() { if (0) { return 1; } else { return -1; } } f()", | 1605 {"function f() { if (0) { return 1; } else { return -1; } } f()", |
1606 0, | 1606 0, |
1607 1, | 1607 1, |
1608 5, | 1608 3, |
1609 {B(LdaSmi8), U8(-1), // | 1609 { |
1610 B(Return), // | 1610 B(LdaSmi8), U8(-1), // |
1611 B(LdaUndefined), // TODO(mythria) redundant return statement | 1611 B(Return), // |
1612 B(Return)}, // could be eliminated. | 1612 }, |
1613 0, | 1613 0, |
1614 {unused, unused, unused, unused, unused, unused}}, | 1614 {unused, unused, unused, unused, unused, unused}}, |
1615 {"function f() { if ('lucky') { return 1; } else { return -1; } } f();", | 1615 {"function f() { if ('lucky') { return 1; } else { return -1; } } f();", |
1616 0, | 1616 0, |
1617 1, | 1617 1, |
1618 5, | 1618 3, |
1619 {B(LdaSmi8), U8(1), // | 1619 { |
1620 B(Return), // | 1620 B(LdaSmi8), U8(1), // |
1621 B(LdaUndefined), // TODO(mythria) redundant return statement | 1621 B(Return), // |
1622 B(Return)}, // could be eliminated. | 1622 }, |
1623 0, | 1623 0, |
1624 {unused, unused, unused, unused, unused, unused}}, | 1624 {unused, unused, unused, unused, unused, unused}}, |
1625 {"function f() { if (false) { return 1; } else { return -1; } } f();", | 1625 {"function f() { if (false) { return 1; } else { return -1; } } f();", |
1626 0, | 1626 0, |
1627 1, | 1627 1, |
1628 5, | 1628 3, |
1629 {B(LdaSmi8), U8(-1), // | 1629 { |
1630 B(Return), // | 1630 B(LdaSmi8), U8(-1), // |
1631 B(LdaUndefined), // TODO(mythria) redundant return statement | 1631 B(Return), // |
1632 B(Return)}, // could be eliminated. | 1632 }, |
1633 0, | 1633 0, |
1634 {unused, unused, unused, unused, unused, unused}}, | 1634 {unused, unused, unused, unused, unused, unused}}, |
1635 {"function f() { if (false) { return 1; } } f();", | 1635 {"function f() { if (false) { return 1; } } f();", |
1636 0, | 1636 0, |
1637 1, | 1637 1, |
1638 2, | 1638 2, |
1639 {B(LdaUndefined), // | 1639 { |
1640 B(Return)}, | 1640 B(LdaUndefined), // |
| 1641 B(Return), // |
| 1642 }, |
| 1643 0, |
| 1644 {unused, unused, unused, unused, unused, unused}}, |
| 1645 {"function f() { var a = 1; if (a) { a += 1; } else { return 2; } } f();", |
| 1646 1 * kPointerSize, |
| 1647 1, |
| 1648 21, |
| 1649 { |
| 1650 B(LdaSmi8), U8(1), // |
| 1651 B(Star), R(0), // |
| 1652 B(Ldar), R(0), // |
| 1653 B(JumpIfToBooleanFalse), U8(10), // |
| 1654 B(LdaSmi8), U8(1), // |
| 1655 B(Add), R(0), // |
| 1656 B(Star), R(0), // |
| 1657 B(Jump), U8(5), // |
| 1658 B(LdaSmi8), U8(2), // |
| 1659 B(Return), // |
| 1660 B(LdaUndefined), // |
| 1661 B(Return), // |
| 1662 }, |
1641 0, | 1663 0, |
1642 {unused, unused, unused, unused, unused, unused}}, | 1664 {unused, unused, unused, unused, unused, unused}}, |
1643 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }" | 1665 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }" |
1644 "f(99);", | 1666 "f(99);", |
1645 0, | 1667 0, |
1646 2, | 1668 2, |
1647 15, | 1669 13, |
1648 {B(LdaZero), // | 1670 { |
1649 B(TestLessThanOrEqual), A(1, 2), // | 1671 B(LdaZero), // |
1650 B(JumpIfFalse), U8(7), // | 1672 B(TestLessThanOrEqual), A(1, 2), // |
1651 B(LdaConstant), U8(0), // | 1673 B(JumpIfFalse), U8(5), // |
1652 B(Return), // | 1674 B(LdaConstant), U8(0), // |
1653 B(Jump), U8(5), // | 1675 B(Return), // |
1654 B(LdaConstant), U8(1), // | 1676 B(LdaConstant), U8(1), // |
1655 B(Return), // | 1677 B(Return), // |
1656 B(LdaUndefined), // | 1678 B(LdaUndefined), // |
1657 B(Return)}, // | 1679 B(Return), // |
| 1680 }, |
1658 2, | 1681 2, |
1659 {helper.factory()->NewNumberFromInt(200), | 1682 {helper.factory()->NewNumberFromInt(200), |
1660 helper.factory()->NewNumberFromInt(-200), unused, unused, unused, | 1683 helper.factory()->NewNumberFromInt(-200), unused, unused, unused, |
1661 unused}}, | 1684 unused}}, |
1662 {"function f(a, b) { if (a in b) { return 200; } }" | 1685 {"function f(a, b) { if (a in b) { return 200; } }" |
1663 "f('prop', { prop: 'yes'});", | 1686 "f('prop', { prop: 'yes'});", |
1664 0, | 1687 0, |
1665 3, | 1688 3, |
1666 11, | 1689 11, |
1667 {B(Ldar), A(2, 3), // | 1690 { |
1668 B(TestIn), A(1, 3), // | 1691 B(Ldar), A(2, 3), // |
1669 B(JumpIfFalse), U8(5), // | 1692 B(TestIn), A(1, 3), // |
1670 B(LdaConstant), U8(0), // | 1693 B(JumpIfFalse), U8(5), // |
1671 B(Return), // | 1694 B(LdaConstant), U8(0), // |
1672 B(LdaUndefined), // | 1695 B(Return), // |
1673 B(Return)}, // | 1696 B(LdaUndefined), // |
| 1697 B(Return), // |
| 1698 }, |
1674 1, | 1699 1, |
1675 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused, | 1700 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused, |
1676 unused}}, | 1701 unused}}, |
1677 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " | 1702 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " |
1678 REPEAT_32(SPACE, "b = a; a = b; ") | 1703 REPEAT_32(SPACE, "b = a; a = b; ") |
1679 " return 200; } else { return -200; } } f(0.001)", | 1704 " return 200; } else { return -200; } } f(0.001)", |
1680 2 * kPointerSize, | 1705 2 * kPointerSize, |
1681 2, | 1706 2, |
1682 278, | 1707 276, |
1683 { | 1708 { |
1684 B(LdaZero), // | 1709 B(LdaZero), // |
1685 B(Star), R(0), // | 1710 B(Star), R(0), // |
1686 B(LdaZero), // | 1711 B(LdaZero), // |
1687 B(Star), R(1), // | 1712 B(Star), R(1), // |
1688 B(LdaConstant), U8(0), // | 1713 B(LdaConstant), U8(0), // |
1689 B(TestEqualStrict), R(0), // | 1714 B(TestEqualStrict), R(0), // |
1690 B(JumpIfFalseConstant), U8(2), // | 1715 B(JumpIfFalseConstant), U8(2), // |
1691 REPEAT_32(COMMA, // | 1716 REPEAT_32(COMMA, // |
1692 B(Ldar), R(0), // | 1717 B(Ldar), R(0), // |
1693 B(Star), R(1), // | 1718 B(Star), R(1), // |
1694 B(Ldar), R(1), // | 1719 B(Ldar), R(1), // |
1695 B(Star), R(0)), // | 1720 B(Star), R(0)), // |
1696 B(LdaConstant), U8(1), // | 1721 B(LdaConstant), U8(1), // |
1697 B(Return), // | 1722 B(Return), // |
1698 B(Jump), U8(5), // | |
1699 B(LdaConstant), U8(3), // | 1723 B(LdaConstant), U8(3), // |
1700 B(Return), // | 1724 B(Return), // |
1701 B(LdaUndefined), // | 1725 B(LdaUndefined), // |
1702 B(Return)}, // | 1726 B(Return)}, // |
1703 4, | 1727 4, |
1704 {helper.factory()->NewHeapNumber(0.01), | 1728 {helper.factory()->NewHeapNumber(0.01), |
1705 helper.factory()->NewNumberFromInt(200), | 1729 helper.factory()->NewNumberFromInt(200), |
1706 helper.factory()->NewNumberFromInt(263), | 1730 helper.factory()->NewNumberFromInt(261), |
1707 helper.factory()->NewNumberFromInt(-200), unused, unused}}, | 1731 helper.factory()->NewNumberFromInt(-200), unused, unused}}, |
1708 {"function f() { var a = 0; var b = 0; if (a) { " | 1732 {"function f() { var a = 0; var b = 0; if (a) { " |
1709 REPEAT_32(SPACE, "b = a; a = b; ") | 1733 REPEAT_32(SPACE, "b = a; a = b; ") |
1710 " return 200; } else { return -200; } } f()", | 1734 " return 200; } else { return -200; } } f()", |
1711 2 * kPointerSize, | 1735 2 * kPointerSize, |
1712 1, | 1736 1, |
1713 276, | 1737 274, |
1714 { | 1738 { |
1715 B(LdaZero), // | 1739 B(LdaZero), // |
1716 B(Star), R(0), // | 1740 B(Star), R(0), // |
1717 B(LdaZero), // | 1741 B(LdaZero), // |
1718 B(Star), R(1), // | 1742 B(Star), R(1), // |
1719 B(Ldar), R(0), // | 1743 B(Ldar), R(0), // |
1720 B(JumpIfToBooleanFalseConstant), U8(1), // | 1744 B(JumpIfToBooleanFalseConstant), U8(1), // |
1721 REPEAT_32(COMMA, // | 1745 REPEAT_32(COMMA, // |
1722 B(Ldar), R(0), // | 1746 B(Ldar), R(0), // |
1723 B(Star), R(1), // | 1747 B(Star), R(1), // |
1724 B(Ldar), R(1), // | 1748 B(Ldar), R(1), // |
1725 B(Star), R(0)), // | 1749 B(Star), R(0)), // |
1726 B(LdaConstant), U8(0), // | 1750 B(LdaConstant), U8(0), // |
1727 B(Return), // | 1751 B(Return), // |
1728 B(Jump), U8(5), // | |
1729 B(LdaConstant), U8(2), // | 1752 B(LdaConstant), U8(2), // |
1730 B(Return), // | 1753 B(Return), // |
1731 B(LdaUndefined), // | 1754 B(LdaUndefined), // |
1732 B(Return)}, // | 1755 B(Return)}, // |
1733 3, | 1756 3, |
1734 {helper.factory()->NewNumberFromInt(200), | 1757 {helper.factory()->NewNumberFromInt(200), |
1735 helper.factory()->NewNumberFromInt(263), | 1758 helper.factory()->NewNumberFromInt(261), |
1736 helper.factory()->NewNumberFromInt(-200), unused, unused, unused}}, | 1759 helper.factory()->NewNumberFromInt(-200), unused, unused, unused}}, |
1737 | 1760 |
1738 {"function f(a, b) {\n" | 1761 {"function f(a, b) {\n" |
1739 " if (a == b) { return 1; }\n" | 1762 " if (a == b) { return 1; }\n" |
1740 " if (a === b) { return 1; }\n" | 1763 " if (a === b) { return 1; }\n" |
1741 " if (a < b) { return 1; }\n" | 1764 " if (a < b) { return 1; }\n" |
1742 " if (a > b) { return 1; }\n" | 1765 " if (a > b) { return 1; }\n" |
1743 " if (a <= b) { return 1; }\n" | 1766 " if (a <= b) { return 1; }\n" |
1744 " if (a >= b) { return 1; }\n" | 1767 " if (a >= b) { return 1; }\n" |
1745 " if (a in b) { return 1; }\n" | 1768 " if (a in b) { return 1; }\n" |
(...skipping 26 matching lines...) Expand all Loading... |
1772 {"function f() {" | 1795 {"function f() {" |
1773 " var a = 0;" | 1796 " var a = 0;" |
1774 " if (a) {" | 1797 " if (a) {" |
1775 " return 20;" | 1798 " return 20;" |
1776 "} else {" | 1799 "} else {" |
1777 " return -20;}" | 1800 " return -20;}" |
1778 "};" | 1801 "};" |
1779 "f();", | 1802 "f();", |
1780 1 * kPointerSize, | 1803 1 * kPointerSize, |
1781 1, | 1804 1, |
1782 17, | 1805 15, |
1783 { | 1806 { |
1784 B(LdaZero), // | 1807 B(LdaZero), // |
1785 B(Star), R(0), // | 1808 B(Star), R(0), // |
1786 B(Ldar), R(0), // | 1809 B(Ldar), R(0), // |
1787 B(JumpIfToBooleanFalse), U8(7), // | 1810 B(JumpIfToBooleanFalse), U8(5), // |
1788 B(LdaSmi8), U8(20), // | 1811 B(LdaSmi8), U8(20), // |
1789 B(Return), // | 1812 B(Return), // |
1790 B(Jump), U8(5), // | |
1791 B(LdaSmi8), U8(-20), // | 1813 B(LdaSmi8), U8(-20), // |
1792 B(Return), // | 1814 B(Return), // |
1793 B(LdaUndefined), // | 1815 B(LdaUndefined), // |
1794 B(Return) | 1816 B(Return) |
1795 }, | 1817 }, |
1796 0, | 1818 0, |
1797 {unused, unused, unused, unused, unused, unused}} | 1819 {unused, unused, unused, unused, unused, unused}} |
1798 }; | 1820 }; |
1799 | 1821 |
1800 for (size_t i = 0; i < arraysize(snippets); i++) { | 1822 for (size_t i = 0; i < arraysize(snippets); i++) { |
(...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3341 | 3363 |
3342 TEST(TryCatch) { | 3364 TEST(TryCatch) { |
3343 InitializedHandleScope handle_scope; | 3365 InitializedHandleScope handle_scope; |
3344 BytecodeGeneratorHelper helper; | 3366 BytecodeGeneratorHelper helper; |
3345 | 3367 |
3346 // TODO(rmcilroy): modify tests when we have real try catch support. | 3368 // TODO(rmcilroy): modify tests when we have real try catch support. |
3347 ExpectedSnippet<int> snippets[] = { | 3369 ExpectedSnippet<int> snippets[] = { |
3348 {"try { return 1; } catch(e) { return 2; }", | 3370 {"try { return 1; } catch(e) { return 2; }", |
3349 kPointerSize, | 3371 kPointerSize, |
3350 1, | 3372 1, |
3351 5, | 3373 3, |
3352 { | 3374 { |
3353 B(LdaSmi8), U8(1), // | 3375 B(LdaSmi8), U8(1), // |
3354 B(Return), // | 3376 B(Return), // |
3355 B(LdaUndefined), // | |
3356 B(Return), // | |
3357 }, | 3377 }, |
3358 0}, | 3378 0}, |
3359 }; | 3379 }; |
3360 | 3380 |
3361 for (size_t i = 0; i < arraysize(snippets); i++) { | 3381 for (size_t i = 0; i < arraysize(snippets); i++) { |
3362 Handle<BytecodeArray> bytecode_array = | 3382 Handle<BytecodeArray> bytecode_array = |
3363 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3383 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
3364 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3384 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
3365 } | 3385 } |
3366 } | 3386 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3430 {"throw 'Error';", | 3450 {"throw 'Error';", |
3431 0, | 3451 0, |
3432 1, | 3452 1, |
3433 3, | 3453 3, |
3434 { | 3454 { |
3435 B(LdaConstant), U8(0), // | 3455 B(LdaConstant), U8(0), // |
3436 B(Throw), // | 3456 B(Throw), // |
3437 }, | 3457 }, |
3438 1, | 3458 1, |
3439 {"Error"}}, | 3459 {"Error"}}, |
3440 {"if ('test') { throw 'Error'; };", | 3460 {"var a = 1; if (a) { throw 'Error'; };", |
3441 0, | 3461 1 * kPointerSize, |
3442 1, | 3462 1, |
3443 5, | 3463 13, |
3444 { | 3464 { |
3445 B(LdaConstant), U8(0), // | 3465 B(LdaSmi8), U8(1), // |
3446 B(Throw), // | 3466 B(Star), R(0), // |
3447 B(LdaUndefined), // | 3467 B(Ldar), R(0), // |
3448 B(Return), // | 3468 B(JumpIfToBooleanFalse), U8(5), // |
| 3469 B(LdaConstant), U8(0), // |
| 3470 B(Throw), // |
| 3471 B(LdaUndefined), // |
| 3472 B(Return), // |
3449 }, | 3473 }, |
3450 1, | 3474 1, |
3451 {"Error"}}, | 3475 {"Error"}}, |
3452 }; | 3476 }; |
3453 | 3477 |
3454 for (size_t i = 0; i < arraysize(snippets); i++) { | 3478 for (size_t i = 0; i < arraysize(snippets); i++) { |
3455 Handle<BytecodeArray> bytecode_array = | 3479 Handle<BytecodeArray> bytecode_array = |
3456 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3480 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
3457 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3481 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
3458 } | 3482 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3608 B(Star), R(1), // | 3632 B(Star), R(1), // |
3609 B(Call), R(1), R(2), U8(0), // | 3633 B(Call), R(1), R(2), U8(0), // |
3610 B(LdaContextSlot), R(0), U8(first_context_slot), // | 3634 B(LdaContextSlot), R(0), U8(first_context_slot), // |
3611 B(Return), // | 3635 B(Return), // |
3612 }, | 3636 }, |
3613 1, | 3637 1, |
3614 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3638 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
3615 {"'use strict'; let a = 1; { let b = 2; return function() { a + b; }; }", | 3639 {"'use strict'; let a = 1; { let b = 2; return function() { a + b; }; }", |
3616 4 * kPointerSize, | 3640 4 * kPointerSize, |
3617 1, | 3641 1, |
3618 49, | 3642 45, |
3619 { | 3643 { |
3620 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 3644 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
3621 R(closure), U8(1), // | 3645 R(closure), U8(1), // |
3622 B(PushContext), R(0), // | 3646 B(PushContext), R(0), // |
3623 B(LdaTheHole), // | 3647 B(LdaTheHole), // |
3624 B(StaContextSlot), R(0), U8(first_context_slot), // | 3648 B(StaContextSlot), R(0), U8(first_context_slot), // |
3625 B(LdaSmi8), U8(1), // | 3649 B(LdaSmi8), U8(1), // |
3626 B(StaContextSlot), R(0), U8(first_context_slot), // | 3650 B(StaContextSlot), R(0), U8(first_context_slot), // |
3627 B(LdaConstant), U8(0), // | 3651 B(LdaConstant), U8(0), // |
3628 B(Star), R(2), // | 3652 B(Star), R(2), // |
3629 B(Ldar), R(closure), // | 3653 B(Ldar), R(closure), // |
3630 B(Star), R(3), // | 3654 B(Star), R(3), // |
3631 B(CallRuntime), U16(Runtime::kPushBlockContext), R(2), U8(2), // | 3655 B(CallRuntime), U16(Runtime::kPushBlockContext), R(2), U8(2), // |
3632 B(PushContext), R(1), // | 3656 B(PushContext), R(1), // |
3633 B(LdaTheHole), // | 3657 B(LdaTheHole), // |
3634 B(StaContextSlot), R(1), U8(first_context_slot), // | 3658 B(StaContextSlot), R(1), U8(first_context_slot), // |
3635 B(LdaSmi8), U8(2), // | 3659 B(LdaSmi8), U8(2), // |
3636 B(StaContextSlot), R(1), U8(first_context_slot), // | 3660 B(StaContextSlot), R(1), U8(first_context_slot), // |
3637 B(LdaConstant), U8(1), // | 3661 B(LdaConstant), U8(1), // |
3638 B(CreateClosure), U8(0), // | 3662 B(CreateClosure), U8(0), // |
3639 B(Return), // | 3663 B(Return), // |
3640 // TODO(rmcilroy): Dead code after this point due to return in nested | |
3641 // block - investigate eliminating this. | |
3642 B(PopContext), R(0), | |
3643 B(LdaUndefined), // | |
3644 B(Return), // | |
3645 }, | 3664 }, |
3646 2, | 3665 2, |
3647 {InstanceType::FIXED_ARRAY_TYPE, | 3666 {InstanceType::FIXED_ARRAY_TYPE, |
3648 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3667 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
3649 }; | 3668 }; |
3650 | 3669 |
3651 for (size_t i = 0; i < arraysize(snippets); i++) { | 3670 for (size_t i = 0; i < arraysize(snippets); i++) { |
3652 Handle<BytecodeArray> bytecode_array = | 3671 Handle<BytecodeArray> bytecode_array = |
3653 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3672 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
3654 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3673 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4924 }}, | 4943 }}, |
4925 }; | 4944 }; |
4926 | 4945 |
4927 for (size_t i = 0; i < arraysize(snippets); i++) { | 4946 for (size_t i = 0; i < arraysize(snippets); i++) { |
4928 Handle<BytecodeArray> bytecode_array = | 4947 Handle<BytecodeArray> bytecode_array = |
4929 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4948 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
4930 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4949 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
4931 } | 4950 } |
4932 } | 4951 } |
4933 | 4952 |
| 4953 |
| 4954 TEST(BasicBlockToBoolean) { |
| 4955 InitializedHandleScope handle_scope; |
| 4956 BytecodeGeneratorHelper helper; |
| 4957 |
| 4958 // Check that we don't omit ToBoolean calls if they are at the start of basic |
| 4959 // blocks. |
| 4960 ExpectedSnippet<int> snippets[] = { |
| 4961 {"var a = 1; if (a || a < 0) { return 1; }", |
| 4962 1 * kPointerSize, |
| 4963 1, |
| 4964 18, |
| 4965 { |
| 4966 B(LdaSmi8), U8(1), // |
| 4967 B(Star), R(0), // |
| 4968 B(Ldar), R(0), // |
| 4969 B(JumpIfToBooleanTrue), U8(5), // |
| 4970 B(LdaZero), // |
| 4971 B(TestLessThan), R(0), // |
| 4972 B(JumpIfToBooleanFalse), U8(5), // |
| 4973 B(LdaSmi8), U8(1), // |
| 4974 B(Return), // |
| 4975 B(LdaUndefined), // |
| 4976 B(Return), // |
| 4977 }}, |
| 4978 {"var a = 1; if (a && a < 0) { return 1; }", |
| 4979 1 * kPointerSize, |
| 4980 1, |
| 4981 18, |
| 4982 { |
| 4983 B(LdaSmi8), U8(1), // |
| 4984 B(Star), R(0), // |
| 4985 B(Ldar), R(0), // |
| 4986 B(JumpIfToBooleanFalse), U8(5), // |
| 4987 B(LdaZero), // |
| 4988 B(TestLessThan), R(0), // |
| 4989 B(JumpIfToBooleanFalse), U8(5), // |
| 4990 B(LdaSmi8), U8(1), // |
| 4991 B(Return), // |
| 4992 B(LdaUndefined), // |
| 4993 B(Return), // |
| 4994 }}, |
| 4995 {"var a = 1; a = (a || a < 0) ? 2 : 3;", |
| 4996 1 * kPointerSize, |
| 4997 1, |
| 4998 23, |
| 4999 { |
| 5000 B(LdaSmi8), U8(1), // |
| 5001 B(Star), R(0), // |
| 5002 B(Ldar), R(0), // |
| 5003 B(JumpIfToBooleanTrue), U8(5), // |
| 5004 B(LdaZero), // |
| 5005 B(TestLessThan), R(0), // |
| 5006 B(JumpIfToBooleanFalse), U8(6), // |
| 5007 B(LdaSmi8), U8(2), // |
| 5008 B(Jump), U8(4), // |
| 5009 B(LdaSmi8), U8(3), // |
| 5010 B(Star), R(0), // |
| 5011 B(LdaUndefined), // |
| 5012 B(Return), // |
| 5013 }}, |
| 5014 }; |
| 5015 |
| 5016 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5017 Handle<BytecodeArray> bytecode_array = |
| 5018 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 5019 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5020 } |
| 5021 } |
| 5022 |
| 5023 |
| 5024 TEST(DeadCodeRemoval) { |
| 5025 InitializedHandleScope handle_scope; |
| 5026 BytecodeGeneratorHelper helper; |
| 5027 |
| 5028 ExpectedSnippet<int> snippets[] = { |
| 5029 {"return; var a = 1; a();", |
| 5030 1 * kPointerSize, |
| 5031 1, |
| 5032 2, |
| 5033 { |
| 5034 B(LdaUndefined), // |
| 5035 B(Return), // |
| 5036 }}, |
| 5037 {"if (false) { return; }; var a = 1;", |
| 5038 1 * kPointerSize, |
| 5039 1, |
| 5040 6, |
| 5041 { |
| 5042 B(LdaSmi8), U8(1), // |
| 5043 B(Star), R(0), // |
| 5044 B(LdaUndefined), // |
| 5045 B(Return), // |
| 5046 }}, |
| 5047 {"if (true) { return 1; } else { return 2; };", |
| 5048 0, |
| 5049 1, |
| 5050 3, |
| 5051 { |
| 5052 B(LdaSmi8), U8(1), // |
| 5053 B(Return), // |
| 5054 }}, |
| 5055 {"var a = 1; if (a) { return 1; }; return 2;", |
| 5056 1 * kPointerSize, |
| 5057 1, |
| 5058 14, |
| 5059 { |
| 5060 B(LdaSmi8), U8(1), // |
| 5061 B(Star), R(0), // |
| 5062 B(Ldar), R(0), // |
| 5063 B(JumpIfToBooleanFalse), U8(5), // |
| 5064 B(LdaSmi8), U8(1), // |
| 5065 B(Return), // |
| 5066 B(LdaSmi8), U8(2), // |
| 5067 B(Return), // |
| 5068 }}, |
| 5069 }; |
| 5070 |
| 5071 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5072 Handle<BytecodeArray> bytecode_array = |
| 5073 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 5074 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5075 } |
| 5076 } |
| 5077 |
4934 } // namespace interpreter | 5078 } // namespace interpreter |
4935 } // namespace internal | 5079 } // namespace internal |
4936 } // namespace v8 | 5080 } // namespace v8 |
OLD | NEW |