tc39 / proposal-set-methods

Proposal for new Set methods in JS
https://tc39.github.io/proposal-set-methods/
Other
655 stars 15 forks source link

Normative: close keys iterators in early exits #85

Closed bakkot closed 1 year ago

bakkot commented 1 year ago

Fixes https://github.com/tc39/proposal-set-methods/issues/81.

zloirock commented 1 year ago

Why? It should work with Set-like objects, Set iterators have no .return method - this is an extension of iterators protocol not related to this case. However, it's extra work for implementations and extra problems for optimization.

bakkot commented 1 year ago

Right now it's an invariant in the specification that every iteration of an iterator will either exhaust the iterator, hit an error condition in the iterator, or close the iterator. I would like to preserve that invariant. I don't think we want to make "does not have a .return method on its .keys iterator" part of the definition of "Set-like objects".

zloirock commented 1 year ago

I don't think that such a definition is worse than the overcomplication of this method.

bakkot commented 1 year ago

I am pretty strongly on the side of preserving the invariant that the spec closes iterators.