Generator issue: exceptions while initializing arguments

Brendan Eich brendan at mozilla.org
Sat Sep 15 12:39:06 PDT 2012


Rick Waldron wrote:
> On Sat, Sep 15, 2012 at 2:14 AM, Brendan Eich <brendan at mozilla.org 
> <mailto: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?

Yes, back to loc 1. Kevin Smith made the


     function* g(a, b = makeTheWorldABetterPlace()) { ... }

     let iter = g(123);
     // Is the world a better place yet?  I hope so.


  case and I tried beefing it up with the empty generator and single 
parameter with default value example (assert(n === 1) after, above).

/be


More information about the es-discuss mailing list