| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 function_ = | 629 function_ = |
| 630 new (zone()) Variable(this, name, CONST, kind, kCreatedInitialized); | 630 new (zone()) Variable(this, name, CONST, kind, kCreatedInitialized); |
| 631 if (calls_sloppy_eval()) { | 631 if (calls_sloppy_eval()) { |
| 632 NonLocal(name, DYNAMIC); | 632 NonLocal(name, DYNAMIC); |
| 633 } else { | 633 } else { |
| 634 variables_.Add(zone(), function_); | 634 variables_.Add(zone(), function_); |
| 635 } | 635 } |
| 636 return function_; | 636 return function_; |
| 637 } | 637 } |
| 638 | 638 |
| 639 bool Scope::HasBeenRemoved() const { |
| 640 // TODO(neis): Store this information somewhere instead of calculating it. |
| 641 |
| 642 if (!is_block_scope() || is_declaration_scope()) return false; |
| 643 |
| 644 Scope* parent = outer_scope(); |
| 645 if (parent == nullptr) { |
| 646 DCHECK(is_script_scope()); |
| 647 return false; |
| 648 } |
| 649 |
| 650 Scope* sibling = parent->inner_scope(); |
| 651 for (; sibling != nullptr; sibling = sibling->sibling()) { |
| 652 if (sibling == this) return false; |
| 653 } |
| 654 |
| 655 DCHECK_NULL(inner_scope_); |
| 656 return true; |
| 657 } |
| 658 |
| 659 Scope* Scope::GetUnremovedScope() { |
| 660 Scope* scope = this; |
| 661 while (scope != nullptr && scope->HasBeenRemoved()) { |
| 662 scope = scope->outer_scope(); |
| 663 } |
| 664 DCHECK_NOT_NULL(scope); |
| 665 return scope; |
| 666 } |
| 667 |
| 639 Scope* Scope::FinalizeBlockScope() { | 668 Scope* Scope::FinalizeBlockScope() { |
| 640 DCHECK(is_block_scope()); | 669 DCHECK(is_block_scope()); |
| 641 | 670 |
| 642 if (variables_.occupancy() > 0 || | 671 if (variables_.occupancy() > 0 || |
| 643 (is_declaration_scope() && calls_sloppy_eval())) { | 672 (is_declaration_scope() && calls_sloppy_eval())) { |
| 644 return this; | 673 return this; |
| 645 } | 674 } |
| 646 | 675 |
| 647 // Remove this scope from outer scope. | 676 // Remove this scope from outer scope. |
| 648 outer_scope()->RemoveInnerScope(this); | 677 outer_scope()->RemoveInnerScope(this); |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 Variable* function = | 2056 Variable* function = |
| 2028 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2057 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
| 2029 bool is_function_var_in_context = | 2058 bool is_function_var_in_context = |
| 2030 function != nullptr && function->IsContextSlot(); | 2059 function != nullptr && function->IsContextSlot(); |
| 2031 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2060 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 2032 (is_function_var_in_context ? 1 : 0); | 2061 (is_function_var_in_context ? 1 : 0); |
| 2033 } | 2062 } |
| 2034 | 2063 |
| 2035 } // namespace internal | 2064 } // namespace internal |
| 2036 } // namespace v8 | 2065 } // namespace v8 |
| OLD | NEW |