block scope + direct non-strict eval

Brendan Eich brendan at mozilla.org
Tue Jan 31 13:53:04 PST 2012


On this very thread we are hashing out how eval("let x = ...") interacts 
with the dynamic scope. I started advocating an ES5-like isolaed eval 
lexical scope, and we could do that for let and const -- but var for 
direct eval from non-strict code must affect the dynamic scope, same 
with function in all likelihood (i.e., that's how eval("function 
f(){...}") works now).

We already did the work in ES4/3.1 days, culminating in ES5, to 
distinguish direct from indirect eval. Direct eval from strict code is 
well-defined to have a fresh lexical scope in which to bind vars and 
functions in the eval'ed source:

js> function f(s){"use strict"; eval(s); return g}
js> var g = "global";
js> f("function g(){}")
"global"
js> f("var g=42")
"global"

For strict direct eval, it follows that let and const must bind in the 
fresh lexical scope created for eval. But direct eval from non-strict 
code still faces the two choices Allen outlined.

Indirect eval is always non-strict and scoped only by the global scope.

/be

> Claus Reinke <mailto:claus.reinke at talk21.com>
> January 31, 2012 1:05 PM
>
> Btw, how does versioning work across eval? If I have a function body 
> with an eval in it, will the body/eval run as in ES5 or as in ES6? 
> Will that change if the body or the eval contain ES6 features? Will 
> ES5/ES6
> scripts be able to eval ES6/ES5 code?
>
> Claus
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
> Brendan Eich <mailto:brendan at mozilla.org>
> January 31, 2012 10:23 AM
> I bet the "mode" was what got Sam's attention (mine too) in your 
> "classic mode". We are not making hard mode walls or version opt-in. 
> No engine will have a mode enum that must be advanced (implicitly or 
> explicitly) and checked in order to tell what to do in unversioned 
> script. Or so we think!
>
> /be
>
> Andreas Rossberg <mailto:rossberg at google.com>
> January 31, 2012 10:20 AM
>
> You mean as in: "extend" is the new "eliminate"?
>
> I'm sorry, I couldn't resist...
>
> /Andreas
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
> Allen Wirfs-Brock <mailto:allen at wirfs-brock.com>
> January 31, 2012 9:40 AM
>
> What we agreed to eliminate is the concept of a"classic mode" that 
> corresponds to unextended non-strict ES5. Both non-strict and strict 
> code in ES6 will include support for the extended ES6 language 
> features. In a few cases the semantics of extensions may differ 
> slightly between strict and non-strict code and a few extensions may 
> only be available for use by strict code
>
> Allen
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
> Andreas Rossberg <mailto:rossberg at google.com>
> January 31, 2012 8:44 AM
>
> What do you mean? I don't see how it can be eliminated, except by name 
> games.
>
> /Andreas
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list