Commit 0c699a58 authored by verwaest's avatar verwaest Committed by Commit bot

Don't analyze scopes outside of the compiled scope

The outer scope of the scope we are compiling doesn't need analysis. Either we're compiling top-level code in which case there is no outer scope. Or we are compiling code at the top-level (eval, function, module), and there won't be anything to resolve in the outer scope. Lastly we could also be compiling with a deserialized scope. In that case the outer scope is already resolved.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2224593002
Cr-Commit-Position: refs/heads/master@{#38419}
parent e6822a83
...@@ -376,21 +376,19 @@ int Scope::num_parameters() const { ...@@ -376,21 +376,19 @@ int Scope::num_parameters() const {
void Scope::Analyze(ParseInfo* info) { void Scope::Analyze(ParseInfo* info) {
DCHECK(info->literal() != NULL); DCHECK(info->literal() != NULL);
DeclarationScope* scope = info->literal()->scope(); DeclarationScope* scope = info->literal()->scope();
DeclarationScope* top = scope;
// Traverse the scope tree up to the first unresolved scope or the global // We are compiling one of three cases:
// scope and start scope resolution and variable allocation from that scope. // 1) top-level code,
// Such a scope is always a closure-scope, so always skip to the next closure // 2) a function/eval/module on the top-level
// scope. // 3) a function/eval in a scope that was already resolved.
while (!top->is_script_scope() && DCHECK(scope->scope_type() == SCRIPT_SCOPE ||
!top->outer_scope()->already_resolved()) { scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
top = top->outer_scope()->GetClosureScope(); scope->outer_scope()->already_resolved());
}
// Allocate the variables. // Allocate the variables.
{ {
AstNodeFactory ast_node_factory(info->ast_value_factory()); AstNodeFactory ast_node_factory(info->ast_value_factory());
top->AllocateVariables(info, &ast_node_factory); scope->AllocateVariables(info, &ast_node_factory);
} }
#ifdef DEBUG #ifdef DEBUG
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment