No changes would be made to the behavior of strict functions. var
declarations in eval
in strict mode do not get hoisted outside of the eval
itself.
-
-
Save bakkot/fb91c5182dc3de0e8833c5c37e533777 to your computer and use it in GitHub Desktop.
variations on parameter scoping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var z = 'outer'; | |
(function ( | |
x = ( | |
eval('var z = "param"; print("eval param1 :=", z)'), | |
print('param1 :=', z) | |
), | |
y = ( | |
eval('print("eval param2 :=", z)'), | |
print('param2 :=', z) | |
), | |
) { | |
var z; | |
print('inner :=', z); | |
})(); | |
print('outer :=', z); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### ** CURRENT SPEC **, SpiderMonkey, V8, XS | |
eval param1 := param | |
param1 := param | |
eval param2 := outer | |
param2 := outer | |
inner := undefined | |
outer := outer | |
#### Chakra | |
eval param1 := param | |
param1 := outer | |
eval param2 := param | |
param2 := outer | |
inner := undefined | |
outer := outer | |
#### JavaScriptCore | |
eval param1 := param | |
param1 := param | |
eval param2 := param | |
param2 := param | |
inner := undefined | |
outer := param | |
#### ** PROPOSED SPEC ** | |
eval param1 := param | |
param1 := param | |
eval param2 := param | |
param2 := param | |
inner := undefined | |
outer := outer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: differs from case one only in the removal of the `var z` in the function body | |
// The output only differs from case one for `inner :=` | |
var z = 'outer'; | |
(function ( | |
x = ( | |
eval('var z = "param"; print("eval param1 :=", z)'), | |
print('param1 :=', z) | |
), | |
y = ( | |
eval('print("eval param2 :=", z)'), | |
print('param2 :=', z) | |
), | |
) { | |
print('inner :=', z); | |
})(); | |
print('outer :=', z); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### ** CURRENT SPEC **, SpiderMonkey, V8, XS | |
eval param1 := param | |
param1 := param | |
eval param2 := outer | |
param2 := outer | |
inner := outer | |
outer := outer | |
#### Chakra | |
eval param1 := param | |
param1 := outer | |
eval param2 := param | |
param2 := outer | |
inner := outer | |
outer := outer | |
#### JavaScriptCore | |
eval param1 := param | |
param1 := param | |
eval param2 := param | |
param2 := param | |
inner := param | |
outer := param | |
#### ** PROPOSED SPEC ** | |
eval param1 := param | |
param1 := param | |
eval param2 := param | |
param2 := param | |
inner := param | |
outer := outer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var z = 'outer'; | |
(function ( | |
x = eval('var z = "param";'), | |
z = 'default', | |
) { | |
print('inner :=', z); | |
})(); | |
print('outer :=', z); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### ** CURRENT SPEC **, JavaScriptCore, SpiderMonkey, V8, XS | |
inner := default | |
outer := outer | |
#### ** PROPOSED SPEC **, Chakra | |
ReferenceError: Let/Const redeclaration | |
(Note: this is an error per the PR because of EvalDeclarationInstantiation 5.d.ii.2.a.i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment