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/scopes.h" | 5 #include "src/scopes.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/messages.h" | 9 #include "src/messages.h" |
10 #include "src/parser.h" | 10 #include "src/parser.h" |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 | 758 |
759 bool Scope::AllowsLazyCompilationWithoutContext() const { | 759 bool Scope::AllowsLazyCompilationWithoutContext() const { |
760 return !force_eager_compilation_ && HasTrivialOuterContext(); | 760 return !force_eager_compilation_ && HasTrivialOuterContext(); |
761 } | 761 } |
762 | 762 |
763 | 763 |
764 int Scope::ContextChainLength(Scope* scope) { | 764 int Scope::ContextChainLength(Scope* scope) { |
765 int n = 0; | 765 int n = 0; |
766 for (Scope* s = this; s != scope; s = s->outer_scope_) { | 766 for (Scope* s = this; s != scope; s = s->outer_scope_) { |
767 DCHECK(s != NULL); // scope must be in the scope chain | 767 DCHECK(s != NULL); // scope must be in the scope chain |
768 if (s->is_with_scope() || s->num_heap_slots() > 0) n++; | 768 if (s->NeedsContext()) n++; |
769 // Catch and module scopes always have heap slots. | |
770 DCHECK(!s->is_catch_scope() || s->num_heap_slots() > 0); | |
771 DCHECK(!s->is_module_scope() || s->num_heap_slots() > 0); | |
772 } | 769 } |
773 return n; | 770 return n; |
774 } | 771 } |
775 | 772 |
776 | 773 |
| 774 int Scope::MaxNestedContextChainLength() { |
| 775 int max_context_chain_length = 0; |
| 776 for (int i = 0; i < inner_scopes_.length(); i++) { |
| 777 Scope* scope = inner_scopes_[i]; |
| 778 max_context_chain_length = std::max(scope->MaxNestedContextChainLength(), |
| 779 max_context_chain_length); |
| 780 } |
| 781 if (NeedsContext()) { |
| 782 max_context_chain_length += 1; |
| 783 } |
| 784 return max_context_chain_length; |
| 785 } |
| 786 |
| 787 |
777 Scope* Scope::DeclarationScope() { | 788 Scope* Scope::DeclarationScope() { |
778 Scope* scope = this; | 789 Scope* scope = this; |
779 while (!scope->is_declaration_scope()) { | 790 while (!scope->is_declaration_scope()) { |
780 scope = scope->outer_scope(); | 791 scope = scope->outer_scope(); |
781 } | 792 } |
782 return scope; | 793 return scope; |
783 } | 794 } |
784 | 795 |
785 | 796 |
786 Scope* Scope::ClosureScope() { | 797 Scope* Scope::ClosureScope() { |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1658 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1648 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1659 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1649 (is_function_var_in_context ? 1 : 0); | 1660 (is_function_var_in_context ? 1 : 0); |
1650 } | 1661 } |
1651 | 1662 |
1652 | 1663 |
1653 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1664 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1654 | 1665 |
1655 } // namespace internal | 1666 } // namespace internal |
1656 } // namespace v8 | 1667 } // namespace v8 |
OLD | NEW |