Index: src/mips/full-codegen-mips.cc |
diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc |
index da4756aed3b2f97bd6b36f004b74b895f4d58c62..0c6681388daefe6180a4847dbaac8126273440d8 100644 |
--- a/src/mips/full-codegen-mips.cc |
+++ b/src/mips/full-codegen-mips.cc |
@@ -1690,11 +1690,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(v0); // Save result on stack. |
@@ -1702,9 +1704,10 @@ 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(property->value())); |
+ ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
// Fall through. |
case ObjectLiteral::Property::COMPUTED: |
if (key->value()->IsInternalizedString()) { |
@@ -1768,6 +1771,87 @@ 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 "PutOwnProperty" 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(v0); // 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: |
+ // Duplicate receiver on stack. |
+ __ lw(a0, MemOperand(sp)); |
+ __ push(a0); |
+ VisitForStackValue(key); |
+ VisitForStackValue(value); |
+ if (property->emit_store()) { |
+ __ CallRuntime(Runtime::kPutOwnProperty, 3); |
+ } else { |
+ __ Drop(3); |
+ } |
+ break; |
+ case ObjectLiteral::Property::PROTOTYPE: |
+ // Duplicate receiver on stack. |
+ __ lw(a0, MemOperand(sp)); |
+ __ push(a0); |
+ VisitForStackValue(value); |
+ if (property->emit_store()) { |
+ __ CallRuntime(Runtime::kSetPrototype, 2); |
+ } else { |
+ __ Drop(2); |
+ } |
+ break; |
+ case ObjectLiteral::Property::GETTER: { |
+ ObjectLiteral::Accessors *accessors = |
+ accessor_table.lookup(key->AsLiteral())->second; |
+ accessors->getter = value; |
+ |
+ // Duplicate receiver on stack. |
+ __ lw(a0, MemOperand(sp)); |
+ __ push(a0); |
+ VisitForStackValue(key); |
+ EmitAccessor(accessors->getter); |
+ EmitAccessor(accessors->setter); |
+ __ li(a0, Operand(Smi::FromInt(NONE))); // PropertyAttributes. |
+ __ push(a0); |
+ __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
+ break; |
+ } |
+ case ObjectLiteral::Property::SETTER: { |
+ ObjectLiteral::Accessors *accessors = |
+ accessor_table.lookup(key->AsLiteral())->second; |
+ accessors->setter = value; |
+ |
+ // Duplicate receiver on stack. |
+ __ lw(a0, MemOperand(sp)); |
+ __ push(a0); |
+ VisitForStackValue(key); |
+ EmitAccessor(accessors->getter); |
+ EmitAccessor(accessors->setter); |
+ __ li(a0, Operand(Smi::FromInt(NONE))); // PropertyAttributes. |
+ __ push(a0); |
+ __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
+ break; |
+ } |
+ } |
+ } |
+ |
if (expr->has_function()) { |
ASSERT(result_saved); |
__ lw(a0, MemOperand(sp)); |