Repository navigation
Implement ES2025 Iterator helpers (supersedes #2078) - #2541
Open
average-web-dev wants to merge 3 commits into
Open
average-web-dev wants to merge 3 commits into
average-web-dev wants to merge 3 commits into
Conversation
Add the ES2025 global Iterator constructor with Iterator.from and the iterator helper methods (map, filter, take, drop, flatMap, reduce, toArray, forEach, some, every, find), as well as Iterator.concat from the iterator sequencing proposal. The new Iterator is only installed for VERSION_ECMASCRIPT; older language versions keep the legacy JS 1.7 Iterator. All built-in iterators now share a common %Iterator.prototype%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds the ES2025
Iteratorglobal and the iterator helper methods, plusIterator.concatfrom the iterator sequencing proposal. It is a freshimplementation rather than a rebase of #2078, which had conflicts and caused
regressions in unrelated areas of
test262.properties.What's included
Iteratorconstructor: abstract (throws aTypeErrorwhen called orconstructed directly), with
Iterator.prototypenon-writable andnon-configurable.
Iterator.from, including%WrapForValidIteratorPrototype%for iteratorsthat don't inherit from
Iterator.prototype.Iterator.concat.map,filter,take,drop,flatMap, implemented as asmall state machine behind
%IteratorHelperPrototype%. They follow thegenerator state semantics: a reentrant
next()throws, andreturn()behavescorrectly in the suspended-start and suspended-yield states.
reduce,toArray,forEach,some,every,find.Iterator.prototype.constructorand[Symbol.toStringTag]as accessorproperties, using
SetterThatIgnoresPrototypeProperties.validation fails,
nextis read only once (GetIteratorDirect), andIteratorClosekeeps its throw and normal completion semantics.Shared
%Iterator.prototype%All built-in iterators (Array, String, Map, Set, RegExp String, Java
iterators) and generators now inherit from a common
%Iterator.prototype%.Before this change, each iterator prototype defined its own
[Symbol.iterator]and inherited directly fromObject.prototype.Language version instead of a feature flag
Following the discussion in #2078, the new
Iteratoris installed only forContext.VERSION_ECMASCRIPT, with no feature flag. Older language versionskeep the legacy JS 1.7
Iteratorand see no behavior change. For thoseversions only a hidden
%Iterator.prototype%is created, so that built-initerators still share a common prototype.
test262
built-ins/Iterator: 465/510 → 243/510 failing. No new failures in anyother directory.
The remaining failures are outside the scope of this PR:
Iterator.zip/zipKeyed(not yet in the spec)class … extends Iterator(class syntax is unsupported)thisgets boxed, sinceCallable.calltakes aScriptablereceiverSymbol.dispose(explicit resource management)f(...a, ...b)), an existing bug$262) /subclassable.jsTests
New JUnit 5 class
tests/.../es2025/IteratorHelpersTest.java. It covers theprototype chain, the abstract constructor, each helper, laziness, closing of
the underlying iterator on early exit and on validation errors, reentrancy,
from,concat, the accessor properties, and unchanged legacy behavior belowVERSION_ECMASCRIPT.SerializationCoverageTestis updated for the new serializable root(
IteratorRecord).A note on how this was developed
I developed this PR with the help of an AI coding agent (Claude Code), and I
reviewed, tested and take responsibility for all of the changes. If the project
has concerns about or rules for AI-assisted contributions, please let me know.
I'm happy to rework parts of it, split it up, or change my approach.
I'm dyslexic, so I usually let AI help me write or proofread text like this
description. If anything reads unclear, please ask and I'll clarify.
🤖 Generated with Claude Code