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/v8.h" | 5 #include "src/v8.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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 bool Scope::HasTrivialOuterContext() const { | 704 bool Scope::HasTrivialOuterContext() const { |
705 Scope* outer = outer_scope_; | 705 Scope* outer = outer_scope_; |
706 if (outer == NULL) return true; | 706 if (outer == NULL) return true; |
707 // Note that the outer context may be trivial in general, but the current | 707 // Note that the outer context may be trivial in general, but the current |
708 // scope may be inside a 'with' statement in which case the outer context | 708 // scope may be inside a 'with' statement in which case the outer context |
709 // for this scope is not trivial. | 709 // for this scope is not trivial. |
710 return !scope_inside_with_ && outer->HasTrivialContext(); | 710 return !scope_inside_with_ && outer->HasTrivialContext(); |
711 } | 711 } |
712 | 712 |
713 | 713 |
714 bool Scope::HasLazyCompilableOuterContext() const { | |
715 Scope* outer = outer_scope_; | |
716 if (outer == NULL) return true; | |
717 // We have to prevent lazy compilation if this scope is inside a with scope | |
718 // and all declaration scopes between them have empty contexts. Such | |
719 // declaration scopes may become invisible during scope info deserialization. | |
720 outer = outer->DeclarationScope(); | |
721 bool found_non_trivial_declarations = false; | |
722 for (const Scope* scope = outer; scope != NULL; scope = scope->outer_scope_) { | |
723 if (scope->is_with_scope() && !found_non_trivial_declarations) return false; | |
724 if (scope->is_block_scope() && !scope->decls_.is_empty()) return false; | |
725 if (scope->is_declaration_scope() && scope->num_heap_slots() > 0) { | |
726 found_non_trivial_declarations = true; | |
727 } | |
728 } | |
729 return true; | |
730 } | |
731 | |
732 | |
733 bool Scope::AllowsLazyParsing() const { | 714 bool Scope::AllowsLazyParsing() const { |
734 // If we are inside a block scope, we must parse eagerly to find out how | 715 // If we are inside a block scope, we must parse eagerly to find out how |
735 // to allocate variables on the block scope. At this point, declarations may | 716 // to allocate variables on the block scope. At this point, declarations may |
736 // not have yet been parsed. | 717 // not have yet been parsed. |
737 for (const Scope* scope = this; scope != NULL; scope = scope->outer_scope_) { | 718 for (const Scope* scope = this; scope != NULL; scope = scope->outer_scope_) { |
738 if (scope->is_block_scope()) return false; | 719 if (scope->is_block_scope()) return false; |
739 } | 720 } |
740 return AllowsLazyCompilation(); | 721 return AllowsLazyCompilation(); |
741 } | 722 } |
742 | 723 |
743 | 724 |
744 bool Scope::AllowsLazyCompilation() const { | 725 bool Scope::AllowsLazyCompilation() const { return !force_eager_compilation_; } |
745 return !force_eager_compilation_ && HasLazyCompilableOuterContext(); | |
746 } | |
747 | 726 |
748 | 727 |
749 bool Scope::AllowsLazyCompilationWithoutContext() const { | 728 bool Scope::AllowsLazyCompilationWithoutContext() const { |
750 return !force_eager_compilation_ && HasTrivialOuterContext(); | 729 return !force_eager_compilation_ && HasTrivialOuterContext(); |
751 } | 730 } |
752 | 731 |
753 | 732 |
754 int Scope::ContextChainLength(Scope* scope) { | 733 int Scope::ContextChainLength(Scope* scope) { |
755 int n = 0; | 734 int n = 0; |
756 for (Scope* s = this; s != scope; s = s->outer_scope_) { | 735 for (Scope* s = this; s != scope; s = s->outer_scope_) { |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 } | 1560 } |
1582 | 1561 |
1583 | 1562 |
1584 int Scope::ContextLocalCount() const { | 1563 int Scope::ContextLocalCount() const { |
1585 if (num_heap_slots() == 0) return 0; | 1564 if (num_heap_slots() == 0) return 0; |
1586 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1565 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1587 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1566 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1588 } | 1567 } |
1589 } // namespace internal | 1568 } // namespace internal |
1590 } // namespace v8 | 1569 } // namespace v8 |
OLD | NEW |