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

Unified Diff: src/scopes.cc

Issue 24023: Rearrange the code in Scope::ResolveVariable.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/local-load-from-eval.js » ('j') | test/mjsunit/local-load-from-eval.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopes.cc
===================================================================
--- src/scopes.cc (revision 1317)
+++ src/scopes.cc (working copy)
@@ -608,25 +608,9 @@
// a local or outer eval() call, or an outer 'with' statement),
// or we don't know about the outer scope (because we are
// in an eval scope).
- if (!is_global_scope() &&
- (scope_inside_with_ || outer_scope_is_eval_scope_)) {
- // If we are inside a with statement or the code is executed
- // using eval, we give up and look up the variable at runtime.
- var = NonLocal(proxy->name(), Variable::DYNAMIC);
-
- } else if (!is_global_scope() &&
- (scope_calls_eval_ || outer_scope_calls_eval_)) {
- // If the code is not executed using eval and there are no
- // with scopes, either we have a local or a global variable
- // that might be shadowed by an eval-introduced variable.
- if (invalidated_local != NULL) {
- var = NonLocal(proxy->name(), Variable::DYNAMIC_LOCAL);
- var->set_local_if_not_shadowed(invalidated_local);
- } else {
- var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL);
- }
-
- } else {
+ if (is_global_scope() ||
+ !(scope_inside_with_ || outer_scope_is_eval_scope_ ||
+ scope_calls_eval_ || outer_scope_calls_eval_)) {
// We must have a global variable.
ASSERT(global_scope != NULL);
var = new Variable(global_scope, proxy->name(),
@@ -639,6 +623,32 @@
// latter returns undefined. Sigh...
// var->rewrite_ = new Property(new Literal(env_->global()),
// new Literal(proxy->name()));
+
+ } else if (scope_inside_with_) {
+ // If we are inside a with statement we give up and look up
+ // the variable at runtime.
+ var = NonLocal(proxy->name(), Variable::DYNAMIC);
+
+ } else if (invalidated_local != NULL) {
+ // No with statements are involved and we found a local
+ // variable that might be shadowed by eval introduced
+ // variables.
+ var = NonLocal(proxy->name(), Variable::DYNAMIC_LOCAL);
+ var->set_local_if_not_shadowed(invalidated_local);
+
+ } else if (outer_scope_is_eval_scope_) {
+ // No with statements and we did not find a local and the code
+ // is executed with a call to eval. We don't know anything
+ // because we do not have information about the scopes
+ // surrounding the eval call.
+ var = NonLocal(proxy->name(), Variable::DYNAMIC);
+
+ } else {
+ // No with statements and we did not find a local and the code
+ // is not executed with a call to eval. We know that this
+ // variable is global unless it is shadowed by eval-introduced
+ // variables.
+ var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL);
}
}
}
« no previous file with comments | « no previous file | test/mjsunit/local-load-from-eval.js » ('j') | test/mjsunit/local-load-from-eval.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698