Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling return() on a suspendedStart iterator helper doesn't seem to call return() on the underlying #266

Closed
syg opened this issue Feb 15, 2023 · 2 comments · Fixed by #267

Comments

@syg
Copy link

syg commented Feb 15, 2023

Iterator helpers are specified as generators whose bodies are Abstract Closures. That is, they start in a suspendedStart state until one of its step methods is called. If you call return() on a helper before next(), this goes to GeneratorResumeAbrupt, which has a fast path for going from suspendedStart -> completed without evaluating anything. AFAICT this won't call return() on the underlying, which is the intention.

@bakkot
Copy link
Collaborator

bakkot commented Feb 15, 2023

Agreed that this is a bug.

I think this can be fixed by adding a special case for suspendedStart in %IteratorHelperPrototype%.return ( ), though it will require moving the iterated record from a captured alias to a slot on the object. (Which is annoying, because the objects are created by CreateIteratorFromClosure, which doesn't currently allow you to specify additional slots on the created object.)

@syg

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants