| 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 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
| 10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 | 129 |
| 130 template <typename T> | 130 template <typename T> |
| 131 static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected, | 131 static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected, |
| 132 Handle<BytecodeArray> actual, | 132 Handle<BytecodeArray> actual, |
| 133 bool has_unknown = false) { | 133 bool has_unknown = false) { |
| 134 CHECK_EQ(actual->frame_size(), expected.frame_size); | 134 CHECK_EQ(actual->frame_size(), expected.frame_size); |
| 135 CHECK_EQ(actual->parameter_count(), expected.parameter_count); | 135 CHECK_EQ(actual->parameter_count(), expected.parameter_count); |
| 136 CHECK_EQ(actual->length(), expected.bytecode_length); | 136 CHECK_EQ(actual->length(), expected.bytecode_length); |
| 137 if (expected.constant_count != -1) { | 137 if (expected.constant_count == 0) { |
| 138 if (expected.constant_count == 0) { | 138 CHECK_EQ(actual->constant_pool(), CcTest::heap()->empty_fixed_array()); |
| 139 CHECK_EQ(actual->constant_pool(), CcTest::heap()->empty_fixed_array()); | 139 } else { |
| 140 } else { | 140 CHECK_EQ(actual->constant_pool()->length(), expected.constant_count); |
| 141 CHECK_EQ(actual->constant_pool()->length(), expected.constant_count); | 141 for (int i = 0; i < expected.constant_count; i++) { |
| 142 for (int i = 0; i < expected.constant_count; i++) { | 142 CheckConstant(expected.constants[i], actual->constant_pool()->get(i)); |
| 143 CheckConstant(expected.constants[i], actual->constant_pool()->get(i)); | |
| 144 } | |
| 145 } | 143 } |
| 146 } | 144 } |
| 147 | 145 |
| 148 BytecodeArrayIterator iterator(actual); | 146 BytecodeArrayIterator iterator(actual); |
| 149 int i = 0; | 147 int i = 0; |
| 150 while (!iterator.done()) { | 148 while (!iterator.done()) { |
| 151 int bytecode_index = i++; | 149 int bytecode_index = i++; |
| 152 Bytecode bytecode = iterator.current_bytecode(); | 150 Bytecode bytecode = iterator.current_bytecode(); |
| 153 if (Bytecodes::ToByte(bytecode) != expected.bytecode[bytecode_index]) { | 151 if (Bytecodes::ToByte(bytecode) != expected.bytecode[bytecode_index]) { |
| 154 std::ostringstream stream; | 152 std::ostringstream stream; |
| (...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); | 1483 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); |
| 1486 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1484 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1487 } | 1485 } |
| 1488 } | 1486 } |
| 1489 | 1487 |
| 1490 | 1488 |
| 1491 TEST(DeclareGlobals) { | 1489 TEST(DeclareGlobals) { |
| 1492 InitializedHandleScope handle_scope; | 1490 InitializedHandleScope handle_scope; |
| 1493 BytecodeGeneratorHelper helper; | 1491 BytecodeGeneratorHelper helper; |
| 1494 | 1492 |
| 1495 ExpectedSnippet<int> snippets[] = { | 1493 ExpectedSnippet<InstanceType> snippets[] = { |
| 1496 {"var a = 1;", | 1494 {"var a = 1;", |
| 1497 5 * kPointerSize, | 1495 5 * kPointerSize, |
| 1498 1, | 1496 1, |
| 1499 45, | 1497 45, |
| 1500 { | 1498 { |
| 1501 B(Ldar), R(Register::function_closure().index()), // | 1499 B(Ldar), R(Register::function_closure().index()), // |
| 1502 B(Star), R(2), // | 1500 B(Star), R(2), // |
| 1503 B(LdaConstant), U8(0), // | 1501 B(LdaConstant), U8(0), // |
| 1504 B(Star), R(3), // | 1502 B(Star), R(3), // |
| 1505 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | 1503 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // |
| 1506 B(PushContext), R(1), // | 1504 B(PushContext), R(1), // |
| 1507 B(LdaConstant), U8(1), // | 1505 B(LdaConstant), U8(1), // |
| 1508 B(Star), R(2), // | 1506 B(Star), R(2), // |
| 1509 B(LdaZero), // | 1507 B(LdaZero), // |
| 1510 B(Star), R(3), // | 1508 B(Star), R(3), // |
| 1511 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // | 1509 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // |
| 1512 B(LdaConstant), U8(2), // | 1510 B(LdaConstant), U8(2), // |
| 1513 B(Star), R(2), // | 1511 B(Star), R(2), // |
| 1514 B(LdaZero), // | 1512 B(LdaZero), // |
| 1515 B(Star), R(3), // | 1513 B(Star), R(3), // |
| 1516 B(LdaSmi8), U8(1), // | 1514 B(LdaSmi8), U8(1), // |
| 1517 B(Star), R(4), // | 1515 B(Star), R(4), // |
| 1518 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // | 1516 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // |
| 1519 U8(3), // | 1517 U8(3), // |
| 1520 B(LdaUndefined), // | 1518 B(LdaUndefined), // |
| 1521 B(Return) // | 1519 B(Return) // |
| 1522 }, | 1520 }, |
| 1523 -1}, | 1521 3, |
| 1522 {InstanceType::FIXED_ARRAY_TYPE, |
| 1523 InstanceType::FIXED_ARRAY_TYPE, |
| 1524 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 1524 {"function f() {}", | 1525 {"function f() {}", |
| 1525 3 * kPointerSize, | 1526 3 * kPointerSize, |
| 1526 1, | 1527 1, |
| 1527 29, | 1528 29, |
| 1528 { | 1529 { |
| 1529 B(Ldar), R(Register::function_closure().index()), // | 1530 B(Ldar), R(Register::function_closure().index()), // |
| 1530 B(Star), R(1), // | 1531 B(Star), R(1), // |
| 1531 B(LdaConstant), U8(0), // | 1532 B(LdaConstant), U8(0), // |
| 1532 B(Star), R(2), // | 1533 B(Star), R(2), // |
| 1533 B(CallRuntime), U16(Runtime::kNewScriptContext), R(1), U8(2), // | 1534 B(CallRuntime), U16(Runtime::kNewScriptContext), R(1), U8(2), // |
| 1534 B(PushContext), R(0), // | 1535 B(PushContext), R(0), // |
| 1535 B(LdaConstant), U8(1), // | 1536 B(LdaConstant), U8(1), // |
| 1536 B(Star), R(1), // | 1537 B(Star), R(1), // |
| 1537 B(LdaZero), // | 1538 B(LdaZero), // |
| 1538 B(Star), R(2), // | 1539 B(Star), R(2), // |
| 1539 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // | 1540 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
| 1540 B(LdaUndefined), // | 1541 B(LdaUndefined), // |
| 1541 B(Return) // | 1542 B(Return) // |
| 1542 }, | 1543 }, |
| 1543 -1}, | 1544 2, |
| 1545 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}}, |
| 1544 {"var a = 1;\na=2;", | 1546 {"var a = 1;\na=2;", |
| 1545 5 * kPointerSize, | 1547 5 * kPointerSize, |
| 1546 1, | 1548 1, |
| 1547 52, | 1549 52, |
| 1548 { | 1550 { |
| 1549 B(Ldar), R(Register::function_closure().index()), // | 1551 B(Ldar), R(Register::function_closure().index()), // |
| 1550 B(Star), R(2), // | 1552 B(Star), R(2), // |
| 1551 B(LdaConstant), U8(0), // | 1553 B(LdaConstant), U8(0), // |
| 1552 B(Star), R(3), // | 1554 B(Star), R(3), // |
| 1553 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | 1555 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1564 B(LdaSmi8), U8(1), // | 1566 B(LdaSmi8), U8(1), // |
| 1565 B(Star), R(4), // | 1567 B(Star), R(4), // |
| 1566 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // | 1568 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // |
| 1567 U8(3), // | 1569 U8(3), // |
| 1568 B(LdaSmi8), U8(2), // | 1570 B(LdaSmi8), U8(2), // |
| 1569 B(StaGlobal), _, // | 1571 B(StaGlobal), _, // |
| 1570 B(Star), R(0), // | 1572 B(Star), R(0), // |
| 1571 B(Ldar), R(0), // | 1573 B(Ldar), R(0), // |
| 1572 B(Return) // | 1574 B(Return) // |
| 1573 }, | 1575 }, |
| 1574 -1}, | 1576 3, |
| 1577 {InstanceType::FIXED_ARRAY_TYPE, |
| 1578 InstanceType::FIXED_ARRAY_TYPE, |
| 1579 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 1575 {"function f() {}\nf();", | 1580 {"function f() {}\nf();", |
| 1576 4 * kPointerSize, | 1581 4 * kPointerSize, |
| 1577 1, | 1582 1, |
| 1578 43, | 1583 43, |
| 1579 { | 1584 { |
| 1580 B(Ldar), R(Register::function_closure().index()), // | 1585 B(Ldar), R(Register::function_closure().index()), // |
| 1581 B(Star), R(2), // | 1586 B(Star), R(2), // |
| 1582 B(LdaConstant), U8(0), // | 1587 B(LdaConstant), U8(0), // |
| 1583 B(Star), R(3), // | 1588 B(Star), R(3), // |
| 1584 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | 1589 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // |
| 1585 B(PushContext), R(1), // | 1590 B(PushContext), R(1), // |
| 1586 B(LdaConstant), U8(1), // | 1591 B(LdaConstant), U8(1), // |
| 1587 B(Star), R(2), // | 1592 B(Star), R(2), // |
| 1588 B(LdaZero), // | 1593 B(LdaZero), // |
| 1589 B(Star), R(3), // | 1594 B(Star), R(3), // |
| 1590 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // | 1595 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // |
| 1591 B(LdaUndefined), // | 1596 B(LdaUndefined), // |
| 1592 B(Star), R(3), // | 1597 B(Star), R(3), // |
| 1593 B(LdaGlobal), _, // | 1598 B(LdaGlobal), _, // |
| 1594 B(Star), R(2), // | 1599 B(Star), R(2), // |
| 1595 B(Call), R(2), R(3), U8(0), // | 1600 B(Call), R(2), R(3), U8(0), // |
| 1596 B(Star), R(0), // | 1601 B(Star), R(0), // |
| 1597 B(Ldar), R(0), // | 1602 B(Ldar), R(0), // |
| 1598 B(Return) // | 1603 B(Return) // |
| 1599 }, | 1604 }, |
| 1600 -1}, | 1605 2, |
| 1606 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}}, |
| 1601 }; | 1607 }; |
| 1602 | 1608 |
| 1603 for (size_t i = 0; i < arraysize(snippets); i++) { | 1609 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1604 Handle<BytecodeArray> bytecode_array = | 1610 Handle<BytecodeArray> bytecode_array = |
| 1605 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | 1611 helper.MakeTopLevelBytecode(snippets[i].code_snippet); |
| 1606 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 1612 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
| 1607 } | 1613 } |
| 1608 } | 1614 } |
| 1609 | 1615 |
| 1610 | 1616 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1759 " x = x + 1;" | 1765 " x = x + 1;" |
| 1760 "}", | 1766 "}", |
| 1761 2 * kPointerSize, | 1767 2 * kPointerSize, |
| 1762 1, | 1768 1, |
| 1763 29, | 1769 29, |
| 1764 { | 1770 { |
| 1765 B(LdaZero), // | 1771 B(LdaZero), // |
| 1766 B(Star), R(0), // | 1772 B(Star), R(0), // |
| 1767 B(Ldar), R(0), // | 1773 B(Ldar), R(0), // |
| 1768 B(Star), R(1), // | 1774 B(Star), R(1), // |
| 1769 B(LdaSmi8), // | 1775 B(LdaSmi8), U8(1), // |
| 1770 U8(1), // | |
| 1771 B(TestEqual), R(1), // | 1776 B(TestEqual), R(1), // |
| 1772 B(JumpIfFalse), U8(4), // | 1777 B(JumpIfFalse), U8(4), // |
| 1773 B(Jump), U8(14), // | 1778 B(Jump), U8(14), // |
| 1774 B(Ldar), R(0), // | 1779 B(Ldar), R(0), // |
| 1775 B(Star), R(1), // | 1780 B(Star), R(1), // |
| 1776 B(LdaSmi8), U8(1), // | 1781 B(LdaSmi8), U8(1), // |
| 1777 B(Add), R(1), // | 1782 B(Add), R(1), // |
| 1778 B(Star), R(0), // | 1783 B(Star), R(0), // |
| 1779 B(Jump), U8(-22), // | 1784 B(Jump), U8(-22), // |
| 1780 B(LdaUndefined), // | 1785 B(LdaUndefined), // |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2598 } | 2603 } |
| 2599 | 2604 |
| 2600 | 2605 |
| 2601 TEST(TryCatch) { | 2606 TEST(TryCatch) { |
| 2602 InitializedHandleScope handle_scope; | 2607 InitializedHandleScope handle_scope; |
| 2603 BytecodeGeneratorHelper helper; | 2608 BytecodeGeneratorHelper helper; |
| 2604 | 2609 |
| 2605 // TODO(rmcilroy): modify tests when we have real try catch support. | 2610 // TODO(rmcilroy): modify tests when we have real try catch support. |
| 2606 ExpectedSnippet<int> snippets[] = { | 2611 ExpectedSnippet<int> snippets[] = { |
| 2607 {"try { return 1; } catch(e) { return 2; }", | 2612 {"try { return 1; } catch(e) { return 2; }", |
| 2608 0, | 2613 1 * kPointerSize, |
| 2609 1, | 2614 1, |
| 2610 5, | 2615 5, |
| 2611 { | 2616 { |
| 2612 B(LdaSmi8), U8(1), // | 2617 B(LdaSmi8), U8(1), // |
| 2613 B(Return), // | 2618 B(Return), // |
| 2614 B(LdaUndefined), // | 2619 B(LdaUndefined), // |
| 2615 B(Return), // | 2620 B(Return), // |
| 2616 }, | 2621 }, |
| 2617 0}, | 2622 0}, |
| 2618 }; | 2623 }; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2640 B(Star), R(0), // | 2645 B(Star), R(0), // |
| 2641 B(LdaSmi8), U8(2), // | 2646 B(LdaSmi8), U8(2), // |
| 2642 B(Star), R(0), // | 2647 B(Star), R(0), // |
| 2643 B(LdaSmi8), U8(3), // | 2648 B(LdaSmi8), U8(3), // |
| 2644 B(Star), R(0), // | 2649 B(Star), R(0), // |
| 2645 B(LdaUndefined), // | 2650 B(LdaUndefined), // |
| 2646 B(Return), // | 2651 B(Return), // |
| 2647 }, | 2652 }, |
| 2648 0}, | 2653 0}, |
| 2649 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", | 2654 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", |
| 2650 1 * kPointerSize, | 2655 2 * kPointerSize, |
| 2651 1, | 2656 1, |
| 2652 14, | 2657 14, |
| 2653 { | 2658 { |
| 2654 B(LdaSmi8), U8(1), // | 2659 B(LdaSmi8), U8(1), // |
| 2655 B(Star), R(0), // | 2660 B(Star), R(0), // |
| 2656 B(LdaSmi8), U8(2), // | 2661 B(LdaSmi8), U8(2), // |
| 2657 B(Star), R(0), // | 2662 B(Star), R(0), // |
| 2658 B(LdaSmi8), U8(3), // | 2663 B(LdaSmi8), U8(3), // |
| 2659 B(Star), R(0), // | 2664 B(Star), R(0), // |
| 2660 B(LdaUndefined), // | 2665 B(LdaUndefined), // |
| 2661 B(Return), // | 2666 B(Return), // |
| 2662 }, | 2667 }, |
| 2663 0}, | 2668 0}, |
| 2664 }; | 2669 }; |
| 2665 | 2670 |
| 2666 for (size_t i = 0; i < arraysize(snippets); i++) { | 2671 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2667 Handle<BytecodeArray> bytecode_array = | 2672 Handle<BytecodeArray> bytecode_array = |
| 2668 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2673 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 2669 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2674 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2670 } | 2675 } |
| 2671 } | 2676 } |
| 2672 | 2677 |
| 2678 |
| 2679 TEST(ContextVariables) { |
| 2680 InitializedHandleScope handle_scope; |
| 2681 BytecodeGeneratorHelper helper; |
| 2682 |
| 2683 int closure = Register::function_closure().index(); |
| 2684 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 2685 ExpectedSnippet<InstanceType> snippets[] = { |
| 2686 {"var a; return function() { a = 1; };", |
| 2687 1 * kPointerSize, |
| 2688 1, |
| 2689 12, |
| 2690 { |
| 2691 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2692 R(closure), U8(1), // |
| 2693 B(PushContext), R(0), // |
| 2694 B(LdaConstant), U8(0), // |
| 2695 B(CreateClosure), U8(0), // |
| 2696 B(Return), // |
| 2697 }, |
| 2698 1, |
| 2699 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2700 {"var a = 1; return function() { a = 2; };", |
| 2701 1 * kPointerSize, |
| 2702 1, |
| 2703 17, |
| 2704 { |
| 2705 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2706 R(closure), U8(1), // |
| 2707 B(PushContext), R(0), // |
| 2708 B(LdaSmi8), U8(1), // |
| 2709 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 2710 B(LdaConstant), U8(0), // |
| 2711 B(CreateClosure), U8(0), // |
| 2712 B(Return), // |
| 2713 }, |
| 2714 1, |
| 2715 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2716 {"var a = 1; var b = 2; return function() { a = 2; b = 3 };", |
| 2717 1 * kPointerSize, |
| 2718 1, |
| 2719 22, |
| 2720 { |
| 2721 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2722 R(closure), U8(1), // |
| 2723 B(PushContext), R(0), // |
| 2724 B(LdaSmi8), U8(1), // |
| 2725 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 2726 B(LdaSmi8), U8(2), // |
| 2727 B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
| 2728 B(LdaConstant), U8(0), // |
| 2729 B(CreateClosure), U8(0), // |
| 2730 B(Return), // |
| 2731 }, |
| 2732 1, |
| 2733 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2734 {"var a; (function() { a = 2; })(); return a;", |
| 2735 3 * kPointerSize, |
| 2736 1, |
| 2737 24, |
| 2738 { |
| 2739 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2740 R(closure), U8(1), // |
| 2741 B(PushContext), R(0), // |
| 2742 B(LdaUndefined), // |
| 2743 B(Star), R(2), // |
| 2744 B(LdaConstant), U8(0), // |
| 2745 B(CreateClosure), U8(0), // |
| 2746 B(Star), R(1), // |
| 2747 B(Call), R(1), R(2), U8(0), // |
| 2748 B(LdaContextSlot), R(0), U8(first_context_slot), // |
| 2749 B(Return), // |
| 2750 }, |
| 2751 1, |
| 2752 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2753 {"'use strict'; let a = 1; { let b = 2; return function() { a + b; }; }", |
| 2754 4 * kPointerSize, |
| 2755 1, |
| 2756 51, |
| 2757 { |
| 2758 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2759 R(closure), U8(1), // |
| 2760 B(PushContext), R(0), // |
| 2761 B(LdaTheHole), // |
| 2762 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 2763 B(LdaConstant), U8(0), // |
| 2764 B(LdaSmi8), U8(1), // |
| 2765 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 2766 B(LdaConstant), U8(1), // |
| 2767 B(Star), R(2), // |
| 2768 B(Ldar), R(closure), // |
| 2769 B(Star), R(3), // |
| 2770 B(CallRuntime), U16(Runtime::kPushBlockContext), R(2), U8(2), // |
| 2771 B(PushContext), R(1), // |
| 2772 B(LdaTheHole), // |
| 2773 B(StaContextSlot), R(1), U8(first_context_slot), // |
| 2774 B(LdaSmi8), U8(2), // |
| 2775 B(StaContextSlot), R(1), U8(first_context_slot), // |
| 2776 B(LdaConstant), U8(2), // |
| 2777 B(CreateClosure), U8(0), // |
| 2778 B(Return), // |
| 2779 // TODO(rmcilroy): Dead code after this point due to return in nested |
| 2780 // block - investigate eliminating this. |
| 2781 B(PopContext), R(0), |
| 2782 B(LdaUndefined), // |
| 2783 B(Return), // |
| 2784 }, |
| 2785 3, |
| 2786 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 2787 InstanceType::FIXED_ARRAY_TYPE, |
| 2788 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2789 }; |
| 2790 |
| 2791 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2792 Handle<BytecodeArray> bytecode_array = |
| 2793 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 2794 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2795 } |
| 2796 } |
| 2797 |
| 2798 |
| 2799 TEST(ContextParameters) { |
| 2800 InitializedHandleScope handle_scope; |
| 2801 BytecodeGeneratorHelper helper; |
| 2802 |
| 2803 int closure = Register::function_closure().index(); |
| 2804 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 2805 ExpectedSnippet<InstanceType> snippets[] = { |
| 2806 {"function f(arg1) { return function() { arg1 = 2; }; }", |
| 2807 1 * kPointerSize, |
| 2808 2, |
| 2809 17, |
| 2810 { |
| 2811 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2812 R(closure), U8(1), // |
| 2813 B(PushContext), R(0), // |
| 2814 B(Ldar), R(helper.kLastParamIndex), // |
| 2815 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 2816 B(LdaConstant), U8(0), // |
| 2817 B(CreateClosure), U8(0), // |
| 2818 B(Return), // |
| 2819 }, |
| 2820 1, |
| 2821 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2822 {"function f(arg1) { var a = function() { arg1 = 2; }; return arg1; }", |
| 2823 2 * kPointerSize, |
| 2824 2, |
| 2825 22, |
| 2826 { |
| 2827 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2828 R(closure), U8(1), // |
| 2829 B(PushContext), R(1), // |
| 2830 B(Ldar), R(helper.kLastParamIndex), // |
| 2831 B(StaContextSlot), R(1), U8(first_context_slot), // |
| 2832 B(LdaConstant), U8(0), // |
| 2833 B(CreateClosure), U8(0), // |
| 2834 B(Star), R(0), // |
| 2835 B(LdaContextSlot), R(1), U8(first_context_slot), // |
| 2836 B(Return), // |
| 2837 }, |
| 2838 1, |
| 2839 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2840 {"function f(a1, a2, a3, a4) { return function() { a1 = a3; }; }", |
| 2841 1 * kPointerSize, |
| 2842 5, |
| 2843 22, |
| 2844 { |
| 2845 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2846 R(closure), U8(1), // |
| 2847 B(PushContext), R(0), // |
| 2848 B(Ldar), R(helper.kLastParamIndex - 3), // |
| 2849 B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
| 2850 B(Ldar), R(helper.kLastParamIndex -1), // |
| 2851 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 2852 B(LdaConstant), U8(0), // |
| 2853 B(CreateClosure), U8(0), // |
| 2854 B(Return), // |
| 2855 }, |
| 2856 1, |
| 2857 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2858 {"function f() { var self = this; return function() { self = 2; }; }", |
| 2859 1 * kPointerSize, |
| 2860 1, |
| 2861 17, |
| 2862 { |
| 2863 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 2864 R(closure), U8(1), // |
| 2865 B(PushContext), R(0), // |
| 2866 B(Ldar), R(helper.kLastParamIndex), // |
| 2867 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 2868 B(LdaConstant), U8(0), // |
| 2869 B(CreateClosure), U8(0), // |
| 2870 B(Return), // |
| 2871 }, |
| 2872 1, |
| 2873 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2874 }; |
| 2875 |
| 2876 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2877 Handle<BytecodeArray> bytecode_array = |
| 2878 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 2879 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2880 } |
| 2881 } |
| 2882 |
| 2673 } // namespace interpreter | 2883 } // namespace interpreter |
| 2674 } // namespace internal | 2884 } // namespace internal |
| 2675 } // namespace v8 | 2885 } // namespace v8 |
| OLD | NEW |