Reviewers: rossberg,

Description:
[es6] JSObject::GetOwnElementKeys should collect String wrapper keys first

This makes Object.getOwnPropertyNames() return the integer keys in the
proper order, following the spec:

http://www.ecma-international.org/ecma-262/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys

BUG=v8:4118
LOG=n

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

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

Affected files (+17, -15 lines):
  M src/objects.cc
  M test/test262-es6/test262-es6.status


Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index aeb6bb5fe79dcc76682a389f2620fde06493121e..df5ffcfd20989cde9822f34e278f6051c1c087ee 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -12972,6 +12972,23 @@ int JSObject::NumberOfEnumElements() {
 int JSObject::GetOwnElementKeys(FixedArray* storage,
                                 PropertyAttributes filter) {
   int counter = 0;
+
+  // If this is a String wrapper, add the string indices first,
+  // as they're guaranteed to preced the elements in numerical order
+  // and ascending order is required by ECMA-262, 6th, 9.1.12.
+  if (IsJSValue()) {
+    Object* val = JSValue::cast(this)->value();
+    if (val->IsString()) {
+      String* str = String::cast(val);
+      if (storage) {
+        for (int i = 0; i < str->length(); i++) {
+          storage->set(counter + i, Smi::FromInt(i));
+        }
+      }
+      counter += str->length();
+    }
+  }
+
   switch (GetElementsKind()) {
     case FAST_SMI_ELEMENTS:
     case FAST_ELEMENTS:
@@ -13078,18 +13095,6 @@ int JSObject::GetOwnElementKeys(FixedArray* storage,
     }
   }

-  if (this->IsJSValue()) {
-    Object* val = JSValue::cast(this)->value();
-    if (val->IsString()) {
-      String* str = String::cast(val);
-      if (storage) {
-        for (int i = 0; i < str->length(); i++) {
-          storage->set(counter + i, Smi::FromInt(i));
-        }
-      }
-      counter += str->length();
-    }
-  }
   DCHECK(!storage || storage->length() == counter);
   return counter;
 }
Index: test/test262-es6/test262-es6.status
diff --git a/test/test262-es6/test262-es6.status b/test/test262-es6/test262-es6.status index 62261f2b5c1e71011cbc9004586bcb0bbd8c4688..8a699a094109781e2ec3d8d7697e170ff57bfdc2 100644
--- a/test/test262-es6/test262-es6.status
+++ b/test/test262-es6/test262-es6.status
@@ -286,9 +286,6 @@
   'built-ins/Boolean/prototype/valueOf/S15.6.4.3_A1_T1': [FAIL],
   'built-ins/Boolean/prototype/valueOf/S15.6.4.3_A1_T2': [FAIL],

-  # https://code.google.com/p/v8/issues/detail?id=4118
-  'built-ins/Object/getOwnPropertyNames/15.2.3.4-4-44': [FAIL],
-
   # https://code.google.com/p/v8/issues/detail?id=3087
   'built-ins/Array/prototype/every/15.4.4.16-3-12': [FAIL],
   'built-ins/Array/prototype/every/15.4.4.16-3-14': [FAIL],


--
--
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