yield* desugaring

Andreas Rossberg rossberg at google.com
Mon May 13 10:42:12 PDT 2013

On 13 May 2013 17:58, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> Every other place in the language (syntax and built-in functions) where we expect Iterables we transparently accept either iterator or generator objects.  Why should yield* be any different.

Generators are subtypes of iterators, but not the other way round. So
it is to be expected that there are contexts where you can use the
latter but not the former. And 'yield' is quite naturally a feature of

> However, there is another alternative to close that addresses the finally issue.  I can make it statically illegal for a "yield" statement to be nested within a block that is protected by a "finally".  This preserve the integrity of "finally" which is my only concern.  It also address the for-of early exit issues. This restriction is trivial to specify (and should be only slightly less trivial to implement). Since I don't currently have "close" in the spec.  I probably should have done this anyway.

Yes, we had the same discussion in the V8 team the other week. It's a
reasonable restriction, but it's also an ad-hoc restriction, which I'm
personally not overly fond of. Moreover, there might be use cases
where you control both definition and consumption of a generator, so
that using finally might be safe and sensible. (On the other hand,
there aren't really many meaningful use cases for finally to start
with, so I don't worry too much about that.)

In short, I could live with that, but don't think it's necessary.


More information about the es-discuss mailing list