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

Side by Side Diff: src/x87/full-codegen-x87.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: Dynamic part of object literal initialized with PutOwnProperty 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_X87 7 #if V8_TARGET_ARCH_X87
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 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 // If result_saved is true the result is on top of the stack. If 1619 // If result_saved is true the result is on top of the stack. If
1620 // result_saved is false the result is in eax. 1620 // result_saved is false the result is in eax.
1621 bool result_saved = false; 1621 bool result_saved = false;
1622 1622
1623 // Mark all computed expressions that are bound to a key that 1623 // Mark all computed expressions that are bound to a key that
1624 // is shadowed by a later occurrence of the same key. For the 1624 // is shadowed by a later occurrence of the same key. For the
1625 // marked expressions, no store code is emitted. 1625 // marked expressions, no store code is emitted.
1626 expr->CalculateEmitStore(zone()); 1626 expr->CalculateEmitStore(zone());
1627 1627
1628 AccessorTable accessor_table(zone()); 1628 AccessorTable accessor_table(zone());
1629 for (int i = 0; i < expr->properties()->length(); i++) { 1629 int property_index = 0;
1630 ObjectLiteral::Property* property = expr->properties()->at(i); 1630 for (; property_index < expr->properties()->length(); property_index++) {
1631 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1631 if (property->IsCompileTimeValue()) continue; 1632 if (property->IsCompileTimeValue()) continue;
1633 if (property->kind() == ObjectLiteral::Property::COMPUTED_NAME) break;
1632 1634
1633 Literal* key = property->key(); 1635 Literal* key = property->key()->AsLiteral();
1634 Expression* value = property->value(); 1636 Expression* value = property->value();
1635 if (!result_saved) { 1637 if (!result_saved) {
1636 __ push(eax); // Save result on the stack 1638 __ push(eax); // Save result on the stack
1637 result_saved = true; 1639 result_saved = true;
1638 } 1640 }
1639 switch (property->kind()) { 1641 switch (property->kind()) {
1640 case ObjectLiteral::Property::CONSTANT: 1642 case ObjectLiteral::Property::CONSTANT:
1643 case ObjectLiteral::Property::COMPUTED_NAME:
1641 UNREACHABLE(); 1644 UNREACHABLE();
1642 case ObjectLiteral::Property::MATERIALIZED_LITERAL: 1645 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1643 ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); 1646 ASSERT(!CompileTimeValue::IsCompileTimeValue(value));
1644 // Fall through. 1647 // Fall through.
1645 case ObjectLiteral::Property::COMPUTED: 1648 case ObjectLiteral::Property::COMPUTED:
1646 if (key->value()->IsInternalizedString()) { 1649 if (key->value()->IsInternalizedString()) {
1647 if (property->emit_store()) { 1650 if (property->emit_store()) {
1648 VisitForAccumulatorValue(value); 1651 VisitForAccumulatorValue(value);
1649 __ mov(ecx, Immediate(key->value())); 1652 __ mov(ecx, Immediate(key->value()));
1650 __ mov(edx, Operand(esp, 0)); 1653 __ mov(edx, Operand(esp, 0));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 it != accessor_table.end(); 1692 it != accessor_table.end();
1690 ++it) { 1693 ++it) {
1691 __ push(Operand(esp, 0)); // Duplicate receiver. 1694 __ push(Operand(esp, 0)); // Duplicate receiver.
1692 VisitForStackValue(it->first); 1695 VisitForStackValue(it->first);
1693 EmitAccessor(it->second->getter); 1696 EmitAccessor(it->second->getter);
1694 EmitAccessor(it->second->setter); 1697 EmitAccessor(it->second->setter);
1695 __ push(Immediate(Smi::FromInt(NONE))); 1698 __ push(Immediate(Smi::FromInt(NONE)));
1696 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); 1699 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5);
1697 } 1700 }
1698 1701
1702 // Object literals have two parts. The "static" part on the left contains no
1703 // computed property names, and so we can compute its map ahead of time; see
1704 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part
1705 // starts with the first computed property name, and continues with all
1706 // properties to its right. All the code from above initializes the static
1707 // component of the object literal, and arranges for the map of the result to
1708 // reflect the static order in which the keys appear. For the dynamic
1709 // properties, we compile them into a series of "PutOwnProperty" runtime
1710 // calls. This will preserve insertion order.
1711 for (; property_index < expr->properties()->length(); property_index++) {
1712 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1713
1714 Expression* key = property->key();
1715 Expression* value = property->value();
1716 if (!result_saved) {
1717 __ push(eax); // Save result on the stack
1718 result_saved = true;
1719 }
1720
1721 switch (property->kind()) {
1722 case ObjectLiteral::Property::CONSTANT:
1723 case ObjectLiteral::Property::COMPUTED_NAME:
1724 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1725 case ObjectLiteral::Property::COMPUTED:
1726 __ push(Operand(esp, 0)); // Duplicate receiver.
1727 VisitForStackValue(key);
1728 VisitForStackValue(value);
1729 if (property->emit_store()) {
1730 __ CallRuntime(Runtime::kPutOwnProperty, 3);
1731 } else {
1732 __ Drop(3);
1733 }
1734 break;
1735 case ObjectLiteral::Property::PROTOTYPE:
1736 __ push(Operand(esp, 0)); // Duplicate receiver.
1737 VisitForStackValue(value);
1738 if (property->emit_store()) {
1739 __ CallRuntime(Runtime::kSetPrototype, 2);
1740 } else {
1741 __ Drop(2);
1742 }
1743 break;
1744 case ObjectLiteral::Property::GETTER: {
1745 ObjectLiteral::Accessors *accessors =
1746 accessor_table.lookup(key->AsLiteral())->second;
1747 accessors->getter = value;
1748
1749 __ push(Operand(esp, 0)); // Duplicate receiver.
1750 VisitForStackValue(key);
1751 EmitAccessor(accessors->getter);
1752 EmitAccessor(accessors->setter);
1753 __ push(Immediate(Smi::FromInt(NONE)));
1754 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5);
1755 break;
1756 }
1757 case ObjectLiteral::Property::SETTER: {
1758 ObjectLiteral::Accessors *accessors =
1759 accessor_table.lookup(key->AsLiteral())->second;
1760 accessors->setter = value;
1761
1762 __ push(Operand(esp, 0)); // Duplicate receiver.
1763 VisitForStackValue(key);
1764 EmitAccessor(accessors->getter);
1765 EmitAccessor(accessors->setter);
1766 __ push(Immediate(Smi::FromInt(NONE)));
1767 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5);
1768 break;
1769 }
1770 }
1771 }
1772
1699 if (expr->has_function()) { 1773 if (expr->has_function()) {
1700 ASSERT(result_saved); 1774 ASSERT(result_saved);
1701 __ push(Operand(esp, 0)); 1775 __ push(Operand(esp, 0));
1702 __ CallRuntime(Runtime::kToFastProperties, 1); 1776 __ CallRuntime(Runtime::kToFastProperties, 1);
1703 } 1777 }
1704 1778
1705 if (result_saved) { 1779 if (result_saved) {
1706 context()->PlugTOS(); 1780 context()->PlugTOS();
1707 } else { 1781 } else {
1708 context()->Plug(eax); 1782 context()->Plug(eax);
(...skipping 3087 matching lines...) Expand 10 before | Expand all | Expand 10 after
4796 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 4870 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
4797 Assembler::target_address_at(call_target_address, 4871 Assembler::target_address_at(call_target_address,
4798 unoptimized_code)); 4872 unoptimized_code));
4799 return OSR_AFTER_STACK_CHECK; 4873 return OSR_AFTER_STACK_CHECK;
4800 } 4874 }
4801 4875
4802 4876
4803 } } // namespace v8::internal 4877 } } // namespace v8::internal
4804 4878
4805 #endif // V8_TARGET_ARCH_X87 4879 #endif // V8_TARGET_ARCH_X87
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698