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

Unified Diff: src/ast/scopes.cc

Issue 2231813003: Make Variable::is_this always return the correct value (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 4 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 | « src/ast/scopes.h ('k') | src/ast/variables.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index 4d7ddd2ca8c10a03882cc84119ab01d51e37069e..f7cbdd4279bcb03a94d70c6052ec70ba478bba91 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -670,10 +670,11 @@ Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode,
maybe_assigned_flag);
}
-Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name) {
+Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name,
+ Variable::Kind kind) {
DCHECK(is_script_scope());
- return variables_.Declare(zone(), this, name, DYNAMIC_GLOBAL,
- Variable::NORMAL, kCreatedInitialized);
+ return variables_.Declare(zone(), this, name, DYNAMIC_GLOBAL, kind,
+ kCreatedInitialized);
}
@@ -1242,16 +1243,15 @@ void Scope::CheckZones() {
}
#endif // DEBUG
-
-Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
+Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode,
+ Variable::Kind kind) {
if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone());
VariableMap* map = dynamics_->GetMap(mode);
Variable* var = map->Lookup(name);
if (var == NULL) {
// Declare a new non-local.
DCHECK(!IsLexicalVariableMode(mode));
- var = map->Declare(zone(), NULL, name, mode, Variable::NORMAL,
- kCreatedInitialized);
+ var = map->Declare(zone(), NULL, name, mode, kind, kCreatedInitialized);
// Allocate it by giving it a dynamic lookup.
var->AllocateTo(VariableLocation::LOOKUP, -1);
}
@@ -1381,6 +1381,9 @@ void Scope::ResolveTo(ParseInfo* info, BindingKind binding_kind,
}
#endif
+ // TODO(verwaest): 'this' should always be declared and found. That way we can
+ // remove this workaround.
+ Variable::Kind kind = proxy->is_this() ? Variable::THIS : Variable::NORMAL;
switch (binding_kind) {
case BOUND:
break;
@@ -1391,29 +1394,29 @@ void Scope::ResolveTo(ParseInfo* info, BindingKind binding_kind,
// scope which was not promoted to a context, this can happen if we use
// debugger to evaluate arbitrary expressions at a break point).
if (var->IsGlobalObjectProperty()) {
- var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL);
+ var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL, kind);
} else if (var->is_dynamic()) {
- var = NonLocal(proxy->raw_name(), DYNAMIC);
+ var = NonLocal(proxy->raw_name(), DYNAMIC, kind);
} else {
Variable* invalidated = var;
- var = NonLocal(proxy->raw_name(), DYNAMIC_LOCAL);
+ var = NonLocal(proxy->raw_name(), DYNAMIC_LOCAL, kind);
var->set_local_if_not_shadowed(invalidated);
}
break;
case UNBOUND:
// No binding has been found. Declare a variable on the global object.
- var = info->script_scope()->DeclareDynamicGlobal(proxy->raw_name());
+ var = info->script_scope()->DeclareDynamicGlobal(proxy->raw_name(), kind);
break;
case UNBOUND_EVAL_SHADOWED:
// No binding has been found. But some scope makes a sloppy 'eval' call.
- var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL);
+ var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL, kind);
break;
case DYNAMIC_LOOKUP:
// The variable could not be resolved statically.
- var = NonLocal(proxy->raw_name(), DYNAMIC);
+ var = NonLocal(proxy->raw_name(), DYNAMIC, kind);
break;
}
« no previous file with comments | « src/ast/scopes.h ('k') | src/ast/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698