@@ -39,6 +39,35 @@ copyright: false
3939 </emu-alg>
4040</emu-clause>
4141
42+ <emu-clause id="sec-iterator.prototype.sliding">
43+ <h1>Iterator.prototype.sliding ( _windowSize_ )</h1>
44+ <p>This method performs the following steps when called:</p>
45+ <emu-alg>
46+ 1. Let _O_ be the *this* value.
47+ 1. If _O_ is not an Object, throw a *TypeError* exception.
48+ 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
49+ 1. If _windowSize_ is not an integral Number in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), then
50+ 1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
51+ 1. Return ? IteratorClose(_iterated_, _error_).
52+ 1. Set _iterated_ to ? GetIteratorDirect(_O_).
53+ 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _windowSize_ and performs the following steps when called:
54+ 1. Let _buffer_ be a new empty List.
55+ 1. Repeat,
56+ 1. Let _value_ be ? IteratorStepValue(_iterated_).
57+ 1. If _value_ is ~done~, then
58+ 1. If _buffer_ is not empty and the number of elements in _buffer_ < ℝ(_windowSize_), perform ? Yield(CreateArrayFromList(_buffer_)).
59+ 1. Return ReturnCompletion(*undefined*).
60+ 1. Append _value_ to _buffer_.
61+ 1. If the number of elements in _buffer_ is ℝ(_windowSize_), then
62+ 1. Let _completion_ be Completion(Yield(CreateArrayFromList(_buffer_))).
63+ 1. IfAbruptCloseIterator(_completion_, _iterated_).
64+ 1. Remove the first element from _buffer_.
65+ 1. Let _result_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterators]] »).
66+ 1. Set _result_.[[UnderlyingIterators]] to « _iterated_ ».
67+ 1. Return _result_.
68+ </emu-alg>
69+ </emu-clause>
70+
4271<emu-clause id="sec-iterator.prototype.windows">
4372 <h1>Iterator.prototype.windows ( _windowSize_ )</h1>
4473 <p>This method performs the following steps when called:</p>
0 commit comments