14:59 | <Dominic Farolino> | I'm observing that for-await...of loops don't call an async iterator's return method upon exhaustion, but do run async generator finally blocks. But don't these loops always call AsyncIteratorClose() (https://tc39.es/ecma262/#_ref_6951), which I think would indeed run the return method on any async iterator? What am I missing? |
15:13 | <nicolo-ribaudo> | They only call AsyncIteratorClose if you exit early (either due to an error in the head, or an error/return/break in the body) |
15:14 | <nicolo-ribaudo> | They still run finally blocks because they run as part of the evaluation of the async generator body before yielding control back to the for-await loop. The for-await loop doesn't "see" that the finally block exists |
15:24 | <bakkot> | specifically the normal exit is step 6.e of ForIn/OfBodyEvaluation |
15:24 | <bakkot> | 6.l is the break/throw/return case |