Implement ES2025 Iterator.from() static method #2082
Closed
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.
Summary
This PR adds the Iterator.from() static method, continuing the ES2025 iterator helpers implementation started in #2078.
What's Added
Iterator.from() converts any iterable or iterator-like object into a proper iterator that inherits from Iterator.prototype. This includes:
Implementation Approach
The IteratorWrapper class follows the same pattern as NativeArrayIterator - it extends ES6Iterator and uses the standard delegation pattern through isDone() and nextValue(). This keeps things consistent with how Rhino handles iterators elsewhere in the codebase.
The wrapper also handles return() and throw() methods when they exist on the underlying iterator, ensuring proper cleanup and error propagation.
Known Limitation
The global Iterator constructor isn't exposed yet because it conflicts with the legacy Iterator() function that's used for Java interop. We'll need to figure out a migration path for this before the full iterator helpers can be used from JavaScript.
Testing
Basic tests verify that Iterator.prototype exists with the right Symbol properties. The infrastructure is ready for more comprehensive testing once we resolve the global naming conflict.
Part of #1696
Depends on #2078