From 4698b4b3cadd2547cf87a03daebaa23e3bd92cd5 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sun, 6 Sep 2020 10:01:37 +0000 Subject: Issue #1639 - Implement object.fromEntries() Adds a self-hosted implementation of this map->object conversion. This resolves #1639. --- js/src/builtin/Object.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'js/src/builtin/Object.js') diff --git a/js/src/builtin/Object.js b/js/src/builtin/Object.js index 9ed1be0e1..c4739037e 100644 --- a/js/src/builtin/Object.js +++ b/js/src/builtin/Object.js @@ -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; +} -- cgit v1.2.3