Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/ia32/full-codegen-ia32.cc

Issue 332443002: Add support for computed property names in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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 "SetOwnProperty" 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::kSetOwnProperty, 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 // TODO(wingo): Allow computed names for accessor properties. Currently
1747 // disallowed by the parser.
1748 case ObjectLiteral::Property::GETTER: {
1749 ObjectLiteral::Accessors *accessors =
1750 accessor_table.lookup(key->AsLiteral())->second;
1751 accessors->getter = value;
1752
1753 __ push(Operand(esp, 0)); // Duplicate receiver.
1754 VisitForStackValue(key);
1755 EmitAccessor(accessors->getter);
1756 EmitAccessor(accessors->setter);
1757 __ push(Immediate(Smi::FromInt(NONE)));
1758 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5);
1759 break;
1760 }
1761 case ObjectLiteral::Property::SETTER: {
1762 ObjectLiteral::Accessors *accessors =
1763 accessor_table.lookup(key->AsLiteral())->second;
1764 accessors->setter = value;
1765
1766 __ push(Operand(esp, 0)); // Duplicate receiver.
1767 VisitForStackValue(key);
1768 EmitAccessor(accessors->getter);
1769 EmitAccessor(accessors->setter);
1770 __ push(Immediate(Smi::FromInt(NONE)));
1771 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5);
1772 break;
1773 }
1774 }
1775 }
1776
1702 if (expr->has_function()) { 1777 if (expr->has_function()) {
1703 ASSERT(result_saved); 1778 ASSERT(result_saved);
1704 __ push(Operand(esp, 0)); 1779 __ push(Operand(esp, 0));
1705 __ CallRuntime(Runtime::kToFastProperties, 1); 1780 __ CallRuntime(Runtime::kToFastProperties, 1);
1706 } 1781 }
1707 1782
1708 if (result_saved) { 1783 if (result_saved) {
1709 context()->PlugTOS(); 1784 context()->PlugTOS();
1710 } else { 1785 } else {
1711 context()->Plug(eax); 1786 context()->Plug(eax);
(...skipping 3091 matching lines...) Expand 10 before | Expand all | Expand 10 after
4803 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 4878 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
4804 Assembler::target_address_at(call_target_address, 4879 Assembler::target_address_at(call_target_address,
4805 unoptimized_code)); 4880 unoptimized_code));
4806 return OSR_AFTER_STACK_CHECK; 4881 return OSR_AFTER_STACK_CHECK;
4807 } 4882 }
4808 4883
4809 4884
4810 } } // namespace v8::internal 4885 } } // namespace v8::internal
4811 4886
4812 #endif // V8_TARGET_ARCH_IA32 4887 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/mips/full-codegen-mips.cc » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698