Bug 167328

Summary: strict mode eval doesn't initialize functions with the proper scope
Product: WebKit Reporter: Saam Barati <saam>
Component: JavaScriptCoreAssignee: 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   

Description Saam Barati 2017-01-23 15:10:12 PST
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();")
Comment 1 Saam Barati 2017-01-23 15:18:57 PST

*** This bug has been marked as a duplicate of bug 163208 ***
Comment 2 Saam Barati 2017-01-25 11:20:03 PST
This isn't a duplicate.
Comment 3 Saam Barati 2017-01-25 12:06:58 PST
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?