Index: src/x87/full-codegen-x87.cc |
diff --git a/src/x87/full-codegen-x87.cc b/src/x87/full-codegen-x87.cc |
index d5a98865846e1eefc94507abc8cf1ab6469f292c..c8625758485b518b25188520b575d2eac1802dfb 100644 |
--- a/src/x87/full-codegen-x87.cc |
+++ b/src/x87/full-codegen-x87.cc |
@@ -1626,11 +1626,13 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
expr->CalculateEmitStore(zone()); |
AccessorTable accessor_table(zone()); |
- for (int i = 0; i < expr->properties()->length(); i++) { |
- ObjectLiteral::Property* property = expr->properties()->at(i); |
+ int property_index = 0; |
+ for (; property_index < expr->properties()->length(); property_index++) { |
+ ObjectLiteral::Property* property = expr->properties()->at(property_index); |
if (property->IsCompileTimeValue()) continue; |
+ if (property->kind() == ObjectLiteral::Property::COMPUTED_NAME) break; |
- Literal* key = property->key(); |
+ Literal* key = property->key()->AsLiteral(); |
Expression* value = property->value(); |
if (!result_saved) { |
__ push(eax); // Save result on the stack |
@@ -1638,6 +1640,7 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
} |
switch (property->kind()) { |
case ObjectLiteral::Property::CONSTANT: |
+ case ObjectLiteral::Property::COMPUTED_NAME: |
UNREACHABLE(); |
case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
@@ -1696,6 +1699,79 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
__ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
} |
+ // Object literals have two parts. The "static" part on the left contains no |
+ // computed property names, and so we can compute its map ahead of time; see |
+ // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part |
+ // starts with the first computed property name, and continues with all |
+ // properties to its right. All the code from above initializes the static |
+ // component of the object literal, and arranges for the map of the result to |
+ // reflect the static order in which the keys appear. For the dynamic |
+ // properties, we compile them into a series of "SetOwnProperty" runtime |
+ // calls. This will preserve insertion order. |
+ for (; property_index < expr->properties()->length(); property_index++) { |
+ ObjectLiteral::Property* property = expr->properties()->at(property_index); |
+ |
+ Expression* key = property->key(); |
+ Expression* value = property->value(); |
+ if (!result_saved) { |
+ __ push(eax); // Save result on the stack |
+ result_saved = true; |
+ } |
+ |
+ switch (property->kind()) { |
+ case ObjectLiteral::Property::CONSTANT: |
+ case ObjectLiteral::Property::COMPUTED_NAME: |
+ case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
+ case ObjectLiteral::Property::COMPUTED: |
+ __ push(Operand(esp, 0)); // Duplicate receiver. |
+ VisitForStackValue(key); |
+ VisitForStackValue(value); |
+ if (property->emit_store()) { |
+ __ CallRuntime(Runtime::kSetOwnProperty, 3); |
+ } else { |
+ __ Drop(3); |
+ } |
+ break; |
+ case ObjectLiteral::Property::PROTOTYPE: |
+ __ push(Operand(esp, 0)); // Duplicate receiver. |
+ VisitForStackValue(value); |
+ if (property->emit_store()) { |
+ __ CallRuntime(Runtime::kSetPrototype, 2); |
+ } else { |
+ __ Drop(2); |
+ } |
+ break; |
+ // TODO(wingo): Allow computed names for accessor properties. Currently |
+ // disallowed by the parser. |
+ case ObjectLiteral::Property::GETTER: { |
+ ObjectLiteral::Accessors *accessors = |
+ accessor_table.lookup(key->AsLiteral())->second; |
+ accessors->getter = value; |
+ |
+ __ push(Operand(esp, 0)); // Duplicate receiver. |
+ VisitForStackValue(key); |
+ EmitAccessor(accessors->getter); |
+ EmitAccessor(accessors->setter); |
+ __ push(Immediate(Smi::FromInt(NONE))); |
+ __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
+ break; |
+ } |
+ case ObjectLiteral::Property::SETTER: { |
+ ObjectLiteral::Accessors *accessors = |
+ accessor_table.lookup(key->AsLiteral())->second; |
+ accessors->setter = value; |
+ |
+ __ push(Operand(esp, 0)); // Duplicate receiver. |
+ VisitForStackValue(key); |
+ EmitAccessor(accessors->getter); |
+ EmitAccessor(accessors->setter); |
+ __ push(Immediate(Smi::FromInt(NONE))); |
+ __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
+ break; |
+ } |
+ } |
+ } |
+ |
if (expr->has_function()) { |
ASSERT(result_saved); |
__ push(Operand(esp, 0)); |