Normative: iterator helpers close receiver on argument validation failure #3467
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.
The general rule when working with iterators / iterables is that once you get an iterator it is your responsibility to close it when you're done with it, unless it errors out or completes. We're consistent about this when we get the iterator from an iterable, and in some of the places where we get the iterator directly (e.g. in
Set.prototype.isDisjointFrom
step 5.c.ii.1.a), but as pointed out by @zloirock, iterator helpers don't close their receiver when one of their argument is invalid. Since iterator helpers are conceptually "take ownership" of their receiver (either by consuming it fully, or by closing the receiver when the iterator helper itself is closed), and since an argument failing validation is not an error of the underlying iterator, helpers should close their receiver in this case to be consistent with the general rule above.Unfortunately
IfAbruptCloseIterator
andIteratorClose
both take an Iterator Record, not the iterator object itself, and we don't construct the Iterator Record until after argument validation. So we have to make a "partial" Iterator Record for use by these methods. (It's still a well-typed Iterator Record.) This is a spec fiction to simplify the spec text and doesn't need to correspond to anything in an actual implementation.