From 3ed20ff700083448a53b2e12d6a54e212c451e43 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 11 Jul 2018 13:11:02 -0700 Subject: [PATCH] Editorial: create addIterableFromEntries abstract operation This consolidates some of the logic in the Map and WeakMap constructors, and also creates a convenient operation for https://github.com/tc39/proposal-object-from-entries/issues/11. --- spec.html | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/spec.html b/spec.html index fcac57f9721..e01aaf16fd6 100644 --- a/spec.html +++ b/spec.html @@ -33553,14 +33553,25 @@

Map ( [ _iterable_ ] )

1. If NewTarget is *undefined*, throw a *TypeError* exception. 1. Let _map_ be ? OrdinaryCreateFromConstructor(NewTarget, `"%MapPrototype%"`, « [[MapData]] »). 1. Set _map_.[[MapData]] to a new empty List. - 1. If _iterable_ is not present, let _iterable_ be *undefined*. - 1. If _iterable_ is either *undefined* or *null*, return _map_. + 1. If _iterable_ is not present, or is either *undefined* or *null*, return _map_. 1. Let _adder_ be ? Get(_map_, `"set"`). + 1. Return ? AddEntriesFromIterable(_map_, _iterable_, _adder_). + + +

If the parameter _iterable_ is present, it is expected to be an object that implements an @@iterator method that returns an iterator object that produces a two element array-like object whose first element is a value that will be used as a Map key and whose second element is the value to associate with that key.

+
+ + + +

AddEntriesFromIterable ( _target_, _iterable_, _adder_ )

+

The abstract operation AddEntriesFromIterable accepts a _target_ object, an _iterable_ of entries, and an _adder_ function to be invoked, with _target_ as the receiver.

+ 1. If IsCallable(_adder_) is *false*, throw a *TypeError* exception. + 1. Assert: _iterable_ is present, and is neither *undefined* nor *null*. 1. Let _iteratorRecord_ be ? GetIterator(_iterable_). 1. Repeat, 1. Let _next_ be ? IteratorStep(_iteratorRecord_). - 1. If _next_ is *false*, return _map_. + 1. If _next_ is *false*, return _target_. 1. Let _nextItem_ be ? IteratorValue(_next_). 1. If Type(_nextItem_) is not Object, then 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). @@ -33569,11 +33580,11 @@

Map ( [ _iterable_ ] )

1. If _k_ is an abrupt completion, return ? IteratorClose(_iteratorRecord_, _k_). 1. Let _v_ be Get(_nextItem_, `"1"`). 1. If _v_ is an abrupt completion, return ? IteratorClose(_iteratorRecord_, _v_). - 1. Let _status_ be Call(_adder_, _map_, « _k_.[[Value]], _v_.[[Value]] »). + 1. Let _status_ be Call(_adder_, _target_, « _k_.[[Value]], _v_.[[Value]] »). 1. If _status_ is an abrupt completion, return ? IteratorClose(_iteratorRecord_, _status_).
-

If the parameter _iterable_ is present, it is expected to be an object that implements an @@iterator method that returns an iterator object that produces a two element array-like object whose first element is a value that will be used as a Map key and whose second element is the value to associate with that key.

+

The parameter _iterable_ is expected to be an object that implements an @@iterator method that returns an iterator object that produces a two element array-like object whose first element is a value that will be used as a Map key and whose second element is the value to associate with that key.

@@ -34266,24 +34277,9 @@

WeakMap ( [ _iterable_ ] )

1. If NewTarget is *undefined*, throw a *TypeError* exception. 1. Let _map_ be ? OrdinaryCreateFromConstructor(NewTarget, `"%WeakMapPrototype%"`, « [[WeakMapData]] »). 1. Set _map_.[[WeakMapData]] to a new empty List. - 1. If _iterable_ is not present, let _iterable_ be *undefined*. - 1. If _iterable_ is either *undefined* or *null*, return _map_. + 1. If _iterable_ is not present, or is either *undefined* or *null*, return _map_. 1. Let _adder_ be ? Get(_map_, `"set"`). - 1. If IsCallable(_adder_) is *false*, throw a *TypeError* exception. - 1. Let _iteratorRecord_ be ? GetIterator(_iterable_). - 1. Repeat, - 1. Let _next_ be ? IteratorStep(_iterRecord_). - 1. If _next_ is *false*, return _map_. - 1. Let _nextItem_ be ? IteratorValue(_next_). - 1. If Type(_nextItem_) is not Object, then - 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). - 1. Return ? IteratorClose(_iteratorRecord_, _error_). - 1. Let _k_ be Get(_nextItem_, `"0"`). - 1. If _k_ is an abrupt completion, return ? IteratorClose(_iteratorRecord_, _k_). - 1. Let _v_ be Get(_nextItem_, `"1"`). - 1. If _v_ is an abrupt completion, return ? IteratorClose(_iteratorRecord_, _v_). - 1. Let _status_ be Call(_adder_, _map_, « _k_.[[Value]], _v_.[[Value]] »). - 1. If _status_ is an abrupt completion, return ? IteratorClose(_iteratorRecord_, _status_). + 1. Return ? AddEntriesFromIterable(_map_, _iterable_, _adder_).

If the parameter _iterable_ is present, it is expected to be an object that implements an @@iterator method that returns an iterator object that produces a two element array-like object whose first element is a value that will be used as a WeakMap key and whose second element is the value to associate with that key.