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_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
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 1582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1593 expr->BuildConstantProperties(isolate()); | 1593 expr->BuildConstantProperties(isolate()); |
1594 Handle<FixedArray> constant_properties = expr->constant_properties(); | 1594 Handle<FixedArray> constant_properties = expr->constant_properties(); |
1595 int flags = expr->fast_elements() | 1595 int flags = expr->fast_elements() |
1596 ? ObjectLiteral::kFastElements | 1596 ? ObjectLiteral::kFastElements |
1597 : ObjectLiteral::kNoFlags; | 1597 : ObjectLiteral::kNoFlags; |
1598 flags |= expr->has_function() | 1598 flags |= expr->has_function() |
1599 ? ObjectLiteral::kHasFunction | 1599 ? ObjectLiteral::kHasFunction |
1600 : ObjectLiteral::kNoFlags; | 1600 : ObjectLiteral::kNoFlags; |
1601 int properties_count = constant_properties->length() / 2; | 1601 int properties_count = constant_properties->length() / 2; |
1602 if (expr->may_store_doubles() || expr->depth() > 1 || | 1602 if (expr->may_store_doubles() || expr->depth() > 1 || |
1603 masm()->serializer_enabled() || | 1603 masm()->serializer_enabled() || flags != ObjectLiteral::kFastElements || |
1604 flags != ObjectLiteral::kFastElements || | |
1605 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { | 1604 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
1606 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1605 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1607 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); | 1606 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
1608 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1607 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
1609 __ push(Immediate(constant_properties)); | 1608 __ push(Immediate(constant_properties)); |
1610 __ push(Immediate(Smi::FromInt(flags))); | 1609 __ push(Immediate(Smi::FromInt(flags))); |
1611 __ CallRuntime(Runtime::kHiddenCreateObjectLiteral, 4); | 1610 __ CallRuntime(Runtime::kHiddenCreateObjectLiteral, 4); |
1612 } else { | 1611 } else { |
1613 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1612 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1614 __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); | 1613 __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
1615 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); | 1614 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
1616 __ mov(ecx, Immediate(constant_properties)); | 1615 __ mov(ecx, Immediate(constant_properties)); |
1617 __ mov(edx, Immediate(Smi::FromInt(flags))); | 1616 __ mov(edx, Immediate(Smi::FromInt(flags))); |
1618 FastCloneShallowObjectStub stub(isolate(), properties_count); | 1617 FastCloneShallowObjectStub stub(isolate(), properties_count); |
1619 __ CallStub(&stub); | 1618 __ CallStub(&stub); |
1620 } | 1619 } |
1621 | 1620 |
1622 // If result_saved is true the result is on top of the stack. If | 1621 // If result_saved is true the result is on top of the stack. If |
1623 // result_saved is false the result is in eax. | 1622 // result_saved is false the result is in eax. |
1624 bool result_saved = false; | 1623 bool result_saved = false; |
1625 | 1624 |
1626 // Mark all computed expressions that are bound to a key that | 1625 // Mark all computed expressions that are bound to a key that |
1627 // is shadowed by a later occurrence of the same key. For the | 1626 // is shadowed by a later occurrence of the same key. For the |
1628 // marked expressions, no store code is emitted. | 1627 // marked expressions, no store code is emitted. |
1629 expr->CalculateEmitStore(zone()); | 1628 expr->CalculateEmitStore(zone()); |
1630 | 1629 |
1631 AccessorTable accessor_table(zone()); | 1630 AccessorTable accessor_table(zone()); |
1632 for (int i = 0; i < expr->properties()->length(); i++) { | 1631 int property_index = 0; |
1633 ObjectLiteral::Property* property = expr->properties()->at(i); | 1632 for (; property_index < expr->properties()->length(); property_index++) { |
1633 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
1634 if (property->IsCompileTimeValue()) continue; | 1634 if (property->IsCompileTimeValue()) continue; |
1635 if (property->kind() == ObjectLiteral::Property::COMPUTED_NAME) break; | |
1635 | 1636 |
1636 Literal* key = property->key(); | 1637 Literal* key = property->key()->AsLiteral(); |
1637 Expression* value = property->value(); | 1638 Expression* value = property->value(); |
1638 if (!result_saved) { | 1639 if (!result_saved) { |
1639 __ push(eax); // Save result on the stack | 1640 __ push(eax); // Save result on the stack |
1640 result_saved = true; | 1641 result_saved = true; |
1641 } | 1642 } |
1642 switch (property->kind()) { | 1643 switch (property->kind()) { |
1643 case ObjectLiteral::Property::CONSTANT: | 1644 case ObjectLiteral::Property::CONSTANT: |
1645 case ObjectLiteral::Property::COMPUTED_NAME: | |
1644 UNREACHABLE(); | 1646 UNREACHABLE(); |
1645 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | 1647 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
1646 ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); | 1648 ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
1647 // Fall through. | 1649 // Fall through. |
1648 case ObjectLiteral::Property::COMPUTED: | 1650 case ObjectLiteral::Property::COMPUTED: |
1649 if (key->value()->IsInternalizedString()) { | 1651 if (key->value()->IsInternalizedString()) { |
1650 if (property->emit_store()) { | 1652 if (property->emit_store()) { |
1651 VisitForAccumulatorValue(value); | 1653 VisitForAccumulatorValue(value); |
1652 __ mov(ecx, Immediate(key->value())); | 1654 __ mov(ecx, Immediate(key->value())); |
1653 __ mov(edx, Operand(esp, 0)); | 1655 __ mov(edx, Operand(esp, 0)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1692 it != accessor_table.end(); | 1694 it != accessor_table.end(); |
1693 ++it) { | 1695 ++it) { |
1694 __ push(Operand(esp, 0)); // Duplicate receiver. | 1696 __ push(Operand(esp, 0)); // Duplicate receiver. |
1695 VisitForStackValue(it->first); | 1697 VisitForStackValue(it->first); |
1696 EmitAccessor(it->second->getter); | 1698 EmitAccessor(it->second->getter); |
1697 EmitAccessor(it->second->setter); | 1699 EmitAccessor(it->second->setter); |
1698 __ push(Immediate(Smi::FromInt(NONE))); | 1700 __ push(Immediate(Smi::FromInt(NONE))); |
1699 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); | 1701 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
1700 } | 1702 } |
1701 | 1703 |
1704 // Object literals have two parts. The "static" part on the left contains no | |
rossberg
2014/06/13 15:19:24
I'm not convinced that it's best to duplicate this
wingo
2014/06/16 08:32:27
I tried to do this at first, but ran into problems
rossberg
2014/06/18 14:13:40
Perhaps this problem also goes away with the spec
| |
1705 // computed property names, and so we can compute its map ahead of time; see | |
1706 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part | |
1707 // starts with the first computed property name, and continues with all | |
1708 // properties to its right. All the code from above initializes the static | |
1709 // component of the object literal, and arranges for the map of the result to | |
1710 // reflect the static order in which the keys appear. For the dynamic | |
1711 // properties, we compile them into a series of "PutOwnProperty" runtime | |
1712 // calls. This will preserve insertion order. | |
1713 for (; property_index < expr->properties()->length(); property_index++) { | |
1714 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
1715 | |
1716 Expression* key = property->key(); | |
1717 Expression* value = property->value(); | |
1718 if (!result_saved) { | |
1719 __ push(eax); // Save result on the stack | |
1720 result_saved = true; | |
1721 } | |
1722 | |
1723 switch (property->kind()) { | |
1724 case ObjectLiteral::Property::CONSTANT: | |
1725 case ObjectLiteral::Property::COMPUTED_NAME: | |
1726 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
1727 case ObjectLiteral::Property::COMPUTED: | |
1728 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1729 VisitForStackValue(key); | |
1730 VisitForStackValue(value); | |
1731 if (property->emit_store()) { | |
1732 __ CallRuntime(Runtime::kPutOwnProperty, 3); | |
1733 } else { | |
1734 __ Drop(3); | |
1735 } | |
1736 break; | |
1737 case ObjectLiteral::Property::PROTOTYPE: | |
1738 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1739 VisitForStackValue(value); | |
1740 if (property->emit_store()) { | |
1741 __ CallRuntime(Runtime::kSetPrototype, 2); | |
1742 } else { | |
1743 __ Drop(2); | |
1744 } | |
1745 break; | |
1746 case ObjectLiteral::Property::GETTER: { | |
1747 ObjectLiteral::Accessors *accessors = | |
1748 accessor_table.lookup(key->AsLiteral())->second; | |
1749 accessors->getter = value; | |
1750 | |
1751 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1752 VisitForStackValue(key); | |
1753 EmitAccessor(accessors->getter); | |
1754 EmitAccessor(accessors->setter); | |
1755 __ push(Immediate(Smi::FromInt(NONE))); | |
1756 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); | |
1757 break; | |
1758 } | |
1759 case ObjectLiteral::Property::SETTER: { | |
1760 ObjectLiteral::Accessors *accessors = | |
1761 accessor_table.lookup(key->AsLiteral())->second; | |
rossberg
2014/06/13 15:19:24
Is this correct? Can't accessors have computed pro
wingo
2014/06/16 08:32:27
According to spec, yes, but not in the current pat
| |
1762 accessors->setter = value; | |
1763 | |
1764 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1765 VisitForStackValue(key); | |
1766 EmitAccessor(accessors->getter); | |
1767 EmitAccessor(accessors->setter); | |
1768 __ push(Immediate(Smi::FromInt(NONE))); | |
1769 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); | |
1770 break; | |
1771 } | |
1772 } | |
1773 } | |
1774 | |
1702 if (expr->has_function()) { | 1775 if (expr->has_function()) { |
1703 ASSERT(result_saved); | 1776 ASSERT(result_saved); |
1704 __ push(Operand(esp, 0)); | 1777 __ push(Operand(esp, 0)); |
1705 __ CallRuntime(Runtime::kToFastProperties, 1); | 1778 __ CallRuntime(Runtime::kToFastProperties, 1); |
1706 } | 1779 } |
1707 | 1780 |
1708 if (result_saved) { | 1781 if (result_saved) { |
1709 context()->PlugTOS(); | 1782 context()->PlugTOS(); |
1710 } else { | 1783 } else { |
1711 context()->Plug(eax); | 1784 context()->Plug(eax); |
(...skipping 3091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4803 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4876 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4804 Assembler::target_address_at(call_target_address, | 4877 Assembler::target_address_at(call_target_address, |
4805 unoptimized_code)); | 4878 unoptimized_code)); |
4806 return OSR_AFTER_STACK_CHECK; | 4879 return OSR_AFTER_STACK_CHECK; |
4807 } | 4880 } |
4808 | 4881 |
4809 | 4882 |
4810 } } // namespace v8::internal | 4883 } } // namespace v8::internal |
4811 | 4884 |
4812 #endif // V8_TARGET_ARCH_IA32 | 4885 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |