← Back to Pull requests

Normative: add Iterator.prototype.chunks and Iterator.prototype.windows #3970

Merged
michaelficarra merged 1 files (71 lines) on Oct 22, 2026 18:08 UTC
View on GitHub
michaelficarra michaelficarra commented on Sep 02, 2026 18:06 UTC
Author
Diff: 71 lines (+71 / -0) across 1 files Reviewer: linusg Review duration: 72002m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.29) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.29 · 71 lines diff across 1 files
0.29
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.82 · 5 substantive comment(s)
0.82
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
85%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.256
Real PR Conversation Timeline
15 items
linusg linusg commented on code on Sep 02, 2026 18:14 UTC
Code Review
spec.html:1
@@ -49382,6 +49382,39 @@ <h1>set Iterator.prototype.constructor</h1>
           </emu-note>
         </emu-clause>
 
+        <emu-clause id="sec-iterator.prototype.chunks" type="built-in function">

It's debatable whether constructor should be listed before other properties, but the status quo is to sort it alphabetically with the rest so chunks should go before it.

(I also acknowledge that most people will not care about a minor ordering issue whatsoever and this is pedantic. :))

github-actions[bot] github-actions[bot] commented on Sep 02, 2026 18:15 UTC
Bot

The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/3970 and as multiple pages at https://tc39.es/ecma262/pr/3970/multipage .

<hidden purpose="for-rewritable-pr-comment-action-use" value="tc39_pr_preview_comment"></hidden>

michaelficarra michaelficarra commented on code on Sep 02, 2026 20:15 UTC
Code Review
spec.html:1
@@ -49382,6 +49382,39 @@ <h1>set Iterator.prototype.constructor</h1>
           </emu-note>
         </emu-clause>
 
+        <emu-clause id="sec-iterator.prototype.chunks" type="built-in function">

I'm kind of surprised by this ordering, but I also generally don't care about section ordering, so okay.

linusg linusg approved these changes on Sep 02, 2026 22:28 UTC
Approved Reviewer

Approved these changes.

nicolo-ribaudo nicolo-ribaudo approved these changes on Sep 16, 2026 09:16 UTC
Approved Reviewer

Approved these changes.

rbuckton rbuckton commented on code on Oct 15, 2026 15:03 UTC
Code Review
spec.html:1
@@ -49356,6 +49356,39 @@ <h1>Properties of the Iterator Prototype Object</h1>
           <pre><code class="javascript">Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()))</code></pre>
         </emu-note>
 
+        <emu-clause id="sec-iterator.prototype.chunks" type="built-in function">
+          <h1>Iterator.prototype.chunks ( _chunkSize_ )</h1>
+          <p>This method performs the following steps when called:</p>
+          <emu-alg>
+            1. Let _obj_ be the *this* value.
+            1. If _obj_ is not an Object, throw a *TypeError* exception.
+            1. Let _iterated_ be the Iterator Record { [[Iterator]]: _obj_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
+            1. If _chunkSize_ is not an integral Number, then
+              1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _chunkSize_ is not in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), then
+              1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. Set _iterated_ to ? GetIteratorDirect(_obj_).
+            1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _chunkSize_ and performs the following steps when called:
+              1. Let _buffer_ be a new empty List.
+              1. Repeat,
+                1. Let _value_ be ? IteratorStepValue(_iterated_).
+                1. If _value_ is ~done~, then
+                  1. If _buffer_ is not empty, then
+                    1. Perform Completion(Yield(CreateArrayFromList(_buffer_))).

Just to clarify, do we expect to ignore exceptions posted back to the iterator via iter.throw() here? The IfAbruptCloseIterator on step 7.iv.2 below expands into an ? IteratorClose(iteratorRecord, value), so would throw when there are still elements remaining.

rbuckton rbuckton commented on code on Oct 15, 2026 15:04 UTC
Code Review
spec.html:1
@@ -49687,6 +49720,44 @@ <h1>Iterator.prototype.toArray ( )</h1>
           </emu-alg>
         </emu-clause>
 
+        <emu-clause id="sec-iterator.prototype.windows" type="built-in function">
+          <h1>Iterator.prototype.windows ( _windowSize_ [ , _undersized_ ] )</h1>
+          <p>This method performs the following steps when called:</p>
+          <emu-alg>
+            1. Let _obj_ be the *this* value.
+            1. If _obj_ is not an Object, throw a *TypeError* exception.
+            1. Let _iterated_ be the Iterator Record { [[Iterator]]: _obj_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
+            1. If _windowSize_ is not an integral Number, then
+              1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _windowSize_ is not in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), then
+              1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _undersized_ is *undefined*, set _undersized_ to *"only-full"*.
+            1. If _undersized_ is neither *"only-full"* nor *"allow-partial"*, then
+              1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. Set _iterated_ to ? GetIteratorDirect(_obj_).
+            1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_, _windowSize_, and _undersized_ and performs the following steps when called:
+              1. Let _buffer_ be a new empty List.
+              1. Repeat,
+                1. Let _value_ be ? IteratorStepValue(_iterated_).
+                1. If _value_ is ~done~, then
+                  1. If _undersized_ is *"allow-partial"*, _buffer_ is not empty, and the number of elements in _buffer_ &lt; ℝ(_windowSize_), then
+                    1. Perform Completion(Yield(CreateArrayFromList(_buffer_))).

Same as above. Are we supposed to ignore exceptions from the final Yield?

bakkot bakkot commented on code on Oct 15, 2026 15:43 UTC
Code Review
spec.html:1
@@ -49356,6 +49356,39 @@ <h1>Properties of the Iterator Prototype Object</h1>
           <pre><code class="javascript">Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()))</code></pre>
         </emu-note>
 
+        <emu-clause id="sec-iterator.prototype.chunks" type="built-in function">
+          <h1>Iterator.prototype.chunks ( _chunkSize_ )</h1>
+          <p>This method performs the following steps when called:</p>
+          <emu-alg>
+            1. Let _obj_ be the *this* value.
+            1. If _obj_ is not an Object, throw a *TypeError* exception.
+            1. Let _iterated_ be the Iterator Record { [[Iterator]]: _obj_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
+            1. If _chunkSize_ is not an integral Number, then
+              1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _chunkSize_ is not in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), then
+              1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. Set _iterated_ to ? GetIteratorDirect(_obj_).
+            1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _chunkSize_ and performs the following steps when called:
+              1. Let _buffer_ be a new empty List.
+              1. Repeat,
+                1. Let _value_ be ? IteratorStepValue(_iterated_).
+                1. If _value_ is ~done~, then
+                  1. If _buffer_ is not empty, then
+                    1. Perform Completion(Yield(CreateArrayFromList(_buffer_))).

There is no %IteratorHelperPrototype%.throw(), and the one on %GeneratorPrototype% has the wrong brand to be used on iterator helpers, so it doesn't come up.

rbuckton rbuckton commented on code on Oct 15, 2026 19:23 UTC
Code Review
spec.html:1
@@ -49687,6 +49720,44 @@ <h1>Iterator.prototype.toArray ( )</h1>
           </emu-alg>
         </emu-clause>
 
+        <emu-clause id="sec-iterator.prototype.windows" type="built-in function">
+          <h1>Iterator.prototype.windows ( _windowSize_ [ , _undersized_ ] )</h1>
+          <p>This method performs the following steps when called:</p>
+          <emu-alg>
+            1. Let _obj_ be the *this* value.
+            1. If _obj_ is not an Object, throw a *TypeError* exception.
+            1. Let _iterated_ be the Iterator Record { [[Iterator]]: _obj_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
+            1. If _windowSize_ is not an integral Number, then
+              1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _windowSize_ is not in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), then
+              1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _undersized_ is *undefined*, set _undersized_ to *"only-full"*.

We don't appear to be consistent with respect to optional parameters in built-in functions/methods. Date.UTC, for example, uses "is present", while String.prototype.endsWith uses "is undefined". We don't appear to call out within the specification what the difference is, nor do we have an editorial convention that calls this out.

ljharb ljharb commented on code on Oct 15, 2026 19:35 UTC
Code Review
spec.html:1
@@ -49687,6 +49720,44 @@ <h1>Iterator.prototype.toArray ( )</h1>
           </emu-alg>
         </emu-clause>
 
+        <emu-clause id="sec-iterator.prototype.windows" type="built-in function">
+          <h1>Iterator.prototype.windows ( _windowSize_ [ , _undersized_ ] )</h1>
+          <p>This method performs the following steps when called:</p>
+          <emu-alg>
+            1. Let _obj_ be the *this* value.
+            1. If _obj_ is not an Object, throw a *TypeError* exception.
+            1. Let _iterated_ be the Iterator Record { [[Iterator]]: _obj_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
+            1. If _windowSize_ is not an integral Number, then
+              1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _windowSize_ is not in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), then
+              1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _undersized_ is *undefined*, set _undersized_ to *"only-full"*.

That's because endsWith is newer, and Date.UTC is legacy. For APIs post-ES6, we don't differentiate absence from undefined (except with cause which is a special case)

bakkot bakkot commented on code on Oct 15, 2026 21:19 UTC
Code Review
spec.html:1
@@ -49687,6 +49720,44 @@ <h1>Iterator.prototype.toArray ( )</h1>
           </emu-alg>
         </emu-clause>
 
+        <emu-clause id="sec-iterator.prototype.windows" type="built-in function">
+          <h1>Iterator.prototype.windows ( _windowSize_ [ , _undersized_ ] )</h1>
+          <p>This method performs the following steps when called:</p>
+          <emu-alg>
+            1. Let _obj_ be the *this* value.
+            1. If _obj_ is not an Object, throw a *TypeError* exception.
+            1. Let _iterated_ be the Iterator Record { [[Iterator]]: _obj_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
+            1. If _windowSize_ is not an integral Number, then
+              1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _windowSize_ is not in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), then
+              1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _undersized_ is *undefined*, set _undersized_ to *"only-full"*.

It's more of a normative convention than an editorial one, and in the normative conventions we say

In most cases, a built-in function being called with fewer arguments than expected is treated the same as being called with undefined for the remaining arguments.

although that could stand to be promoted to its own convention rather than being embedded within a different one.

gibson042 gibson042 approved these changes on Oct 16, 2026 04:40 UTC
Approved Reviewer

Approved these changes.

rbuckton rbuckton approved these changes on Oct 19, 2026 16:56 UTC
Approved Reviewer

Approved these changes.

rbuckton rbuckton commented on code on Oct 19, 2026 17:00 UTC
Code Review
spec.html:1
@@ -49687,6 +49720,44 @@ <h1>Iterator.prototype.toArray ( )</h1>
           </emu-alg>
         </emu-clause>
 
+        <emu-clause id="sec-iterator.prototype.windows" type="built-in function">
+          <h1>Iterator.prototype.windows ( _windowSize_ [ , _undersized_ ] )</h1>
+          <p>This method performs the following steps when called:</p>
+          <emu-alg>
+            1. Let _obj_ be the *this* value.
+            1. If _obj_ is not an Object, throw a *TypeError* exception.
+            1. Let _iterated_ be the Iterator Record { [[Iterator]]: _obj_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
+            1. If _windowSize_ is not an integral Number, then
+              1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _windowSize_ is not in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), then
+              1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
+              1. Return ? IteratorClose(_iterated_, _error_).
+            1. If _undersized_ is *undefined*, set _undersized_ to *"only-full"*.

That's because endsWith is newer, and Date.UTC is legacy. For APIs post-ES6, we don't differentiate absence from undefined (except with cause which is a special case)

And Iterator.prototype.reduce, since there's a difference between no initial value and an initial value of undefined.

Reviewers
Assignees
michaelficarra michaelficarra
Labels
risk: low confidence: 85.9% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 28.6% (LOW) · Higher = larger blast radius
28.6%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 85.9% · Lower = rushed or shallow review
85.9%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 4% · Safe to merge
4%
Repository