Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: src/scopes.cc

Issue 10704058: Fix lazy compilation for strict eval scopes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scopes.h ('k') | test/mjsunit/regress/regress-crbug-135066.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 bool Scope::HasTrivialOuterContext() const { 655 bool Scope::HasTrivialOuterContext() const {
656 Scope* outer = outer_scope_; 656 Scope* outer = outer_scope_;
657 if (outer == NULL) return true; 657 if (outer == NULL) return true;
658 // Note that the outer context may be trivial in general, but the current 658 // Note that the outer context may be trivial in general, but the current
659 // scope may be inside a 'with' statement in which case the outer context 659 // scope may be inside a 'with' statement in which case the outer context
660 // for this scope is not trivial. 660 // for this scope is not trivial.
661 return !scope_inside_with_ && outer->HasTrivialContext(); 661 return !scope_inside_with_ && outer->HasTrivialContext();
662 } 662 }
663 663
664 664
665 bool Scope::HasLazyCompilableOuterContext() const {
666 Scope* outer = outer_scope_;
667 if (outer == NULL) return true;
668 // There are several reasons that prevent lazy compilation:
669 // - This scope is inside a with scope and all declaration scopes between
670 // them have empty contexts. Such declaration scopes become invisible
671 // during scope info deserialization.
672 // - This scope is inside a strict eval scope with variables that are
673 // potentially context allocated in an artificial function scope that
674 // is not deserialized correctly.
675 outer = outer->DeclarationScope();
676 bool found_non_trivial_declarations = false;
677 for (const Scope* scope = outer; scope != NULL; scope = scope->outer_scope_) {
678 if (scope->is_eval_scope()) return false;
679 if (scope->is_with_scope() && !found_non_trivial_declarations) return false;
680 if (scope->is_declaration_scope() && scope->num_heap_slots() > 0) {
681 found_non_trivial_declarations = true;
682 }
683 }
684 return true;
685 }
686
687
665 bool Scope::AllowsLazyCompilation() const { 688 bool Scope::AllowsLazyCompilation() const {
666 return !force_eager_compilation_ && 689 return !force_eager_compilation_ && HasLazyCompilableOuterContext();
667 !TrivialDeclarationScopesBeforeWithScope();
668 } 690 }
669 691
670 692
671 bool Scope::AllowsLazyCompilationWithoutContext() const { 693 bool Scope::AllowsLazyCompilationWithoutContext() const {
672 return !force_eager_compilation_ && HasTrivialOuterContext(); 694 return !force_eager_compilation_ && HasTrivialOuterContext();
673 } 695 }
674 696
675 697
676 bool Scope::TrivialDeclarationScopesBeforeWithScope() const {
677 Scope* outer = outer_scope_;
678 if (outer == NULL) return false;
679 outer = outer->DeclarationScope();
680 while (outer != NULL) {
681 if (outer->is_with_scope()) return true;
682 if (outer->is_declaration_scope() && outer->num_heap_slots() > 0)
683 return false;
684 outer = outer->outer_scope_;
685 }
686 return false;
687 }
688
689
690 int Scope::ContextChainLength(Scope* scope) { 698 int Scope::ContextChainLength(Scope* scope) {
691 int n = 0; 699 int n = 0;
692 for (Scope* s = this; s != scope; s = s->outer_scope_) { 700 for (Scope* s = this; s != scope; s = s->outer_scope_) {
693 ASSERT(s != NULL); // scope must be in the scope chain 701 ASSERT(s != NULL); // scope must be in the scope chain
694 if (s->num_heap_slots() > 0) n++; 702 if (s->num_heap_slots() > 0) n++;
695 } 703 }
696 return n; 704 return n;
697 } 705 }
698 706
699 707
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 } 1301 }
1294 1302
1295 1303
1296 int Scope::ContextLocalCount() const { 1304 int Scope::ContextLocalCount() const {
1297 if (num_heap_slots() == 0) return 0; 1305 if (num_heap_slots() == 0) return 0;
1298 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1306 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1299 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1307 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1300 } 1308 }
1301 1309
1302 } } // namespace v8::internal 1310 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | test/mjsunit/regress/regress-crbug-135066.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698