Issue #1639 - Implement object.fromEntries()

Adds a self-hosted implementation of this map->object conversion.
This resolves #1639.
This commit is contained in:
Moonchild 2020-09-06 10:01:37 +00:00 • committed by roytam1
commit 065ef47e65
3 changed files with 21 additions and 2 deletions

View file

@ -1239,6 +1239,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
};

View file

@ -202,3 +202,21 @@ function ObjectLookupGetter(name) {
// Step 3.d. (implicit)
}
// Stage 4 draft 2020-09-06 https://tc39.github.io/proposal-object-from-entries/
// 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 step-by-step 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;
}

View file

@ -190,9 +190,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",