Use global Iterator.prototype
for down-level generators
#59514
Merged
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.
If you are compiling generators with
--target ES5 --lib esnext
the types of those generators will also include the iterator helpers methods likemap
,filter
, etc., though our down-level generator emit will not have those methods even when running with newer editions of V8 that do support them:Even when not running in latest V8, iterator helpers can be polyfilled, e.g.:
To better support both scenarios, this makes a small change to our
__generator
helper to use the globalIterator.prototype
object as the prototype for down-level generators, if it is present.This also does the same for our
__asyncGenerator
helper when a globalAsyncIterator.prototype
object is present, even though async iterator helpers are still at Stage 2. Support forAsyncIterator.prototype
seems harmless enough to add at this time but can be postponed to a later PR if necessary.Please note that this will also require the same change in
tslib
.Fixes #59513