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

Closing iterators #838

Closed
rauschma opened this Issue Feb 19, 2015 · 14 comments

Comments

Projects
None yet
3 participants
@rauschma

rauschma commented Feb 19, 2015

In the latest spec, for-of (and others) close iterators (by calling someIterator.return()).

function* foo() {
  yield 'a';
  yield 'b';
}
foo.prototype.return = function (...args) {
  console.log('RETURN');
  return super.return(...args);
};
for (let x of foo()) {
  console.log(x);
  break; // should trigger `return` method
}
@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 19, 2015

Member

Should be easy enough.

Member

kittens commented Feb 19, 2015

Should be easy enough.

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 19, 2015

Member

Although I'll have to make it match this too:

foo: for (let x of foo()) {
  console.log(x);
  break foo; // should trigger `return` method
}
Member

kittens commented Feb 19, 2015

Although I'll have to make it match this too:

foo: for (let x of foo()) {
  console.log(x);
  break foo; // should trigger `return` method
}

@kittens kittens closed this in 8065c98 Feb 21, 2015

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 21, 2015

Member

Done, also handles labels perfectly.

Member

kittens commented Feb 21, 2015

Done, also handles labels perfectly.

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 21, 2015

Member

Released as of 4.4.0, thanks!

Member

kittens commented Feb 21, 2015

Released as of 4.4.0, thanks!

@zloirock

This comment has been minimized.

Show comment
Hide comment
Member

zloirock commented Feb 21, 2015

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 21, 2015

Member

@zloirock Oh jeez, weird.

Member

kittens commented Feb 21, 2015

@zloirock Oh jeez, weird.

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 21, 2015

Member

@zloirock Easy fix, thanks! 61ea720

Member

kittens commented Feb 21, 2015

@zloirock Easy fix, thanks! 61ea720

@zloirock

This comment has been minimized.

Show comment
Hide comment
@zloirock

zloirock Feb 21, 2015

Member

@sebmck iterators may not have this method, see IteratorClose

Member

zloirock commented Feb 21, 2015

@sebmck iterators may not have this method, see IteratorClose

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens
Member

kittens commented Feb 21, 2015

@zloirock Fixed.

@rauschma

This comment has been minimized.

Show comment
Hide comment
@rauschma

rauschma Feb 21, 2015

Note that any kind of abrupt completion leads to return() being called (including exceptions!).

rauschma commented Feb 21, 2015

Note that any kind of abrupt completion leads to return() being called (including exceptions!).

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 21, 2015

Member

Not sure if wrapping the entire block in a try-catch is a good idea.

Member

kittens commented Feb 21, 2015

Not sure if wrapping the entire block in a try-catch is a good idea.

@rauschma

This comment has been minimized.

Show comment
Hide comment
@rauschma

rauschma Feb 21, 2015

Yes, not an easy decision.

rauschma commented Feb 21, 2015

Yes, not an easy decision.

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 21, 2015

Member

I'll push out a patch that fixes the issues @zloirock raised and I'll consider the viability of wrapping it in a try-catch although it doesn't look good.

Member

kittens commented Feb 21, 2015

I'll push out a patch that fixes the issues @zloirock raised and I'll consider the viability of wrapping it in a try-catch although it doesn't look good.

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 27, 2015

Member

for...of loops now close their iterator on abrupt completions. In loose mode this isn't the case.

Member

kittens commented Feb 27, 2015

for...of loops now close their iterator on abrupt completions. In loose mode this isn't the case.

@lock lock bot added the outdated label Jul 28, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Jul 28, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.