diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp index 688e7d398a44..ad5e37fbd042 100644 --- a/js/src/builtin/Object.cpp +++ b/js/src/builtin/Object.cpp @@ -1965,6 +1965,7 @@ static const JSFunctionSpec object_static_methods[] = { 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 }; diff --git a/js/src/builtin/Object.js b/js/src/builtin/Object.js index f4ff9c0f1d32..717e22ecff3a 100644 --- a/js/src/builtin/Object.js +++ b/js/src/builtin/Object.js @@ -286,3 +286,23 @@ function ObjectDefineProperty(obj, propertyKey, attributes) { // 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 + // + // 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; +} + diff --git a/js/src/tests/jstests.list b/js/src/tests/jstests.list index 6987a41d06b9..0d10de12e925 100644 --- a/js/src/tests/jstests.list +++ b/js/src/tests/jstests.list @@ -459,26 +459,6 @@ skip script test262/annexB/language/function-code/block-decl-nested-blocks-with- # 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 diff --git a/js/xpconnect/tests/chrome/test_xrayToJS.xul b/js/xpconnect/tests/chrome/test_xrayToJS.xul index 1d554c967265..97def9ddf4ea 100644 --- a/js/xpconnect/tests/chrome/test_xrayToJS.xul +++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul @@ -193,9 +193,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681 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",