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

Unified Diff: src/ast/scopes.cc

Issue 2274133002: Add function-var to variables_ so LookupRecursive doesn't need to special-case it (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge Created 4 years, 3 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/parsing/parser.cc » ('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 e2c2ad4e9d16cdbc3bf46bd149b79386917f42a4..3073ddbec16a173f0349263e76ed205de3b701ec 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -624,10 +624,16 @@ void DeclarationScope::DeclareDefaultFunctionVariables(
Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name) {
DCHECK(is_function_scope());
DCHECK_NULL(function_);
+ DCHECK_NULL(variables_.Lookup(name));
VariableKind kind = is_sloppy(language_mode()) ? SLOPPY_FUNCTION_NAME_VARIABLE
: NORMAL_VARIABLE;
function_ =
new (zone()) Variable(this, name, CONST, kind, kCreatedInitialized);
+ if (calls_sloppy_eval()) {
+ NonLocal(name, DYNAMIC);
+ } else {
+ variables_.Add(function_);
+ }
return function_;
}
@@ -766,7 +772,15 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name) {
index = scope_info_->ModuleIndex(name_handle, &mode, &init_flag,
&maybe_assigned_flag);
}
- if (index < 0) return nullptr; // Nowhere found.
+
+ if (index < 0) {
+ index = scope_info_->FunctionContextSlotIndex(*name_handle);
+ if (index < 0) return nullptr; // Nowhere found.
+ Variable* var = AsDeclarationScope()->DeclareFunctionVar(name);
+ DCHECK_EQ(CONST, var->mode());
+ var->AllocateTo(VariableLocation::CONTEXT, index);
+ return variables_.Lookup(name);
+ }
VariableKind kind = NORMAL_VARIABLE;
if (location == VariableLocation::CONTEXT &&
@@ -782,22 +796,6 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name) {
return var;
}
-Variable* DeclarationScope::LookupFunctionVar(const AstRawString* name) {
- if (function_ != nullptr && function_->raw_name() == name) {
- return function_;
- } else if (!scope_info_.is_null()) {
- // If we are backed by a scope info, try to lookup the variable there.
- int index = scope_info_->FunctionContextSlotIndex(*(name->string()));
- if (index < 0) return nullptr;
- Variable* var = DeclareFunctionVar(name);
- var->AllocateTo(VariableLocation::CONTEXT, index);
- return var;
- } else {
- return nullptr;
- }
-}
-
-
Variable* Scope::Lookup(const AstRawString* name) {
for (Scope* scope = this;
scope != NULL;
@@ -1455,16 +1453,6 @@ Variable* Scope::LookupRecursive(VariableProxy* proxy, Scope* outer_scope_end) {
// remains the same.)
if (var != nullptr) return var;
- // We did not find a variable locally. Check against the function variable, if
- // any.
- if (is_function_scope()) {
- var = AsDeclarationScope()->LookupFunctionVar(proxy->raw_name());
- if (var != nullptr) {
- if (calls_sloppy_eval()) return NonLocal(proxy->raw_name(), DYNAMIC);
- return var;
- }
- }
-
if (outer_scope_ == outer_scope_end) {
// We may just be trying to find all free variables. In that case, don't
// declare them in the outer scope.
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698