diff --git a/spec.html b/spec.html index b3fa9123ce..ef6053e6d4 100644 --- a/spec.html +++ b/spec.html @@ -3658,12 +3658,23 @@

Well-Known Intrinsic Objects

- %IteratorPrototype% + %Iterator% + `Iterator` - An object that all standard built-in iterator objects indirectly inherit from + The `Iterator` constructor () + + + + + %IteratorHelperPrototype% + + + + + The prototype of Iterator Helper Objects () @@ -4023,6 +4034,16 @@

Well-Known Intrinsic Objects

The WeakSet constructor () + + + %WrapForValidIteratorPrototype% + + + + + The prototype of wrapped Iterator objects returned by Iterator.from () + + @@ -6888,6 +6909,32 @@

1. Set _k_ to _k_ + 1. + + +

+ SetterThatIgnoresPrototypeProperties ( + _thisValue_: an ECMAScript language value, + _home_: an Object, + _p_: a property key, + _v_: an ECMAScript language value, + ): either a normal completion containing ~unused~ or a throw completion +

+
+
+ + 1. If _thisValue_ is not an Object, then + 1. Throw a *TypeError* exception. + 1. If SameValue(_thisValue_, _home_) is *true*, then + 1. NOTE: Throwing here emulates assignment to a non-writable data property on the _home_ object in strict mode code. + 1. Throw a *TypeError* exception. + 1. Let _desc_ be ? _thisValue_.[[GetOwnProperty]](_p_). + 1. If _desc_ is *undefined*, then + 1. Perform ? CreateDataPropertyOrThrow(_thisValue_, _p_, _v_). + 1. Else, + 1. Perform ? Set(_thisValue_, _p_, _v_, *true*). + 1. Return ~unused~. + +
@@ -6950,6 +6997,21 @@

Iterator Records

+ +

+ GetIteratorDirect ( + _obj_: an Object, + ): either a normal completion containing an Iterator Record or a throw completion +

+
+
+ + 1. Let _nextMethod_ be ? Get(_obj_, *"next"*). + 1. Let _iteratorRecord_ be the Iterator Record { [[Iterator]]: _obj_, [[NextMethod]]: _nextMethod_, [[Done]]: *false* }. + 1. Return _iteratorRecord_. + +
+

GetIteratorFromMethod ( @@ -6962,9 +7024,7 @@

1. Let _iterator_ be ? Call(_method_, _obj_). 1. If _iterator_ is not an Object, throw a *TypeError* exception. - 1. Let _nextMethod_ be ? Get(_iterator_, *"next"*). - 1. Let _iteratorRecord_ be the Iterator Record { [[Iterator]]: _iterator_, [[NextMethod]]: _nextMethod_, [[Done]]: *false* }. - 1. Return _iteratorRecord_. + 1. Return ? GetIteratorDirect(_iterator_). @@ -6992,6 +7052,30 @@

+ +

+ GetIteratorFlattenable ( + _obj_: an ECMAScript language value, + _primitiveHandling_: ~iterate-string-primitives~ or ~reject-primitives~, + ): either a normal completion containing an Iterator Record or a throw completion +

+
+
+ + 1. If _obj_ is not an Object, then + 1. If _primitiveHandling_ is ~reject-primitives~, throw a *TypeError* exception. + 1. Assert: _primitiveHandling_ is ~iterate-string-primitives~. + 1. If _obj_ is not a String, throw a *TypeError* exception. + 1. Let _method_ be ? GetMethod(_obj_, %Symbol.iterator%). + 1. If _method_ is *undefined*, then + 1. Let _iterator_ be _obj_. + 1. Else, + 1. Let _iterator_ be ? Call(_method_, _obj_). + 1. If _iterator_ is not an Object, throw a *TypeError* exception. + 1. Return ? GetIteratorDirect(_iterator_). + +
+

IteratorNext ( @@ -7189,7 +7273,7 @@

1. For each element _E_ of _list_, do 1. Perform ? GeneratorYield(CreateIteratorResultObject(_E_, *false*)). 1. Return NormalCompletion(*undefined*). - 1. Let _iterator_ be CreateIteratorFromClosure(_closure_, ~empty~, %IteratorPrototype%). + 1. Let _iterator_ be CreateIteratorFromClosure(_closure_, ~empty~, %Iterator.prototype%). 1. Return the Iterator Record { [[Iterator]]: _iterator_, [[NextMethod]]: %GeneratorFunction.prototype.prototype.next%, [[Done]]: *false* }. @@ -22409,7 +22493,7 @@

The %ForInIteratorPrototype% Object

  • has properties that are inherited by all For-In Iterator Objects.
  • is an ordinary object.
  • -
  • has a [[Prototype]] internal slot whose value is %IteratorPrototype%.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • is never directly accessible to ECMAScript code.
  • has the following properties:
@@ -35583,7 +35667,7 @@

The %StringIteratorPrototype% Object

  • has properties that are inherited by all String Iterator Objects.
  • is an ordinary object.
  • -
  • has a [[Prototype]] internal slot whose value is %IteratorPrototype%.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • has the following properties:
@@ -38652,7 +38736,7 @@

The %RegExpStringIteratorPrototype% Object

  • has properties that are inherited by all RegExp String Iterator Objects.
  • is an ordinary object.
  • -
  • has a [[Prototype]] internal slot whose value is %IteratorPrototype%.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • has the following properties:
@@ -40231,7 +40315,7 @@

The %ArrayIteratorPrototype% Object

  • has properties that are inherited by all Array Iterator Objects.
  • is an ordinary object.
  • -
  • has a [[Prototype]] internal slot whose value is %IteratorPrototype%.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • has the following properties:
@@ -42222,7 +42306,7 @@

The %MapIteratorPrototype% Object

  • has properties that are inherited by all Map Iterator Objects.
  • is an ordinary object.
  • -
  • has a [[Prototype]] internal slot whose value is %IteratorPrototype%.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • has the following properties:
@@ -42852,7 +42936,7 @@

The %SetIteratorPrototype% Object

  • has properties that are inherited by all Set Iterator Objects.
  • is an ordinary object.
  • -
  • has a [[Prototype]] internal slot whose value is %IteratorPrototype%.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • has the following properties:
@@ -46494,27 +46578,465 @@

The IteratorResult Interface

- -

The %IteratorPrototype% Object

-

The %IteratorPrototype% object:

+ +

Iterator Helper Objects

+

An Iterator Helper object is an ordinary object that represents a lazy transformation of some specific source iterator object. There is not a named constructor for Iterator Helper objects. Instead, Iterator Helper objects are created by calling certain methods of Iterator instance objects.

+ + +

The %IteratorHelperPrototype% Object

+

The %IteratorHelperPrototype% object:

+
    +
  • has properties that are inherited by all Iterator Helper Objects.
  • +
  • is an ordinary object.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • +
  • has the following properties:
  • +
+ + +

%IteratorHelperPrototype%.next ( )

+ + 1. Return ? GeneratorResume(*this* value, *undefined*, *"Iterator Helper"*). + +
+ + +

%IteratorHelperPrototype%.return ( )

+ + 1. Let _O_ be *this* value. + 1. Perform ? RequireInternalSlot(_O_, [[UnderlyingIterator]]). + 1. Assert: _O_ has a [[GeneratorState]] internal slot. + 1. If _O_.[[GeneratorState]] is ~suspended-start~, then + 1. Set _O_.[[GeneratorState]] to ~completed~. + 1. NOTE: Once a generator enters the completed state it never leaves it and its associated execution context is never resumed. Any execution state associated with _O_ can be discarded at this point. + 1. Perform ? IteratorClose(_O_.[[UnderlyingIterator]], ReturnCompletion(*undefined*)). + 1. Return CreateIteratorResultObject(*undefined*, *true*). + 1. Let _C_ be ReturnCompletion(*undefined*). + 1. Return ? GeneratorResumeAbrupt(_O_, _C_, *"Iterator Helper"*). + +
+ + +

%IteratorHelperPrototype% [ %Symbol.toStringTag% ]

+

The initial value of the %Symbol.toStringTag% property is the String value *"Iterator Helper"*.

+

This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.

+
+
+
+ + +

Iterator Objects

+ + +

The Iterator Constructor

+

The Iterator constructor:

+
    +
  • is %Iterator%.
  • +
  • is the initial value of the *"Iterator"* property of the global object.
  • +
  • is designed to be subclassable. It may be used as the value of an *extends* clause of a class definition.
  • +
+ + +

Iterator ( )

+

This function performs the following steps when called:

+ + 1. If NewTarget is either *undefined* or the active function object, throw a *TypeError* exception. + 1. Return ? OrdinaryCreateFromConstructor(NewTarget, *"%Iterator.prototype%"*). + +
+
+ + +

Properties of the Iterator Constructor

+

The Iterator constructor:

+
    +
  • has a [[Prototype]] internal slot whose value is %Function.prototype%.
  • +
  • has the following properties:
  • +
+ + +

Iterator.from ( _O_ )

+ + 1. Let _iteratorRecord_ be ? GetIteratorFlattenable(_O_, ~iterate-string-primitives~). + 1. Let _hasInstance_ be ? OrdinaryHasInstance(%Iterator%, _iteratorRecord_.[[Iterator]]). + 1. If _hasInstance_ is *true*, then + 1. Return _iteratorRecord_.[[Iterator]]. + 1. Let _wrapper_ be OrdinaryObjectCreate(%WrapForValidIteratorPrototype%, « [[Iterated]] »). + 1. Set _wrapper_.[[Iterated]] to _iteratorRecord_. + 1. Return _wrapper_. + + + +

The %WrapForValidIteratorPrototype% Object

+

The %WrapForValidIteratorPrototype% object:

+
    +
  • is an ordinary object.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • +
+ + +

%WrapForValidIteratorPrototype%.next ( )

+ + 1. Let _O_ be *this* value. + 1. Perform ? RequireInternalSlot(_O_, [[Iterated]]). + 1. Let _iteratorRecord_ be _O_.[[Iterated]]. + 1. Return ? Call(_iteratorRecord_.[[NextMethod]], _iteratorRecord_.[[Iterator]]). + +
+ + +

%WrapForValidIteratorPrototype%.return ( )

+ + 1. Let _O_ be *this* value. + 1. Perform ? RequireInternalSlot(_O_, [[Iterated]]). + 1. Let _iterator_ be _O_.[[Iterated]].[[Iterator]]. + 1. Assert: _iterator_ is an Object. + 1. Let _returnMethod_ be ? GetMethod(_iterator_, *"return"*). + 1. If _returnMethod_ is *undefined*, then + 1. Return CreateIteratorResultObject(*undefined*, *true*). + 1. Return ? Call(_returnMethod_, _iterator_). + +
+
+
+ + +

Iterator.prototype

+

The initial value of Iterator.prototype is %Iterator.prototype%.

+

This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.

+
+
+
+ + +

The %Iterator.prototype% Object

+

The %Iterator.prototype% object:

  • has a [[Prototype]] internal slot whose value is %Object.prototype%.
  • is an ordinary object.
-

All objects defined in this specification that implement the Iterator interface also inherit from %IteratorPrototype%. ECMAScript code may also define objects that inherit from %IteratorPrototype%. The %IteratorPrototype% object provides a place where additional methods that are applicable to all iterator objects may be added.

-

The following expression is one way that ECMAScript code can access the %IteratorPrototype% object:

+

All objects defined in this specification that implement the Iterator interface also inherit from %Iterator.prototype%. ECMAScript code may also define objects that inherit from %Iterator.prototype%. The %Iterator.prototype% object provides a place where additional methods that are applicable to all iterator objects may be added.

+

The following expression is one way that ECMAScript code can access the %Iterator.prototype% object:

Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()))
- -

%IteratorPrototype% [ %Symbol.iterator% ] ( )

+ +

Iterator.prototype.constructor

+

`Iterator.prototype.constructor` is an accessor property with attributes { [[Enumerable]]: *false*, [[Configurable]]: *true* }. The [[Get]] and [[Set]] attributes are defined as follows:

+ + +

get Iterator.prototype.constructor

+

The value of the [[Get]] attribute is a built-in function that requires no arguments. It performs the following steps when called:

+ + 1. Return %Iterator%. + +
+ + +

set Iterator.prototype.constructor

+

The value of the [[Set]] attribute is a built-in function that takes an argument _v_. It performs the following steps when called:

+ + 1. Perform ? SetterThatIgnoresPrototypeProperties(*this* value, %Iterator.prototype%, *"constructor"*, _v_). + 1. Return *undefined*. + +
+ + +

Unlike the *"constructor"* property on most built-in prototypes, for web-compatibility reasons this property must be an accessor.

+
+
+ + +

Iterator.prototype.drop ( _limit_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. Let _numLimit_ be ? ToNumber(_limit_). + 1. If _numLimit_ is *NaN*, throw a *RangeError* exception. + 1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_). + 1. If _integerLimit_ < 0, throw a *RangeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called: + 1. Let _remaining_ be _integerLimit_. + 1. Repeat, while _remaining_ > 0, + 1. If _remaining_ ≠ +∞, then + 1. Set _remaining_ to _remaining_ - 1. + 1. Let _next_ be ? IteratorStep(_iterated_). + 1. If _next_ is ~done~, return ReturnCompletion(*undefined*). + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return ReturnCompletion(*undefined*). + 1. Let _completion_ be Completion(Yield(_value_)). + 1. IfAbruptCloseIterator(_completion_, _iterated_). + 1. Let _result_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterator]] »). + 1. Set _result_.[[UnderlyingIterator]] to _iterated_. + 1. Return _result_. + +
+ + +

Iterator.prototype.every ( _predicate_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _counter_ be 0. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return *true*. + 1. Let _result_ be Completion(Call(_predicate_, *undefined*, « _value_, 𝔽(_counter_) »)). + 1. IfAbruptCloseIterator(_result_, _iterated_). + 1. If ToBoolean(_result_) is *false*, return ? IteratorClose(_iterated_, NormalCompletion(*false*)). + 1. Set _counter_ to _counter_ + 1. + +
+ + +

Iterator.prototype.filter ( _predicate_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _predicate_ and performs the following steps when called: + 1. Let _counter_ be 0. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return ReturnCompletion(*undefined*). + 1. Let _selected_ be Completion(Call(_predicate_, *undefined*, « _value_, 𝔽(_counter_) »)). + 1. IfAbruptCloseIterator(_selected_, _iterated_). + 1. If ToBoolean(_selected_) is *true*, then + 1. Let _completion_ be Completion(Yield(_value_)). + 1. IfAbruptCloseIterator(_completion_, _iterated_). + 1. Set _counter_ to _counter_ + 1. + 1. Let _result_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterator]] »). + 1. Set _result_.[[UnderlyingIterator]] to _iterated_. + 1. Return _result_. + +
+ + +

Iterator.prototype.find ( _predicate_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _counter_ be 0. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return *undefined*. + 1. Let _result_ be Completion(Call(_predicate_, *undefined*, « _value_, 𝔽(_counter_) »)). + 1. IfAbruptCloseIterator(_result_, _iterated_). + 1. If ToBoolean(_result_) is *true*, return ? IteratorClose(_iterated_, NormalCompletion(_value_)). + 1. Set _counter_ to _counter_ + 1. + +
+ + +

Iterator.prototype.flatMap ( _mapper_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called: + 1. Let _counter_ be 0. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return ReturnCompletion(*undefined*). + 1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)). + 1. IfAbruptCloseIterator(_mapped_, _iterated_). + 1. Let _innerIterator_ be Completion(GetIteratorFlattenable(_mapped_, ~reject-primitives~)). + 1. IfAbruptCloseIterator(_innerIterator_, _iterated_). + 1. Let _innerAlive_ be *true*. + 1. Repeat, while _innerAlive_ is *true*, + 1. Let _innerValue_ be Completion(IteratorStepValue(_innerIterator_)). + 1. IfAbruptCloseIterator(_innerValue_, _iterated_). + 1. If _innerValue_ is ~done~, then + 1. Set _innerAlive_ to *false*. + 1. Else, + 1. Let _completion_ be Completion(Yield(_innerValue_)). + 1. If _completion_ is an abrupt completion, then + 1. Let _backupCompletion_ be Completion(IteratorClose(_innerIterator_, _completion_)). + 1. IfAbruptCloseIterator(_backupCompletion_, _iterated_). + 1. Return ? IteratorClose(_iterated_, _completion_). + 1. Set _counter_ to _counter_ + 1. + 1. Let _result_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterator]] »). + 1. Set _result_.[[UnderlyingIterator]] to _iterated_. + 1. Return _result_. + +
+ + +

Iterator.prototype.forEach ( _procedure_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. If IsCallable(_procedure_) is *false*, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _counter_ be 0. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return *undefined*. + 1. Let _result_ be Completion(Call(_procedure_, *undefined*, « _value_, 𝔽(_counter_) »)). + 1. IfAbruptCloseIterator(_result_, _iterated_). + 1. Set _counter_ to _counter_ + 1. + +
+ + +

Iterator.prototype.map ( _mapper_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called: + 1. Let _counter_ be 0. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return ReturnCompletion(*undefined*). + 1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)). + 1. IfAbruptCloseIterator(_mapped_, _iterated_). + 1. Let _completion_ be Completion(Yield(_mapped_)). + 1. IfAbruptCloseIterator(_completion_, _iterated_). + 1. Set _counter_ to _counter_ + 1. + 1. Let _result_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterator]] »). + 1. Set _result_.[[UnderlyingIterator]] to _iterated_. + 1. Return _result_. + +
+ + +

Iterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. If IsCallable(_reducer_) is *false*, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. If _initialValue_ is not present, then + 1. Let _accumulator_ be ? IteratorStepValue(_iterated_). + 1. If _accumulator_ is ~done~, throw a *TypeError* exception. + 1. Let _counter_ be 1. + 1. Else, + 1. Let _accumulator_ be _initialValue_. + 1. Let _counter_ be 0. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return _accumulator_. + 1. Let _result_ be Completion(Call(_reducer_, *undefined*, « _accumulator_, _value_, 𝔽(_counter_) »)). + 1. IfAbruptCloseIterator(_result_, _iterated_). + 1. Set _accumulator_ to _result_. + 1. Set _counter_ to _counter_ + 1. + +
+ + +

Iterator.prototype.some ( _predicate_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _counter_ be 0. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return *false*. + 1. Let _result_ be Completion(Call(_predicate_, *undefined*, « _value_, 𝔽(_counter_) »)). + 1. IfAbruptCloseIterator(_result_, _iterated_). + 1. If ToBoolean(_result_) is *true*, return ? IteratorClose(_iterated_, NormalCompletion(*true*)). + 1. Set _counter_ to _counter_ + 1. + +
+ + +

Iterator.prototype.take ( _limit_ )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. Let _numLimit_ be ? ToNumber(_limit_). + 1. If _numLimit_ is *NaN*, throw a *RangeError* exception. + 1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_). + 1. If _integerLimit_ < 0, throw a *RangeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called: + 1. Let _remaining_ be _integerLimit_. + 1. Repeat, + 1. If _remaining_ = 0, then + 1. Return ? IteratorClose(_iterated_, ReturnCompletion(*undefined*)). + 1. If _remaining_ ≠ +∞, then + 1. Set _remaining_ to _remaining_ - 1. + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return ReturnCompletion(*undefined*). + 1. Let _completion_ be Completion(Yield(_value_)). + 1. IfAbruptCloseIterator(_completion_, _iterated_). + 1. Let _result_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterator]] »). + 1. Set _result_.[[UnderlyingIterator]] to _iterated_. + 1. Return _result_. + +
+ + +

Iterator.prototype.toArray ( )

+

This method performs the following steps when called:

+ + 1. Let _O_ be the *this* value. + 1. If _O_ is not an Object, throw a *TypeError* exception. + 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _items_ be a new empty List. + 1. Repeat, + 1. Let _value_ be ? IteratorStepValue(_iterated_). + 1. If _value_ is ~done~, return CreateArrayFromList(_items_). + 1. Append _value_ to _items_. + +
+ + +

Iterator.prototype [ %Symbol.iterator% ] ( )

This function performs the following steps when called:

1. Return the *this* value.

The value of the *"name"* property of this function is *"[Symbol.iterator]"*.

+ + +

Iterator.prototype [ %Symbol.toStringTag% ]

+

`Iterator.prototype[%Symbol.toStringTag%]` is an accessor property with attributes { [[Enumerable]]: *false*, [[Configurable]]: *true* }. The [[Get]] and [[Set]] attributes are defined as follows:

+ + +

get Iterator.prototype [ %Symbol.toStringTag% ]

+

The value of the [[Get]] attribute is a built-in function that requires no arguments. It performs the following steps when called:

+ + 1. Return *"Iterator"*. + +
+ + +

set Iterator.prototype [ %Symbol.toStringTag% ]

+

The value of the [[Set]] attribute is a built-in function that takes an argument _v_. It performs the following steps when called:

+ + 1. Perform ? SetterThatIgnoresPrototypeProperties(*this* value, %Iterator.prototype%, %Symbol.toStringTag%, _v_). + 1. Return *undefined*. + +
+ + +

Unlike the %Symbol.toStringTag% property on most built-in prototypes, for web-compatibility reasons this property must be an accessor.

+
+
@@ -48055,7 +48577,7 @@

The %GeneratorPrototype% Object

  • is %GeneratorFunction.prototype.prototype%.
  • is an ordinary object.
  • is not a Generator instance and does not have a [[GeneratorState]] internal slot.
  • -
  • has a [[Prototype]] internal slot whose value is %IteratorPrototype%.
  • +
  • has a [[Prototype]] internal slot whose value is %Iterator.prototype%.
  • has properties that are indirectly inherited by all Generator instances.
  • @@ -48329,13 +48851,15 @@

    _closure_: an Abstract Closure with no parameters, _generatorBrand_: a String or ~empty~, _generatorPrototype_: an Object, + optional _extraSlots_: a List of names of internal slots, ): a Generator

    1. NOTE: _closure_ can contain uses of the Yield operation to yield an IteratorResult object. - 1. Let _internalSlotsList_ be « [[GeneratorState]], [[GeneratorContext]], [[GeneratorBrand]] ». + 1. If _extraSlots_ is not present, set _extraSlots_ to a new empty List. + 1. Let _internalSlotsList_ be the list-concatenation of _extraSlots_ and « [[GeneratorState]], [[GeneratorContext]], [[GeneratorBrand]] ». 1. Let _generator_ be OrdinaryObjectCreate(_generatorPrototype_, _internalSlotsList_). 1. Set _generator_.[[GeneratorBrand]] to _generatorBrand_. 1. Set _generator_.[[GeneratorState]] to *undefined*.