Bug 167328
Summary: | strict mode eval doesn't initialize functions with the proper scope | ||
---|---|---|---|
Product: | WebKit | Reporter: | Saam Barati <saam> |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | REOPENED | ||
Severity: | Normal | CC: | benjamin, fpizlo, ggaren, gskachkov, jfbastien, keith_miller, manian, mark.lam, msaboff, oliver, ticaiolima, WebkitBugTracker, ysuzuki |
Priority: | P2 | ||
Version: | WebKit Local Build | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Saam Barati
They don't have access to the eval's lexical variables at the top level. For example, this doesn't work:
eval("'use strict'; let x = 20; function foo() { return x; }; foo();")
But these do:
eval("'use strict'; let x = 20; let foo = function() { return x; }; foo();")
eval("'use strict'; let x = 20; let y; { function foo() { return x; }; y =foo;} y();")
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Saam Barati
*** This bug has been marked as a duplicate of bug 163208 ***
Saam Barati
This isn't a duplicate.
Saam Barati
I think we should simplify how we do variables in strict mode eval.
Currently, we rely on Interpreter::execute(Eval) to create a StrictEvalActivation that contains the "function" and "var" variables in it. However, I think this is probably unnecessary. I think we can do all of this in bytecode and just create a normal JSLexicalEnvironment for the "var" variables and "function" variables inside the bytecode generator (as long as we're in strict mode). If we're in sloppy mode, we should continue to do what we do now.
Anybody have thoughts on this? Am I missing something that would make this not Just Work?