Skip to content

Normative: use Numbers instead of reals as counters in Iterator builtins#3776

Open
michaelficarra wants to merge 1 commit intomainfrom
mathematical-counters
Open

Normative: use Numbers instead of reals as counters in Iterator builtins#3776
michaelficarra wants to merge 1 commit intomainfrom
mathematical-counters

Conversation

@michaelficarra
Copy link
Copy Markdown
Member

@michaelficarra michaelficarra commented Mar 26, 2026

All known engines are currently non-compliant. If they use Numbers as counters today, they'll stop advancing at 253. So counters passed to user-provided callbacks will always be 253 once they reach that point and take/drop will behave as if Infinity was passed. With this change, internal counters are now Numbers, so the argument passed to user-provided callbacks is expected to repeat at 253 (matching implementations today). In addition, take/drop throw a RangeError on finite inputs ≥ 253.

See tc39/proposal-iterator-includes#12 for context.

@michaelficarra michaelficarra added normative change Affects behavior required to correctly evaluate some ECMAScript source text needs consensus This needs committee consensus before it can be eligible to be merged. needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Mar 26, 2026
@github-actions
Copy link
Copy Markdown

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

@bakkot
Copy link
Copy Markdown
Member

bakkot commented Mar 26, 2026

In #2007 we discussed the issue of counters and IIRC agreed that we should specify them as mathematical values with the understanding that implementations would diverge in the same way they diverge from the requirements to have arbitrarily large strings and callstacks and similar. I think that's better than this.

@michaelficarra
Copy link
Copy Markdown
Member Author

Even JSSE, the entirely AI-generated engine, gets this wrong: https://github.com/pmatos/jsse/blob/main/src/interpreter/builtins/iterators.rs. I guess it didn't read the spec...

@michaelficarra michaelficarra force-pushed the mathematical-counters branch from 56466b4 to a5e3a69 Compare March 27, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs consensus This needs committee consensus before it can be eligible to be merged. needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 normative change Affects behavior required to correctly evaluate some ECMAScript source text web reality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants