Bug 167328 - strict mode eval doesn't initialize functions with the proper scope
Summary: strict mode eval doesn't initialize functions with the proper scope
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2017-01-23 15:10 PST by Saam Barati
Modified: 2017-01-25 12:16 PST (History)
13 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
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?