Bug 1245024 - Implement Object.getOwnPropertyDescriptors. r=efaust,bz
authorTom Schuster <evilpies@gmail.com>
Thu, 09 Jun 2016 20:27:53 +0200
changeset 301387 5238e71b3635
parent 301386 80ca88ff3e6a
child 301388 06a54c686fc9
push id30333
push usercbook@mozilla.com
push dateFri, 10 Jun 2016 13:39:58 +0000
treeherdermozilla-central@52679ce4756c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersefaust, bz
bugs1245024
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1245024 - Implement Object.getOwnPropertyDescriptors. r=efaust,bz
js/src/builtin/Object.cpp
js/src/builtin/Object.js
js/xpconnect/tests/chrome/test_xrayToJS.xul
--- a/js/src/builtin/Object.cpp
+++ b/js/src/builtin/Object.cpp
@@ -1121,16 +1121,17 @@ static const JSPropertySpec object_prope
     JS_PS_END
 };
 
 static const JSFunctionSpec object_static_methods[] = {
     JS_SELF_HOSTED_FN("assign",        "ObjectStaticAssign",        2, 0),
     JS_SELF_HOSTED_FN("getPrototypeOf", "ObjectGetPrototypeOf",     1, 0),
     JS_FN("setPrototypeOf",            obj_setPrototypeOf,          2, 0),
     JS_FN("getOwnPropertyDescriptor",  obj_getOwnPropertyDescriptor,2, 0),
+    JS_SELF_HOSTED_FN("getOwnPropertyDescriptors", "ObjectGetOwnPropertyDescriptors", 1, 0),
     JS_FN("keys",                      obj_keys,                    1, 0),
     JS_FN("values",                    obj_values,                  1, 0),
     JS_FN("entries",                   obj_entries,                 1, 0),
     JS_FN("is",                        obj_is,                      2, 0),
     JS_FN("defineProperty",            obj_defineProperty,          3, 0),
     JS_FN("defineProperties",          obj_defineProperties,        2, 0),
     JS_INLINABLE_FN("create",          obj_create,                  2, 0, ObjectCreate),
     JS_FN("getOwnPropertyNames",       obj_getOwnPropertyNames,     1, 0),
--- a/js/src/builtin/Object.js
+++ b/js/src/builtin/Object.js
@@ -36,16 +36,42 @@ function ObjectStaticAssign(target, firs
             }
         }
     }
 
     // Step 6.
     return to;
 }
 
+// ES stage 4 proposal
+function ObjectGetOwnPropertyDescriptors(O) {
+    // Step 1.
+    var obj = ToObject(O);
+
+    // Step 2.
+    var keys = OwnPropertyKeys(obj, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS);
+
+    // Step 3.
+    var descriptors = {};
+
+    // Step 4.
+    for (var index = 0, len = keys.length; index < len; index++) {
+        var key = keys[index];
+
+        // Steps 4.a-b.
+        var desc = std_Object_getOwnPropertyDescriptor(obj, key);
+
+        // Step 4.c.
+        _DefineDataProperty(descriptors, key, desc);
+    }
+
+    // Step 5.
+    return descriptors;
+}
+
 /* ES6 draft rev 32 (2015 Feb 2) 19.1.2.9. */
 function ObjectGetPrototypeOf(obj) {
     return std_Reflect_getPrototypeOf(ToObject(obj));
 }
 
 /* ES6 draft rev 32 (2015 Feb 2) 19.1.2.11. */
 function ObjectIsExtensible(obj) {
     return IsObject(obj) && std_Reflect_isExtensible(obj);
--- a/js/xpconnect/tests/chrome/test_xrayToJS.xul
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul
@@ -166,18 +166,18 @@ https://bugzilla.mozilla.org/show_bug.cg
     "toGMTString", Symbol.toPrimitive];
   gConstructorProperties['Date'] = constructorProps(["UTC", "parse", "now"]);
   gPrototypeProperties['Object'] =
     ["constructor", "toSource", "toString", "toLocaleString", "valueOf", "watch",
      "unwatch", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable",
      "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__",
      "__proto__"];
   gConstructorProperties['Object'] =
-    constructorProps(["setPrototypeOf", "getOwnPropertyDescriptor", "keys",
-                      "is", "defineProperty", "defineProperties", "create",
+    constructorProps(["setPrototypeOf", "getOwnPropertyDescriptor", "getOwnPropertyDescriptors",
+                      "keys", "is", "defineProperty", "defineProperties", "create",
                       "getOwnPropertyNames", "getOwnPropertySymbols",
                       "preventExtensions", "freeze", "isFrozen", "seal",
                       "isSealed", "assign", "getPrototypeOf", "values",
                       "entries", "isExtensible"])
   gPrototypeProperties['Array'] =
     ["length", "toSource", "toString", "toLocaleString", "join", "reverse", "sort", "push",
       "pop", "shift", "unshift", "splice", "concat", "slice", "lastIndexOf", "indexOf",
       "includes", "forEach", "map", "reduce", "reduceRight", "filter", "some", "every", "find",