a weird yield* edge case

Kevin Smith zenparsing at gmail.com
Sat Jan 31 19:06:41 PST 2015

> I should have said, "when for-of" invokes the close method, because of an
> exception and the close produces a different exception.

Ah yes.  I think those semantics, as currently specified, are right on.

So what would we expect an inner iterator to do, if it supports "return"
but not "throw"?  What would an equivalent "throw" method, in such a
situation, look like?

If it doesn't have a "throw" method then that means that it cannot usefully
process errors.  One generator function which fits that description might

    function* a() {
        try {
            yield 1;
        } finally {

If we call "throw" on a generator produced by this function (when the
generator is paused within the try block), the finally block will run and
then the thrown exception will propagate back to the caller.

So it seems to me that not having a throw method should be equivalent to
something like:

    throw(value) {
        var r = this.return;
        if (r !== undefined)
        throw value;

But I can see the argument for a TypeError (and not calling "return") as
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150131/3feb2ac3/attachment.html>

More information about the es-discuss mailing list