Generator issue: exceptions while initializing arguments

Rick Waldron waldron.rick at gmail.com
Sat Sep 15 06:54:18 PDT 2012


On Sat, Sep 15, 2012 at 2:14 AM, Brendan Eich <brendan at mozilla.org> wrote:

> So to sum up:
>
> 1. Default parameter expressions are evaluated in the activation scope,
> with all formal parameters bound, no use-before-set dead zone (so formals
> are var-like), functions hoisted and in scope -- because in this case,
> simpler and worse are better.
>
> 2. Generator function with default parameters has implicit yield after
> defaulting (which per 1 comes after function hoisting) -- because:
>
>    let n = 0;
>>   function *gen(a = ++n) {}
>>   for (let x of gen()) {}
>>   assert(n === 1);
>>
>
> This is where I am currently, FWIW.


Apologies in advance for making you repeat yourself, but I just want to
circle back to the original question :)

The implicit yield means the thrower example will throw an exception at loc
1, correct?


function thrower() {
  throw "exception";
}

function * G(arg = thrower()) {
   yield arg;
}
let g = G(); // Exception seen here?

Rick




>
>
> /be
> ______________________________**_________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120915/5baacd7f/attachment.html>


More information about the es-discuss mailing list