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

Unified Diff: src/ia32/full-codegen-ia32.cc

Issue 795573005: ES6 computed property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index 1ba409571534ee945cf8a3d16e972c61c5bcb1c4..a55f466c0f7deb65422bf72489fb8ee38cb3796c 100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -1617,11 +1617,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(eax); // Save result on the stack
@@ -1701,6 +1703,71 @@ 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* 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::MATERIALIZED_LITERAL:
+ case ObjectLiteral::Property::COMPUTED:
+ __ push(Operand(esp, 0)); // Duplicate receiver.
+ VisitForStackValue(key);
+ // TODO(arv): ToName for computed properties.
arv (Not doing code reviews) 2014/12/10 23:38:13 todo is done ;-)
+ if (property->is_computed_name()) {
+ __ InvokeBuiltin(Builtins::TO_NAME, CALL_FUNCTION);
Dmitry Lomov (no reviews) 2014/12/11 12:34:35 You can probably just call runtime function here,
arv (Not doing code reviews) 2014/12/11 15:47:24 It is not clear to me why that is preferred?
Dmitry Lomov (no reviews) 2014/12/11 16:01:15 Saves you adding a builtin just for this case
+ __ push(eax);
+ }
+ VisitForStackValue(value);
+ if (property->emit_store()) {
+ __ push(Immediate(Smi::FromInt(NONE)));
+ __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4);
+ } else {
+ __ Drop(3);
+ }
+ break;
+ case ObjectLiteral::Property::PROTOTYPE:
+ DCHECK(!property->is_computed_name());
+ __ push(Operand(esp, 0)); // Duplicate receiver.
+ VisitForStackValue(value);
+ if (property->emit_store()) {
+ __ CallRuntime(Runtime::kInternalSetPrototype, 2);
+ } else {
+ __ Drop(2);
+ }
+ break;
+
+ case ObjectLiteral::Property::GETTER:
+ __ push(Operand(esp, 0)); // Duplicate receiver.
+ VisitForStackValue(key);
+ VisitForStackValue(value);
+ __ CallRuntime(Runtime::kDefineClassGetter, 3);
arv (Not doing code reviews) 2014/12/10 23:38:13 I'll rename these two and move them to runtime-obj
arv (Not doing code reviews) 2014/12/11 23:10:33 Done.
+ break;
+
+ case ObjectLiteral::Property::SETTER:
+ __ push(Operand(esp, 0)); // Duplicate receiver.
+ VisitForStackValue(key);
+ VisitForStackValue(value);
+ __ CallRuntime(Runtime::kDefineClassSetter, 3);
+ break;
+ }
+ }
+
if (expr->has_function()) {
DCHECK(result_saved);
__ push(Operand(esp, 0));
@@ -2394,7 +2461,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* key = property->key();
Expression* value = property->value();
DCHECK(key != NULL);

Powered by Google App Engine
This is Rietveld 408576698