OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
8 | 8 |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 1648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 // If result_saved is true the result is on top of the stack. If | 1659 // If result_saved is true the result is on top of the stack. If |
1660 // result_saved is false the result is in rax. | 1660 // result_saved is false the result is in rax. |
1661 bool result_saved = false; | 1661 bool result_saved = false; |
1662 | 1662 |
1663 // Mark all computed expressions that are bound to a key that | 1663 // Mark all computed expressions that are bound to a key that |
1664 // is shadowed by a later occurrence of the same key. For the | 1664 // is shadowed by a later occurrence of the same key. For the |
1665 // marked expressions, no store code is emitted. | 1665 // marked expressions, no store code is emitted. |
1666 expr->CalculateEmitStore(zone()); | 1666 expr->CalculateEmitStore(zone()); |
1667 | 1667 |
1668 AccessorTable accessor_table(zone()); | 1668 AccessorTable accessor_table(zone()); |
1669 for (int i = 0; i < expr->properties()->length(); i++) { | 1669 int property_index = 0; |
1670 ObjectLiteral::Property* property = expr->properties()->at(i); | 1670 for (; property_index < expr->properties()->length(); property_index++) { |
| 1671 ObjectLiteral::Property* property = expr->properties()->at(property_index); |
1671 if (property->IsCompileTimeValue()) continue; | 1672 if (property->IsCompileTimeValue()) continue; |
| 1673 if (property->kind() == ObjectLiteral::Property::COMPUTED_NAME) break; |
1672 | 1674 |
1673 Literal* key = property->key(); | 1675 Literal* key = property->key()->AsLiteral(); |
1674 Expression* value = property->value(); | 1676 Expression* value = property->value(); |
1675 if (!result_saved) { | 1677 if (!result_saved) { |
1676 __ Push(rax); // Save result on the stack | 1678 __ Push(rax); // Save result on the stack |
1677 result_saved = true; | 1679 result_saved = true; |
1678 } | 1680 } |
1679 switch (property->kind()) { | 1681 switch (property->kind()) { |
1680 case ObjectLiteral::Property::CONSTANT: | 1682 case ObjectLiteral::Property::CONSTANT: |
| 1683 case ObjectLiteral::Property::COMPUTED_NAME: |
1681 UNREACHABLE(); | 1684 UNREACHABLE(); |
1682 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | 1685 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
1683 ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); | 1686 ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
1684 // Fall through. | 1687 // Fall through. |
1685 case ObjectLiteral::Property::COMPUTED: | 1688 case ObjectLiteral::Property::COMPUTED: |
1686 if (key->value()->IsInternalizedString()) { | 1689 if (key->value()->IsInternalizedString()) { |
1687 if (property->emit_store()) { | 1690 if (property->emit_store()) { |
1688 VisitForAccumulatorValue(value); | 1691 VisitForAccumulatorValue(value); |
1689 __ Move(rcx, key->value()); | 1692 __ Move(rcx, key->value()); |
1690 __ movp(rdx, Operand(rsp, 0)); | 1693 __ movp(rdx, Operand(rsp, 0)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 it != accessor_table.end(); | 1732 it != accessor_table.end(); |
1730 ++it) { | 1733 ++it) { |
1731 __ Push(Operand(rsp, 0)); // Duplicate receiver. | 1734 __ Push(Operand(rsp, 0)); // Duplicate receiver. |
1732 VisitForStackValue(it->first); | 1735 VisitForStackValue(it->first); |
1733 EmitAccessor(it->second->getter); | 1736 EmitAccessor(it->second->getter); |
1734 EmitAccessor(it->second->setter); | 1737 EmitAccessor(it->second->setter); |
1735 __ Push(Smi::FromInt(NONE)); | 1738 __ Push(Smi::FromInt(NONE)); |
1736 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); | 1739 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
1737 } | 1740 } |
1738 | 1741 |
| 1742 // Object literals have two parts. The "static" part on the left contains no |
| 1743 // computed property names, and so we can compute its map ahead of time; see |
| 1744 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part |
| 1745 // starts with the first computed property name, and continues with all |
| 1746 // properties to its right. All the code from above initializes the static |
| 1747 // component of the object literal, and arranges for the map of the result to |
| 1748 // reflect the static order in which the keys appear. For the dynamic |
| 1749 // properties, we compile them into a series of "SetOwnProperty" runtime |
| 1750 // calls. This will preserve insertion order. |
| 1751 for (; property_index < expr->properties()->length(); property_index++) { |
| 1752 ObjectLiteral::Property* property = expr->properties()->at(property_index); |
| 1753 |
| 1754 Expression* key = property->key(); |
| 1755 Expression* value = property->value(); |
| 1756 if (!result_saved) { |
| 1757 __ Push(rax); // Save result on the stack |
| 1758 result_saved = true; |
| 1759 } |
| 1760 |
| 1761 switch (property->kind()) { |
| 1762 case ObjectLiteral::Property::CONSTANT: |
| 1763 case ObjectLiteral::Property::COMPUTED_NAME: |
| 1764 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1765 case ObjectLiteral::Property::COMPUTED: |
| 1766 __ Push(Operand(rsp, 0)); // Duplicate receiver. |
| 1767 VisitForStackValue(key); |
| 1768 VisitForStackValue(value); |
| 1769 if (property->emit_store()) { |
| 1770 __ CallRuntime(Runtime::kSetOwnProperty, 3); |
| 1771 } else { |
| 1772 __ Drop(3); |
| 1773 } |
| 1774 break; |
| 1775 case ObjectLiteral::Property::PROTOTYPE: |
| 1776 __ Push(Operand(rsp, 0)); // Duplicate receiver. |
| 1777 VisitForStackValue(value); |
| 1778 if (property->emit_store()) { |
| 1779 __ CallRuntime(Runtime::kSetPrototype, 2); |
| 1780 } else { |
| 1781 __ Drop(2); |
| 1782 } |
| 1783 break; |
| 1784 // TODO(wingo): Allow computed names for accessor properties. Currently |
| 1785 // disallowed by the parser. |
| 1786 case ObjectLiteral::Property::GETTER: { |
| 1787 ObjectLiteral::Accessors *accessors = |
| 1788 accessor_table.lookup(key->AsLiteral())->second; |
| 1789 accessors->getter = value; |
| 1790 |
| 1791 __ Push(Operand(rsp, 0)); // Duplicate receiver. |
| 1792 VisitForStackValue(key); |
| 1793 EmitAccessor(accessors->getter); |
| 1794 EmitAccessor(accessors->setter); |
| 1795 __ Push(Smi::FromInt(NONE)); |
| 1796 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
| 1797 break; |
| 1798 } |
| 1799 case ObjectLiteral::Property::SETTER: { |
| 1800 ObjectLiteral::Accessors *accessors = |
| 1801 accessor_table.lookup(key->AsLiteral())->second; |
| 1802 accessors->setter = value; |
| 1803 |
| 1804 __ Push(Operand(rsp, 0)); // Duplicate receiver. |
| 1805 VisitForStackValue(key); |
| 1806 EmitAccessor(accessors->getter); |
| 1807 EmitAccessor(accessors->setter); |
| 1808 __ Push(Smi::FromInt(NONE)); |
| 1809 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
| 1810 break; |
| 1811 } |
| 1812 } |
| 1813 } |
| 1814 |
1739 if (expr->has_function()) { | 1815 if (expr->has_function()) { |
1740 ASSERT(result_saved); | 1816 ASSERT(result_saved); |
1741 __ Push(Operand(rsp, 0)); | 1817 __ Push(Operand(rsp, 0)); |
1742 __ CallRuntime(Runtime::kToFastProperties, 1); | 1818 __ CallRuntime(Runtime::kToFastProperties, 1); |
1743 } | 1819 } |
1744 | 1820 |
1745 if (result_saved) { | 1821 if (result_saved) { |
1746 context()->PlugTOS(); | 1822 context()->PlugTOS(); |
1747 } else { | 1823 } else { |
1748 context()->Plug(rax); | 1824 context()->Plug(rax); |
(...skipping 3061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4810 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4886 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4811 Assembler::target_address_at(call_target_address, | 4887 Assembler::target_address_at(call_target_address, |
4812 unoptimized_code)); | 4888 unoptimized_code)); |
4813 return OSR_AFTER_STACK_CHECK; | 4889 return OSR_AFTER_STACK_CHECK; |
4814 } | 4890 } |
4815 | 4891 |
4816 | 4892 |
4817 } } // namespace v8::internal | 4893 } } // namespace v8::internal |
4818 | 4894 |
4819 #endif // V8_TARGET_ARCH_X64 | 4895 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |