fix(runtime): bind this=iterable when calling [Symbol.iterator]() (yield* sync delegation)#4788
Merged
Merged
Conversation
js_get_iterator invoked the [Symbol.iterator]() factory via js_closure_call0
after clone_closure_rebind_this, which only rebinds a closure that *captures*
this. A plain function(){ ...this... } iterator factory reads this dynamically
off IMPLICIT_THIS, which was left as the caller's this — so GetIterator ran the
factory with the wrong this. Set IMPLICIT_THIS=iterable around the call (spec
GetIterator -> Call(method, obj)). Fixes test262 yield-star-sync-* (thisValue of
the [Symbol.iterator] call) and array-prototype destructuring iterator cases.
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.
Follow-up to #4777/#4783 yield* async-generator work. Fixes the
thisbinding of the sync-iterator factory inGetIterator.Root cause
js_get_iteratorinvoked the[Symbol.iterator]()factory viajs_closure_call0afterclone_closure_rebind_this— which only rebinds a closure that capturesthis. A plainfunction(){ …this… }iterator factory readsthisdynamically offIMPLICIT_THIS, which was left as the caller'sthis. SoGetIterator(obj)ran the factory with the wrongthis(spec:GetIterator→Call(method, obj)withthis === obj).Fix
Set
IMPLICIT_THIS = iterablearound the factory call (keeping the existingclone_closure_rebind_thisfor the captures-thiseffect-prototype case).Impact
language/{expressions,statements}/async-generator: 93.8% → 94.7% (pass 833 → 841, compile-fail 0). Fixes theyield-star-sync-*thisValueordering cluster and array-prototype destructuring iterator cases. General correctness fix for allfor-of/ destructuring / spread over an object whose[Symbol.iterator]factory readsthis; verified no regression onfor-ofwith athis-reading custom iterator.Not included (return/throw delegation forwarding)
Attempted
yield*.throw()/.return()forwarding to the delegated iterator (specreceived.[[Type]] is throw/return). It requires the catch/return handler to re-enter the delegation loop, but Perry inlines async-generator catch bodies into the.throw()closure where there is no loop context (continue→ "continue statement outside any loop"). Doing it properly is a deep state-machine rework with real regression risk to the sharedyield*path (Effect / #321) — deferred.