From 2ed9e6e634dc46a08f1da2eebef82e3e563d6e72 Mon Sep 17 00:00:00 2001 From: verwaest Date: Mon, 8 Aug 2016 04:51:27 -0700 Subject: [PATCH] Only conditionally add inner scope when deserializing BUG=v8:5209 Review-Url: https://codereview.chromium.org/2224793003 Cr-Commit-Position: refs/heads/master@{#38436} --- src/ast/scopes.cc | 12 ++++++------ src/ast/scopes.h | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc index 0c19dd63a8..2acf68f5e3 100644 --- a/src/ast/scopes.cc +++ b/src/ast/scopes.cc @@ -140,7 +140,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. num_heap_slots_ = Max(num_heap_slots_, static_cast(Context::MIN_CONTEXT_SLOTS)); - AddInnerScope(inner_scope); + if (inner_scope != nullptr) AddInnerScope(inner_scope); } DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, @@ -165,7 +165,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope, scope_type_(CATCH_SCOPE), already_resolved_(true) { SetDefaults(); - AddInnerScope(inner_scope); + if (inner_scope != nullptr) AddInnerScope(inner_scope); num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; Variable* variable = variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, @@ -232,8 +232,8 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, AstValueFactory* ast_value_factory, DeserializationMode deserialization_mode) { // Reconstruct the outer scope chain from a closure's context chain. - Scope* current_scope = NULL; - Scope* innermost_scope = NULL; + Scope* current_scope = nullptr; + Scope* innermost_scope = nullptr; while (!context->IsNativeContext()) { if (context->IsWithContext() || context->IsDebugEvaluateContext()) { // For scope analysis, debug-evaluate is equivalent to a with scope. @@ -241,7 +241,7 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, Scope(zone, current_scope, WITH_SCOPE, Handle::null()); current_scope = with_scope; // All the inner scopes are inside a with. - for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) { + for (Scope* s = innermost_scope; s != nullptr; s = s->outer_scope()) { s->scope_inside_with_ = true; } } else if (context->IsScriptContext()) { @@ -273,7 +273,7 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) { current_scope->DeserializeScopeInfo(isolate, ast_value_factory); } - if (innermost_scope == NULL) innermost_scope = current_scope; + if (innermost_scope == nullptr) innermost_scope = current_scope; context = context->previous(); } diff --git a/src/ast/scopes.h b/src/ast/scopes.h index 68ceb191f8..5be698fc10 100644 --- a/src/ast/scopes.h +++ b/src/ast/scopes.h @@ -622,11 +622,9 @@ class Scope: public ZoneObject { const AstRawString* catch_variable_name); void AddInnerScope(Scope* inner_scope) { - if (inner_scope != nullptr) { - inner_scope->sibling_ = inner_scope_; - inner_scope_ = inner_scope; - inner_scope->outer_scope_ = this; - } + inner_scope->sibling_ = inner_scope_; + inner_scope_ = inner_scope; + inner_scope->outer_scope_ = this; } void RemoveInnerScope(Scope* inner_scope) {