| 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 | |
| 645 bool Scope::HasTrivialContext() const { | 640 bool Scope::HasTrivialContext() const { |
| 646 // A function scope has a trivial context if it always is the global | 641 // A function scope has a trivial context if it always is the global |
| 647 // context. We iteratively scan out the context chain to see if | 642 // context. We iteratively scan out the context chain to see if |
| 648 // there is anything that makes this scope non-trivial; otherwise we | 643 // there is anything that makes this scope non-trivial; otherwise we |
| 649 // return true. | 644 // return true. |
| 650 for (const Scope* scope = this; scope != NULL; scope = scope->outer_scope_) { | 645 for (const Scope* scope = this; scope != NULL; scope = scope->outer_scope_) { |
| 651 if (scope->is_eval_scope()) return false; | 646 if (scope->is_eval_scope()) return false; |
| 652 if (scope->scope_inside_with_) return false; | 647 if (scope->scope_inside_with_) return false; |
| 653 if (scope->num_heap_slots_ > 0) return false; | 648 if (scope->num_heap_slots_ > 0) return false; |
| 654 } | 649 } |
| 655 return true; | 650 return true; |
| 656 } | 651 } |
| 657 | 652 |
| 658 | 653 |
| 659 bool Scope::HasTrivialOuterContext() const { | 654 bool Scope::HasTrivialOuterContext() const { |
| 660 Scope* outer = outer_scope_; | 655 Scope* outer = outer_scope_; |
| 661 if (outer == NULL) return true; | 656 if (outer == NULL) return true; |
| 662 // Note that the outer context may be trivial in general, but the current | 657 // Note that the outer context may be trivial in general, but the current |
| 663 // scope may be inside a 'with' statement in which case the outer context | 658 // scope may be inside a 'with' statement in which case the outer context |
| 664 // for this scope is not trivial. | 659 // for this scope is not trivial. |
| 665 return !scope_inside_with_ && outer->HasTrivialContext(); | 660 return !scope_inside_with_ && outer->HasTrivialContext(); |
| 666 } | 661 } |
| 667 | 662 |
| 668 | 663 |
| 669 bool Scope::AllowsLazyRecompilation() const { | 664 bool Scope::AllowsLazyCompilation() const { |
| 670 return !force_eager_compilation_ && | 665 return !force_eager_compilation_ && |
| 671 !TrivialDeclarationScopesBeforeWithScope(); | 666 !TrivialDeclarationScopesBeforeWithScope(); |
| 672 } | 667 } |
| 673 | 668 |
| 674 | 669 |
| 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 |