MIPS: ES6 computed property names.
Port:74e38e34b3
Original commit message: This adds support for computed property names, under the flag --harmony-computed-property-names, for both object literals and classes. This is a revert of the revert,7d48fd9dc2
. BUG=v8:3754 LOG=Y Review URL: https://codereview.chromium.org/829913005 Cr-Commit-Position: refs/heads/master@{#26088}
This commit is contained in:
parent
56abdc50ba
commit
966dad071a
@ -1671,11 +1671,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->is_computed_name()) break;
|
||||
if (property->IsCompileTimeValue()) continue;
|
||||
|
||||
Literal* key = property->key();
|
||||
Literal* key = property->key()->AsLiteral();
|
||||
Expression* value = property->value();
|
||||
if (!result_saved) {
|
||||
__ push(v0); // Save result on stack.
|
||||
@ -1763,6 +1765,67 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
|
||||
__ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 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* value = property->value();
|
||||
if (!result_saved) {
|
||||
__ push(v0); // Save result on the stack
|
||||
result_saved = true;
|
||||
}
|
||||
|
||||
__ lw(a0, MemOperand(sp)); // Duplicate receiver.
|
||||
__ push(a0);
|
||||
|
||||
if (property->kind() == ObjectLiteral::Property::PROTOTYPE) {
|
||||
DCHECK(!property->is_computed_name());
|
||||
VisitForStackValue(value);
|
||||
if (property->emit_store()) {
|
||||
__ CallRuntime(Runtime::kInternalSetPrototype, 2);
|
||||
} else {
|
||||
__ Drop(2);
|
||||
}
|
||||
} else {
|
||||
EmitPropertyKey(property);
|
||||
VisitForStackValue(value);
|
||||
|
||||
switch (property->kind()) {
|
||||
case ObjectLiteral::Property::CONSTANT:
|
||||
case ObjectLiteral::Property::MATERIALIZED_LITERAL:
|
||||
case ObjectLiteral::Property::COMPUTED:
|
||||
if (property->emit_store()) {
|
||||
__ li(a0, Operand(Smi::FromInt(NONE)));
|
||||
__ push(a0);
|
||||
__ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4);
|
||||
} else {
|
||||
__ Drop(3);
|
||||
}
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::PROTOTYPE:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::GETTER:
|
||||
__ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 3);
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::SETTER:
|
||||
__ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (expr->has_function()) {
|
||||
DCHECK(result_saved);
|
||||
__ lw(a0, MemOperand(sp));
|
||||
@ -2456,9 +2519,7 @@ void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) {
|
||||
|
||||
for (int i = 0; i < lit->properties()->length(); i++) {
|
||||
ObjectLiteral::Property* property = lit->properties()->at(i);
|
||||
Literal* key = property->key()->AsLiteral();
|
||||
Expression* value = property->value();
|
||||
DCHECK(key != NULL);
|
||||
|
||||
if (property->is_static()) {
|
||||
__ lw(scratch, MemOperand(sp, kPointerSize)); // constructor
|
||||
@ -2466,7 +2527,7 @@ void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) {
|
||||
__ lw(scratch, MemOperand(sp, 0)); // prototype
|
||||
}
|
||||
__ push(scratch);
|
||||
VisitForStackValue(key);
|
||||
EmitPropertyKey(property);
|
||||
VisitForStackValue(value);
|
||||
EmitSetHomeObjectIfNeeded(value, 2);
|
||||
|
||||
@ -2479,11 +2540,11 @@ void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) {
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::GETTER:
|
||||
__ CallRuntime(Runtime::kDefineClassGetter, 3);
|
||||
__ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 3);
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::SETTER:
|
||||
__ CallRuntime(Runtime::kDefineClassSetter, 3);
|
||||
__ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 3);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1668,11 +1668,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->is_computed_name()) break;
|
||||
if (property->IsCompileTimeValue()) continue;
|
||||
|
||||
Literal* key = property->key();
|
||||
Literal* key = property->key()->AsLiteral();
|
||||
Expression* value = property->value();
|
||||
if (!result_saved) {
|
||||
__ push(v0); // Save result on stack.
|
||||
@ -1760,6 +1762,67 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
|
||||
__ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 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* value = property->value();
|
||||
if (!result_saved) {
|
||||
__ push(v0); // Save result on the stack
|
||||
result_saved = true;
|
||||
}
|
||||
|
||||
__ ld(a0, MemOperand(sp)); // Duplicate receiver.
|
||||
__ push(a0);
|
||||
|
||||
if (property->kind() == ObjectLiteral::Property::PROTOTYPE) {
|
||||
DCHECK(!property->is_computed_name());
|
||||
VisitForStackValue(value);
|
||||
if (property->emit_store()) {
|
||||
__ CallRuntime(Runtime::kInternalSetPrototype, 2);
|
||||
} else {
|
||||
__ Drop(2);
|
||||
}
|
||||
} else {
|
||||
EmitPropertyKey(property);
|
||||
VisitForStackValue(value);
|
||||
|
||||
switch (property->kind()) {
|
||||
case ObjectLiteral::Property::CONSTANT:
|
||||
case ObjectLiteral::Property::MATERIALIZED_LITERAL:
|
||||
case ObjectLiteral::Property::COMPUTED:
|
||||
if (property->emit_store()) {
|
||||
__ li(a0, Operand(Smi::FromInt(NONE)));
|
||||
__ push(a0);
|
||||
__ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4);
|
||||
} else {
|
||||
__ Drop(3);
|
||||
}
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::PROTOTYPE:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::GETTER:
|
||||
__ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 3);
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::SETTER:
|
||||
__ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (expr->has_function()) {
|
||||
DCHECK(result_saved);
|
||||
__ ld(a0, MemOperand(sp));
|
||||
@ -2453,9 +2516,7 @@ void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) {
|
||||
|
||||
for (int i = 0; i < lit->properties()->length(); i++) {
|
||||
ObjectLiteral::Property* property = lit->properties()->at(i);
|
||||
Literal* key = property->key()->AsLiteral();
|
||||
Expression* value = property->value();
|
||||
DCHECK(key != NULL);
|
||||
|
||||
if (property->is_static()) {
|
||||
__ ld(scratch, MemOperand(sp, kPointerSize)); // constructor
|
||||
@ -2463,7 +2524,7 @@ void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) {
|
||||
__ ld(scratch, MemOperand(sp, 0)); // prototype
|
||||
}
|
||||
__ push(scratch);
|
||||
VisitForStackValue(key);
|
||||
EmitPropertyKey(property);
|
||||
VisitForStackValue(value);
|
||||
EmitSetHomeObjectIfNeeded(value, 2);
|
||||
|
||||
@ -2476,11 +2537,11 @@ void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) {
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::GETTER:
|
||||
__ CallRuntime(Runtime::kDefineClassGetter, 3);
|
||||
__ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 3);
|
||||
break;
|
||||
|
||||
case ObjectLiteral::Property::SETTER:
|
||||
__ CallRuntime(Runtime::kDefineClassSetter, 3);
|
||||
__ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 3);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user