Index: src/ast/scopes.cc |
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc |
index 4ce1c0d85f7970f0b1cd5807d0519aac825d88c3..91bc1ab709596658935b09fac02a418cd210d027 100644 |
--- a/src/ast/scopes.cc |
+++ b/src/ast/scopes.cc |
@@ -636,23 +636,12 @@ Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name) { |
} |
bool Scope::HasBeenRemoved() const { |
- // TODO(neis): Store this information somewhere instead of calculating it. |
- |
- if (!is_block_scope()) return false; // Shortcut. |
- |
- Scope* parent = outer_scope(); |
- if (parent == nullptr) { |
- DCHECK(is_script_scope()); |
- return false; |
- } |
- |
- Scope* sibling = parent->inner_scope(); |
- for (; sibling != nullptr; sibling = sibling->sibling()) { |
- if (sibling == this) return false; |
+ if (sibling() == this) { |
+ DCHECK_NULL(inner_scope_); |
+ DCHECK(is_block_scope()); |
+ return true; |
} |
- |
- DCHECK_NULL(inner_scope_); |
- return true; |
+ return false; |
} |
Scope* Scope::GetUnremovedScope() { |
@@ -666,6 +655,7 @@ Scope* Scope::GetUnremovedScope() { |
Scope* Scope::FinalizeBlockScope() { |
DCHECK(is_block_scope()); |
+ DCHECK(!HasBeenRemoved()); |
if (variables_.occupancy() > 0 || |
(is_declaration_scope() && calls_sloppy_eval())) { |
@@ -704,7 +694,12 @@ Scope* Scope::FinalizeBlockScope() { |
PropagateUsageFlagsToScope(outer_scope_); |
// This block does not need a context. |
num_heap_slots_ = 0; |
- return NULL; |
+ |
+ // Mark scope as removed by making it its own sibling. |
+ sibling_ = this; |
+ DCHECK(HasBeenRemoved()); |
+ |
+ return nullptr; |
} |
void DeclarationScope::AddLocal(Variable* var) { |