Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Issue 8508052: Static resolution of outer variables in eval code. (Closed)

Created:
9 years, 1 month ago by Steven
Modified:
9 years, 1 month ago
CC:
v8-dev
Visibility:
Public.

Description

Static resolution of outer variables in eval code. So far free variables references in eval code are not statically resolved. For example in function foo() { var x = 1; eval("y = x"); } the variable x will get mode DYNAMIC and y will get mode DYNAMIC_GLOBAL, i.e. free variable references trigger dynamic lookups with a fast case handling for global variables. The CL introduces static resolution of free variables references in eval code. If possible variable references are resolved to bindings belonging to outer scopes of the eval call site. This is achieved by deserializing the outer scope chain using Scope::DeserializeScopeChain prior to parsing the eval code similar to lazy parsing of functions. The existing code for variable resolution is used, however resolution starts at the first outer unresolved scope instead of always starting at the root of the scope tree. This is a prerequisite for statically checking validity of assignments in the extended code as specified by the current ES.next draft which will be introduced by a subsequent CL. More specifically section 11.13 of revision 4 of the ES.next draft reads: * It is a Syntax Error if the AssignmentExpression is contained in extended code and the LeftHandSideExpression is an Identifier that does not statically resolve to a declarative environment record binding or if the resolved binding is an immutable binding. TEST=existing tests in mjsunit Committed: http://code.google.com/p/v8/source/detail?r=9999

Patch Set 1 #

Total comments: 4

Patch Set 2 : Addressed comments. #

Total comments: 6

Patch Set 3 : Addressed comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+147 lines, -188 lines) Patch
M src/compiler.h View 1 3 chunks +7 lines, -0 lines 0 comments Download
M src/compiler.cc View 1 3 chunks +3 lines, -0 lines 0 comments Download
M src/contexts.h View 1 chunk +0 lines, -13 lines 0 comments Download
M src/contexts.cc View 1 chunk +0 lines, -56 lines 0 comments Download
M src/parser.h View 1 2 chunks +3 lines, -7 lines 0 comments Download
M src/parser.cc View 1 10 chunks +55 lines, -33 lines 0 comments Download
M src/runtime.cc View 1 1 chunk +6 lines, -9 lines 0 comments Download
M src/scopes.h View 1 4 chunks +9 lines, -7 lines 0 comments Download
M src/scopes.cc View 1 2 16 chunks +59 lines, -60 lines 0 comments Download
M test/cctest/test-parsing.cc View 1 2 chunks +5 lines, -3 lines 0 comments Download

Messages

Total messages: 8 (0 generated)
Steven
PTAL.
9 years, 1 month ago (2011-11-10 11:44:19 UTC) #1
Kevin Millikin (Chromium)
Drive by comment. http://codereview.chromium.org/8508052/diff/1/src/runtime.cc File src/runtime.cc (right): http://codereview.chromium.org/8508052/diff/1/src/runtime.cc#newcode12232 src/runtime.cc:12232: // Create a function context first, ...
9 years, 1 month ago (2011-11-10 12:55:20 UTC) #2
Steven
Please take another look. http://codereview.chromium.org/8508052/diff/1/src/runtime.cc File src/runtime.cc (right): http://codereview.chromium.org/8508052/diff/1/src/runtime.cc#newcode12232 src/runtime.cc:12232: // Create a function context ...
9 years, 1 month ago (2011-11-11 08:35:04 UTC) #3
fschneider
I did not get through all the files yet. Here are my first comments. Also ...
9 years, 1 month ago (2011-11-14 15:20:51 UTC) #4
fschneider
lgtm
9 years, 1 month ago (2011-11-15 10:13:56 UTC) #5
Steven
http://codereview.chromium.org/8508052/diff/6020/src/scopes.cc File src/scopes.cc (right): http://codereview.chromium.org/8508052/diff/6020/src/scopes.cc#newcode132 src/scopes.cc:132: ASSERT((type == GLOBAL_SCOPE) == (outer_scope == NULL)); On 2011/11/14 ...
9 years, 1 month ago (2011-11-15 11:53:23 UTC) #6
fschneider
lgtm http://codereview.chromium.org/8508052/diff/6020/src/scopes.cc File src/scopes.cc (right): http://codereview.chromium.org/8508052/diff/6020/src/scopes.cc#newcode269 src/scopes.cc:269: !top->outer_scope()->already_resolved()) { On 2011/11/15 11:53:23, Steven wrote: > ...
9 years, 1 month ago (2011-11-15 12:06:45 UTC) #7
Steven
9 years, 1 month ago (2011-11-15 13:51:15 UTC) #8
http://codereview.chromium.org/8508052/diff/6020/src/scopes.cc
File src/scopes.cc (right):

http://codereview.chromium.org/8508052/diff/6020/src/scopes.cc#newcode269
src/scopes.cc:269: !top->outer_scope()->already_resolved()) {
On 2011/11/15 12:06:46, fschneider wrote:
> On 2011/11/15 11:53:23, Steven wrote:
> > I've updated the comment with a more thorough description.
> > On 2011/11/14 15:20:52, fschneider wrote:
> > > This loop condition seems inconsistent with the comment.
> > 
> 
> Maybe say: Traverse until the first unresolved scope or the global scope.

Done.

Powered by Google App Engine
This is Rietveld 408576698