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}
This commit is contained in:
verwaest 2016-08-08 01:47:48 -07:00 committed by Commit bot
parent e6822a8338
commit 0c699a5819

View File

@ -376,21 +376,19 @@ int Scope::num_parameters() const {
void Scope::Analyze(ParseInfo* info) {
DCHECK(info->literal() != NULL);
DeclarationScope* scope = info->literal()->scope();
DeclarationScope* top = scope;
// Traverse the scope tree up to the first unresolved scope or the global
// scope and start scope resolution and variable allocation from that scope.
// Such a scope is always a closure-scope, so always skip to the next closure
// scope.
while (!top->is_script_scope() &&
!top->outer_scope()->already_resolved()) {
top = top->outer_scope()->GetClosureScope();
}
// We are compiling one of three cases:
// 1) top-level code,
// 2) a function/eval/module on the top-level
// 3) a function/eval in a scope that was already resolved.
DCHECK(scope->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->already_resolved());
// Allocate the variables.
{
AstNodeFactory ast_node_factory(info->ast_value_factory());
top->AllocateVariables(info, &ast_node_factory);
scope->AllocateVariables(info, &ast_node_factory);
}
#ifdef DEBUG