Bug 1469019 - Object.fromEntries. r=evilpie, r=peterv
authorJason Orendorff <jorendorff@mozilla.com>
Tue, 14 Aug 2018 13:25:30 -0500
changeset 432437 ed3c662bb21d
parent 432436 075bfbeee249
child 432438 2d615f488d9f
push id106737
push userjorendorff@mozilla.com
push dateMon, 20 Aug 2018 18:46:54 +0000
treeherdermozilla-inbound@ed3c662bb21d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie, peterv
bugs1469019
milestone63.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 1469019 - Object.fromEntries. r=evilpie, r=peterv
js/src/builtin/Object.cpp
js/src/builtin/Object.js
js/src/tests/jstests.list
js/xpconnect/tests/chrome/test_xrayToJS.xul
--- a/js/src/builtin/Object.cpp
+++ b/js/src/builtin/Object.cpp
@@ -1960,16 +1960,17 @@ static const JSFunctionSpec object_stati
     JS_FN("getOwnPropertyNames",       obj_getOwnPropertyNames,     1, 0),
     JS_FN("getOwnPropertySymbols",     obj_getOwnPropertySymbols,   1, 0),
     JS_SELF_HOSTED_FN("isExtensible",  "ObjectIsExtensible",        1, 0),
     JS_FN("preventExtensions",         obj_preventExtensions,       1, 0),
     JS_FN("freeze",                    obj_freeze,                  1, 0),
     JS_FN("isFrozen",                  obj_isFrozen,                1, 0),
     JS_FN("seal",                      obj_seal,                    1, 0),
     JS_FN("isSealed",                  obj_isSealed,                1, 0),
+    JS_SELF_HOSTED_FN("fromEntries",   "ObjectFromEntries",         1, 0),
     JS_FS_END
 };
 
 static JSObject*
 CreateObjectConstructor(JSContext* cx, JSProtoKey key)
 {
     Rooted<GlobalObject*> self(cx, cx->global());
     if (!GlobalObject::ensureConstructor(cx, self, JSProto_Function))
--- a/js/src/builtin/Object.js
+++ b/js/src/builtin/Object.js
@@ -281,8 +281,28 @@ function ObjectOrReflectDefineProperty(o
 // 19.1.2.4 Object.defineProperty ( O, P, Attributes )
 function ObjectDefineProperty(obj, propertyKey, attributes) {
     // Steps 1-4.
     ObjectOrReflectDefineProperty(obj, propertyKey, attributes, true);
 
     // Step 5.
     return obj;
 }
+
+// Proposal https://tc39.github.io/proposal-object-from-entries/
+// 1. Object.fromEntries ( iterable )
+function ObjectFromEntries(iter) {
+    // We omit the usual step number comments here because they don't help.
+    // This implementation inlines AddEntriesFromIterator and
+    // CreateDataPropertyOnObject, so it looks more like the polyfill
+    // <https://github.com/tc39/proposal-object-from-entries/blob/master/polyfill.js>
+    // than the spec algorithm.
+    const obj = {};
+
+    for (const pair of allowContentIter(iter)) {
+        if (!IsObject(pair))
+            ThrowTypeError(JSMSG_INVALID_MAP_ITERABLE, "Object.fromEntries");
+        _DefineDataProperty(obj, pair[0], pair[1]);
+    }
+
+    return obj;
+}
+
--- a/js/src/tests/jstests.list
+++ b/js/src/tests/jstests.list
@@ -454,36 +454,16 @@ skip script test262/built-ins/Function/p
 skip script test262/built-ins/Function/prototype/toString/well-known-intrinsic-object-functions.js
 
 # https://bugzilla.mozilla.org/show_bug.cgi?id=1462745
 skip script test262/annexB/language/function-code/block-decl-nested-blocks-with-fun-decl.js
 
 # https://bugzilla.mozilla.org/show_bug.cgi?id=1406171
 skip script test262/built-ins/Reflect/ownKeys/return-on-corresponding-order-large-index.js
 
-# https://bugzilla.mozilla.org/show_bug.cgi?id=1469019
-skip script test262/built-ins/Object/fromEntries/to-property-key.js
-skip script test262/built-ins/Object/fromEntries/iterator-closed-for-string-entry.js.js
-skip script test262/built-ins/Object/fromEntries/supports-symbols.js
-skip script test262/built-ins/Object/fromEntries/evaluation-order.js
-skip script test262/built-ins/Object/fromEntries/length.js
-skip script test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js
-skip script test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-next.js
-skip script test262/built-ins/Object/fromEntries/uses-define-semantics.js
-skip script test262/built-ins/Object/fromEntries/key-order.js
-skip script test262/built-ins/Object/fromEntries/iterator-closed-for-null-entry.js.js
-skip script test262/built-ins/Object/fromEntries/simple-properties.js
-skip script test262/built-ins/Object/fromEntries/empty-iterable.js
-skip script test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-accessor.js
-skip script test262/built-ins/Object/fromEntries/string-entry-object-succeeds.js
-skip script test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-done-accessor.js
-skip script test262/built-ins/Object/fromEntries/prototype.js
-skip script test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-tostring.js
-skip script test262/built-ins/Object/fromEntries/name.js
-
 # https://bugzilla.mozilla.org/show_bug.cgi?id=1291407
 skip script test262/intl402/ListFormat/prototype/toStringTag/toString.js
 skip script test262/intl402/ListFormat/prototype/toStringTag/toStringTag.js
 
 # https://bugzilla.mozilla.org/show_bug.cgi?id=1473228
 skip script test262/intl402/RelativeTimeFormat/prototype/toStringTag/toString.js
 skip script test262/intl402/RelativeTimeFormat/prototype/toStringTag/toStringTag.js
 
--- a/js/xpconnect/tests/chrome/test_xrayToJS.xul
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul
@@ -188,19 +188,19 @@ https://bugzilla.mozilla.org/show_bug.cg
     ["constructor", "toSource", "toString", "toLocaleString", "valueOf",
      "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable",
      "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__",
      "__proto__"];
   gConstructorProperties['Object'] =
     constructorProps(["setPrototypeOf", "getOwnPropertyDescriptor", "getOwnPropertyDescriptors",
                       "keys", "is", "defineProperty", "defineProperties", "create",
                       "getOwnPropertyNames", "getOwnPropertySymbols",
-                      "preventExtensions", "freeze", "isFrozen", "seal",
+                      "preventExtensions", "freeze", "fromEntries", "isFrozen", "seal",
                       "isSealed", "assign", "getPrototypeOf", "values",
-                      "entries", "isExtensible"])
+                      "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",
       "findIndex", "copyWithin", "fill", Symbol.iterator, Symbol.unscopables, "entries", "keys",
       "values", "constructor", "flat", "flatMap"];
   gConstructorProperties['Array'] =
     constructorProps(["join", "reverse", "sort", "push", "pop", "shift",