-
Notifications
You must be signed in to change notification settings - Fork 34
[spec] [[UnderlyingIterator]] -> [[SourceIterators]] so flatMap can proxy return
to the inner iterator also
#278
Conversation
…roxy `return` to the inner iterator also
return
to the inner iterator alsoreturn
to the inner iterator also
I don't think this is necessary. In the non- |
Without this change, if you call |
Yes, it will, per the step named in my comment. This change does not affect anything that happens after the first call to |
@bakkot that covers if |
5.b.ix.4.d actually doesn't cover Rather, it covers the case where the That's how it works in syntactic generators, too: a call to function* gen() {
try {
yield;
} catch {
console.log('not hit');
} finally {
console.log('hit');
}
}
let it = gen();
it.next();
it.return(); // prints 'hit' |
That applies to a generator, but does it also apply to a manually created iterator object with a |
It depends on what the |
OK, so that would mean that in cases like this we don't want the inner non-generator iterator's |
I don't understand your question; can you rephrase or give an example? |
This is the specific test https://github.com/tc39/test262/pull/2818/files#diff-ae62fa2bde6a909c28ea6de018d9e8419cb85a0d813d724448c0eecf995bc954R26 that fails with the current spec, and would pass with this PR. |
That test would pass with the current spec and would not be affected by this PR. The call to |
Thanks, I see what my implementation is missing now (due to me not using syntactic generators). I think this can likely indeed be closed, but since @michaelficarra asked me to open it I'll leave it open until he can confirm. |
I'm satisfied by @bakkot's explanation. We also discussed using |
This closes in the proper order - inner first, then outer - and if both throw, the last exception thrown is the one you see, just like a nested try/finally.
However, this is inconsistent in that flatMap makes ignores the inner iterator's exception and throws the outer one's.
One solution is to make the first exception the one thrown, but that doesn't match try/finally.
Another solution is to throw an AggregateError - either always, or, only when more than one of the
return
methods throws.