Reviewers: Weiliang, arv,

Message:
WL.
PTAL.
thanks

Description:
X87: ES6 computed property names

port 74e38e34b3caecfb660c3ed1336a58c551215793.

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, 7d48fd9dc29c8f5d7c8b5215f9bd537cdd005eba.

BUG=

Please review this at https://codereview.chromium.org/825593004/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+67, -8 lines):
  M src/x87/full-codegen-x87.cc


Index: src/x87/full-codegen-x87.cc
diff --git a/src/x87/full-codegen-x87.cc b/src/x87/full-codegen-x87.cc
index 1f46fdc039f0d8df7cfcd747109a6f483b8bed04..6bca8a0cee8d5dce7d9fd28375a2d74132bcd307 100644
--- a/src/x87/full-codegen-x87.cc
+++ b/src/x87/full-codegen-x87.cc
@@ -1606,11 +1606,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
@@ -1690,6 +1692,65 @@ 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(eax);  // Save result on the stack
+      result_saved = true;
+    }
+
+    __ push(Operand(esp, 0));  // Duplicate receiver.
+
+    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()) {
+            __ push(Immediate(Smi::FromInt(NONE)));
+            __ 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);
     __ push(Operand(esp, 0));
@@ -2381,16 +2442,14 @@ 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()) {
       __ push(Operand(esp, kPointerSize));  // constructor
     } else {
       __ push(Operand(esp, 0));  // prototype
     }
-    VisitForStackValue(key);
+    EmitPropertyKey(property);
     VisitForStackValue(value);
     EmitSetHomeObjectIfNeeded(value, 2);

@@ -2403,11 +2462,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:


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to