block scope + direct non-strict eval

Brendan Eich brendan at mozilla.org
Tue Jan 31 10:13:29 PST 2012


> Andy Wingo <mailto:wingo at igalia.com>
> January 31, 2012 9:07 AM
> Summary: eval introduces a new block scope.

And there's a new var scope per direct eval call in strict code, per 
ES5. Adding 'let' must not reintroduce the pre-strict crazy ;-).
>
>>>   (function (){let x = 20; eval("var x = 10"); return x;})()
>> 10
>
> Surely a SyntaxError, as the var x conflicts with the let x at the
> function-level scope?

Oops, you're right. This is non-strict direct eval, so the var hoists 
and collides with the 'let'. Thanks!

/be
>
> Andy
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
> Sam Tobin-Hochstadt <mailto:samth at ccs.neu.edu>
> January 31, 2012 8:27 AM
> On Tue, Jan 31, 2012 at 9:30 AM, Andy Wingo<wingo at igalia.com>  wrote:
>> Hello ecmascriptians,
>>
>> I hear that TC39 wants to allow let and const into "classic mode".  This
>> sounds like a bad idea to me, but, ok.
>
> Instead, I would say that TC39 wants to eliminate the concept of "classic mode".
>
>> If so, can someone say what these expressions would evaluate to, or the
>> errors they would raise:
>
> I don't think we've talked about the behavior of direct |eval| on
> statements with |let|, but here's what I would hope we'd do:
>
>>   (function (){eval("let x = 10"); return x;})()
>
> ReferenceError
>
>>   (function (){var x = 20; eval("let x = 10"); return x;})()
>>   (function (){let x = 20; eval("let x = 10"); return x;})()
>>   (function (){let x = 20; { eval("let x = 10"); return x;}})()
>>   (function (){ { let x = 20; { eval("let x = 10"); return x;}}})()
>
> 20
>
>>   (function (){let x = 20; eval("var x = 10"); return x;})()
>
> 10
> Andy Wingo <mailto:wingo at igalia.com>
> January 31, 2012 6:30 AM
> Hello ecmascriptians,
>
> I hear that TC39 wants to allow let and const into "classic mode". This
> sounds like a bad idea to me, but, ok.
>
> If so, can someone say what these expressions would evaluate to, or the
> errors they would raise:
>
> (function (){eval("let x = 10"); return x;})()
>
> (function (){var x = 20; eval("let x = 10"); return x;})()
>
> (function (){let x = 20; eval("let x = 10"); return x;})()
>
> (function (){let x = 20; { eval("let x = 10"); return x;}})()
>
> (function (){let x = 20; eval("var x = 10"); return x;})()
>
> (function (){ { let x = 20; { eval("let x = 10"); return x;}}})()
>
> As Leibniz would have it, let us calculate.
>
> Andy
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list