Commit 2ed9e6e6 authored by verwaest's avatar verwaest Committed by Commit bot

Only conditionally add inner scope when deserializing

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2224793003
Cr-Commit-Position: refs/heads/master@{#38436}
parent caf5c5a1
...@@ -140,7 +140,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, ...@@ -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. // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
num_heap_slots_ = Max(num_heap_slots_, num_heap_slots_ = Max(num_heap_slots_,
static_cast<int>(Context::MIN_CONTEXT_SLOTS)); static_cast<int>(Context::MIN_CONTEXT_SLOTS));
AddInnerScope(inner_scope); if (inner_scope != nullptr) AddInnerScope(inner_scope);
} }
DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope,
...@@ -165,7 +165,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope, ...@@ -165,7 +165,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope,
scope_type_(CATCH_SCOPE), scope_type_(CATCH_SCOPE),
already_resolved_(true) { already_resolved_(true) {
SetDefaults(); SetDefaults();
AddInnerScope(inner_scope); if (inner_scope != nullptr) AddInnerScope(inner_scope);
num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
Variable* variable = Variable* variable =
variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL,
...@@ -232,8 +232,8 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, ...@@ -232,8 +232,8 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
AstValueFactory* ast_value_factory, AstValueFactory* ast_value_factory,
DeserializationMode deserialization_mode) { DeserializationMode deserialization_mode) {
// Reconstruct the outer scope chain from a closure's context chain. // Reconstruct the outer scope chain from a closure's context chain.
Scope* current_scope = NULL; Scope* current_scope = nullptr;
Scope* innermost_scope = NULL; Scope* innermost_scope = nullptr;
while (!context->IsNativeContext()) { while (!context->IsNativeContext()) {
if (context->IsWithContext() || context->IsDebugEvaluateContext()) { if (context->IsWithContext() || context->IsDebugEvaluateContext()) {
// For scope analysis, debug-evaluate is equivalent to a with scope. // For scope analysis, debug-evaluate is equivalent to a with scope.
...@@ -241,7 +241,7 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, ...@@ -241,7 +241,7 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
Scope(zone, current_scope, WITH_SCOPE, Handle<ScopeInfo>::null()); Scope(zone, current_scope, WITH_SCOPE, Handle<ScopeInfo>::null());
current_scope = with_scope; current_scope = with_scope;
// All the inner scopes are inside a with. // 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; s->scope_inside_with_ = true;
} }
} else if (context->IsScriptContext()) { } else if (context->IsScriptContext()) {
...@@ -273,7 +273,7 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, ...@@ -273,7 +273,7 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) { if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) {
current_scope->DeserializeScopeInfo(isolate, ast_value_factory); 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(); context = context->previous();
} }
......
...@@ -622,11 +622,9 @@ class Scope: public ZoneObject { ...@@ -622,11 +622,9 @@ class Scope: public ZoneObject {
const AstRawString* catch_variable_name); const AstRawString* catch_variable_name);
void AddInnerScope(Scope* inner_scope) { void AddInnerScope(Scope* inner_scope) {
if (inner_scope != nullptr) { inner_scope->sibling_ = inner_scope_;
inner_scope->sibling_ = inner_scope_; inner_scope_ = inner_scope;
inner_scope_ = inner_scope; inner_scope->outer_scope_ = this;
inner_scope->outer_scope_ = this;
}
} }
void RemoveInnerScope(Scope* inner_scope) { void RemoveInnerScope(Scope* inner_scope) {
......
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