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

Unified Diff: src/ast/scopes.cc

Issue 2237873002: Declare 'this' as DYNAMIC_GLOBAL on the script_scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix places where we declare this, remove shortcut 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
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index 8f24894a8019ac7c42fbb63605d588c6fb2e9060..17a540c16095b709c211c55f1579262cc40b2fa8 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -1252,8 +1252,7 @@ void Scope::CheckZones() {
}
#endif // DEBUG
-Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode,
- Variable::Kind kind) {
+Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone());
VariableMap* map = dynamics_->GetMap(mode);
Variable* var = map->Lookup(name);
@@ -1261,7 +1260,7 @@ Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode,
// Declare a new non-local.
InitializationFlag init_flag = (mode == VAR)
? kCreatedInitialized : kNeedsInitialization;
- var = map->Declare(zone(), NULL, name, mode, kind, init_flag);
+ var = map->Declare(zone(), NULL, name, mode, Variable::NORMAL, init_flag);
// Allocate it by giving it a dynamic lookup.
var->AllocateTo(VariableLocation::LOOKUP, -1);
}
@@ -1273,13 +1272,6 @@ Variable* Scope::LookupRecursive(VariableProxy* proxy,
AstNodeFactory* factory,
Scope* max_outer_scope) {
DCHECK(binding_kind != NULL);
- if (already_resolved() && is_with_scope()) {
adamk 2016/08/11 18:27:17 I'm fine with dropping this check, it's a very str
- // Short-cut: if the scope is deserialized from a scope info, variable
- // allocation is already fixed. We can simply return with dynamic lookup.
- *binding_kind = DYNAMIC_LOOKUP;
- return NULL;
- }
-
// Try to find the variable in this scope.
Variable* var = LookupLocal(proxy->raw_name());
@@ -1315,14 +1307,13 @@ Variable* Scope::LookupRecursive(VariableProxy* proxy,
bool name_can_be_shadowed = var == nullptr || !var->is_this();
if (is_with_scope() && name_can_be_shadowed) {
adamk 2016/08/11 18:27:17 This code has moved around due to your other CL, t
Toon Verwaest 2016/08/12 04:49:40 It was a cleanup in the sense that doesn't have un
- DCHECK(!already_resolved());
// The current scope is a with scope, so the variable binding can not be
// statically resolved. However, note that it was necessary to do a lookup
// in the outer scope anyway, because if a binding exists in an outer scope,
// the associated variable has to be marked as potentially being accessed
// from inside of an inner with scope (the property may not be in the 'with'
// object).
- if (var != NULL) {
+ if (!already_resolved() && var != NULL) {
var->set_is_used();
var->ForceContextAllocation();
if (proxy->is_assigned()) var->set_maybe_assigned();
@@ -1385,9 +1376,6 @@ 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;
@@ -1398,29 +1386,30 @@ 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, kind);
+ var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL);
} else if (var->is_dynamic()) {
- var = NonLocal(proxy->raw_name(), DYNAMIC, kind);
+ var = NonLocal(proxy->raw_name(), DYNAMIC);
} else {
Variable* invalidated = var;
- var = NonLocal(proxy->raw_name(), DYNAMIC_LOCAL, kind);
+ var = NonLocal(proxy->raw_name(), DYNAMIC_LOCAL);
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(), kind);
+ var = info->script_scope()->DeclareDynamicGlobal(proxy->raw_name(),
+ Variable::NORMAL);
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, kind);
+ var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL);
break;
case DYNAMIC_LOOKUP:
// The variable could not be resolved statically.
- var = NonLocal(proxy->raw_name(), DYNAMIC, kind);
+ var = NonLocal(proxy->raw_name(), DYNAMIC);
break;
}
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.cc » ('j') | src/parsing/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698