for-of loops, IteratorClose and the rest of the iterations in the spec
allen at wirfs-brock.com
Wed Sep 10 09:32:08 PDT 2014
On Sep 10, 2014, at 9:00 AM, Andreas Rossberg wrote:
> On 10 September 2014 17:56, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>> We agree at our June meeting to add the "return" method to generators and to
>> conditionally call "return" (if it is present) when a for-of loop terminates
>> before it exhausts its generator. See
>> . IteratorClose is part of the implementation of this features and was
>> added in Rev 27 of the spec.
>> I believe that #1 is implicit in that decision as it has always been an ES6
>> goal that most library methods should be self-hostable in ES. That means
>> that for-of like iteration in those methods should be specified in a manner
>> that matches the observable semantics of for-of.
> It wasn't all that clear to me, but that's good to hear. Does a
> similar argument apply to constructs like rest and spread?
Yes, except that I don't think the "body" of those loops can actually abnormally exit (or in the case of processing parameter lists, the iterator is an internal list iterator that doesn't have a 'return'). But that code should be reviewed to make sure I don't miss something.
More information about the es-discuss