| 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_declaration_scope()) return false; | |
| 643 DCHECK(is_block_scope()); | |
| 644 | |
| 645 Scope* parent = outer_scope(); | |
| 646 if (parent == nullptr) { | |
| 647 DCHECK(is_script_scope()); | |
| 648 return false; | |
| 649 } | |
| 650 | |
| 651 Scope* sibling = parent->inner_scope(); | |
| 652 for (; sibling != nullptr; sibling = sibling->sibling()) { | |
| 653 if (sibling == this) return false; | |
| 654 } | |
| 655 | |
| 656 DCHECK_NULL(inner_scope_); | |
| 657 return true; | |
| 658 } | |
| 659 | |
| 660 Scope* Scope::GetUnremovedScope() { | |
| 661 Scope* scope = this; | |
| 662 while (scope != nullptr && scope->HasBeenRemoved()) { | |
| 663 scope = scope->outer_scope(); | |
| 664 } | |
| 665 DCHECK_NOT_NULL(scope); | |
| 666 return scope; | |
| 667 } | |
| 668 | |
| 669 Scope* Scope::FinalizeBlockScope() { | 639 Scope* Scope::FinalizeBlockScope() { |
| 670 DCHECK(is_block_scope()); | 640 DCHECK(is_block_scope()); |
| 671 | 641 |
| 672 if (variables_.occupancy() > 0 || | 642 if (variables_.occupancy() > 0 || |
| 673 (is_declaration_scope() && calls_sloppy_eval())) { | 643 (is_declaration_scope() && calls_sloppy_eval())) { |
| 674 return this; | 644 return this; |
| 675 } | 645 } |
| 676 | 646 |
| 677 // Remove this scope from outer scope. | 647 // Remove this scope from outer scope. |
| 678 outer_scope()->RemoveInnerScope(this); | 648 outer_scope()->RemoveInnerScope(this); |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2057 Variable* function = | 2027 Variable* function = |
| 2058 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2028 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
| 2059 bool is_function_var_in_context = | 2029 bool is_function_var_in_context = |
| 2060 function != nullptr && function->IsContextSlot(); | 2030 function != nullptr && function->IsContextSlot(); |
| 2061 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2031 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 2062 (is_function_var_in_context ? 1 : 0); | 2032 (is_function_var_in_context ? 1 : 0); |
| 2063 } | 2033 } |
| 2064 | 2034 |
| 2065 } // namespace internal | 2035 } // namespace internal |
| 2066 } // namespace v8 | 2036 } // namespace v8 |
| OLD | NEW |