Revision: 4958
Author: [email protected]
Date: Mon Jun 28 01:31:31 2010
Log: Object.getOwnPropertyNames should be free of duplicates

BUG=41243
Review URL: http://codereview.chromium.org/2825026
http://code.google.com/p/v8/source/detail?r=4958

Modified:
 /branches/bleeding_edge/src/v8natives.js
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/src/v8natives.js    Thu May 27 00:43:43 2010
+++ /branches/bleeding_edge/src/v8natives.js    Mon Jun 28 01:31:31 2010
@@ -677,9 +677,17 @@
     }
   }

-  // Property names are expected to be strings.
-  for (var i = 0; i < propertyNames.length; ++i)
-    propertyNames[i] = ToString(propertyNames[i]);
+  // Property names are expected to be unique strings.
+  var propertySet = {};
+  var j = 0;
+  for (var i = 0; i < propertyNames.length; ++i) {
+    var name = ToString(propertyNames[i]);
+    if (name in propertySet)
+      continue;
+    propertySet[name] = true;
+    propertyNames[j++] = name;
+  }
+  propertyNames.length = j;

   return propertyNames;
 }
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Fri Jun 18 03:52:59 2010
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Mon Jun 28 01:31:31 2010
@@ -5033,6 +5033,31 @@
   context1.Dispose();
   context0.Dispose();
 }
+
+
+static v8::Handle<v8::Array> NamedPropertyEnumerator(const AccessorInfo& info) {
+  v8::Handle<v8::Array> result = v8::Array::New(1);
+  result->Set(0, v8_str("x"));
+  return result;
+}
+
+
+THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
+  v8::HandleScope handle_scope;
+  v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
+
+  obj_template->Set(v8_str("x"), v8::Integer::New(42));
+  obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL,
+                                        NamedPropertyEnumerator);
+
+  LocalContext context;
+  v8::Handle<v8::Object> global = context->Global();
+  global->Set(v8_str("object"), obj_template->NewInstance());
+
+  v8::Handle<Value> value =
+      CompileRun("Object.getOwnPropertyNames(object).join(',')");
+  CHECK_EQ(v8_str("x"), value);
+}


 static v8::Handle<Value> ConstTenGetter(Local<String> name,

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to