OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 // 2) Resolve variables. | 630 // 2) Resolve variables. |
631 if (!ResolveVariablesRecursively(info, factory)) return false; | 631 if (!ResolveVariablesRecursively(info, factory)) return false; |
632 | 632 |
633 // 3) Allocate variables. | 633 // 3) Allocate variables. |
634 AllocateVariablesRecursively(); | 634 AllocateVariablesRecursively(); |
635 | 635 |
636 return true; | 636 return true; |
637 } | 637 } |
638 | 638 |
639 | 639 |
| 640 bool Scope::AllowsLazyCompilation() const { |
| 641 return !force_eager_compilation_ && HasTrivialOuterContext(); |
| 642 } |
| 643 |
| 644 |
640 bool Scope::HasTrivialContext() const { | 645 bool Scope::HasTrivialContext() const { |
641 // A function scope has a trivial context if it always is the global | 646 // A function scope has a trivial context if it always is the global |
642 // context. We iteratively scan out the context chain to see if | 647 // context. We iteratively scan out the context chain to see if |
643 // there is anything that makes this scope non-trivial; otherwise we | 648 // there is anything that makes this scope non-trivial; otherwise we |
644 // return true. | 649 // return true. |
645 for (const Scope* scope = this; scope != NULL; scope = scope->outer_scope_) { | 650 for (const Scope* scope = this; scope != NULL; scope = scope->outer_scope_) { |
646 if (scope->is_eval_scope()) return false; | 651 if (scope->is_eval_scope()) return false; |
647 if (scope->scope_inside_with_) return false; | 652 if (scope->scope_inside_with_) return false; |
648 if (scope->num_heap_slots_ > 0) return false; | 653 if (scope->num_heap_slots_ > 0) return false; |
649 } | 654 } |
650 return true; | 655 return true; |
651 } | 656 } |
652 | 657 |
653 | 658 |
654 bool Scope::HasTrivialOuterContext() const { | 659 bool Scope::HasTrivialOuterContext() const { |
655 Scope* outer = outer_scope_; | 660 Scope* outer = outer_scope_; |
656 if (outer == NULL) return true; | 661 if (outer == NULL) return true; |
657 // Note that the outer context may be trivial in general, but the current | 662 // Note that the outer context may be trivial in general, but the current |
658 // scope may be inside a 'with' statement in which case the outer context | 663 // scope may be inside a 'with' statement in which case the outer context |
659 // for this scope is not trivial. | 664 // for this scope is not trivial. |
660 return !scope_inside_with_ && outer->HasTrivialContext(); | 665 return !scope_inside_with_ && outer->HasTrivialContext(); |
661 } | 666 } |
662 | 667 |
663 | 668 |
664 bool Scope::AllowsLazyCompilation() const { | 669 bool Scope::AllowsLazyRecompilation() const { |
665 return !force_eager_compilation_ && | 670 return !force_eager_compilation_ && |
666 !TrivialDeclarationScopesBeforeWithScope(); | 671 !TrivialDeclarationScopesBeforeWithScope(); |
667 } | 672 } |
668 | 673 |
669 | 674 |
670 bool Scope::AllowsLazyCompilationWithoutContext() const { | |
671 return !force_eager_compilation_ && HasTrivialOuterContext(); | |
672 } | |
673 | |
674 | |
675 bool Scope::TrivialDeclarationScopesBeforeWithScope() const { | 675 bool Scope::TrivialDeclarationScopesBeforeWithScope() const { |
676 Scope* outer = outer_scope_; | 676 Scope* outer = outer_scope_; |
677 if (outer == NULL) return false; | 677 if (outer == NULL) return false; |
678 outer = outer->DeclarationScope(); | 678 outer = outer->DeclarationScope(); |
679 while (outer != NULL) { | 679 while (outer != NULL) { |
680 if (outer->is_with_scope()) return true; | 680 if (outer->is_with_scope()) return true; |
681 if (outer->is_declaration_scope() && outer->num_heap_slots() > 0) | 681 if (outer->is_declaration_scope() && outer->num_heap_slots() > 0) |
682 return false; | 682 return false; |
683 outer = outer->outer_scope_; | 683 outer = outer->outer_scope_; |
684 } | 684 } |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 } | 1292 } |
1293 | 1293 |
1294 | 1294 |
1295 int Scope::ContextLocalCount() const { | 1295 int Scope::ContextLocalCount() const { |
1296 if (num_heap_slots() == 0) return 0; | 1296 if (num_heap_slots() == 0) return 0; |
1297 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1297 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1298 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1298 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1299 } | 1299 } |
1300 | 1300 |
1301 } } // namespace v8::internal | 1301 } } // namespace v8::internal |
OLD | NEW |