Generator issue: exceptions while initializing arguments
Brendan Eich
brendan at mozilla.org
Sat Sep 8 15:47:54 PDT 2012
Sorry to over-reply. This *does* work in SpiderMonkey:
js> function f(a = g) { function g(){}; yield a; }
js> var it = f()
js> it.next()
function g(){}
/be
Brendan Eich wrote:
> SpiderMonkey (Firefox 15 and newer has default parameters):
>
> js> function f(a = g) { function g(){}; return a; }
> js> f()
> function g(){}
>
> So function g is hoisted and a defaults to it, as expected.
>
> The trivial generator variant, i.e., what you get by putting a * after
> function and before f, above:
>
> js> function* f(a = g) { function g() {}; return a; }
> js> var it = f();
> js> it.next();
> function g(){}
>
> (note well, not yet implemented in SpiderMonkey) should behave the
> same, or crazypants.
>
> /be
>
> Brendan Eich wrote:
>> Brendan Eich wrote:
>>>> However, the semantics of parameter default value initialization
>>>> can result in exceptions and more closely links argument
>>>> instantiations with the actual activation of the generator
>>>> function. You can't really build the parameter bindings without
>>>> performing declaration instantiation for the function.
>>>
>>> Agreed, that's absolutely true (no "really" about it -- or rather,
>>> "for real" ;-).
>>
>> And (I should have written), if your point was that we must bind all
>> var and top level function/let/const declarations before the implicit
>> yield; inserted "after the opening brace", I don't see a problem.
>> Hoisted functions with usable initial values, hoisted vars with
>> undefined initial values, and temporal dead zones for the let and
>> const declarations that are at top (generator body) level. Right?
>>
>> /be
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
More information about the es-discuss
mailing list