| 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/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 // TODO(marja): Refactor parsing modes: also add s->is_function_scope() | 1103 // TODO(marja): Refactor parsing modes: also add s->is_function_scope() |
| 1104 // here. | 1104 // here. |
| 1105 } | 1105 } |
| 1106 return true; | 1106 return true; |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 bool DeclarationScope::AllowsLazyCompilation() const { | 1109 bool DeclarationScope::AllowsLazyCompilation() const { |
| 1110 return !force_eager_compilation_; | 1110 return !force_eager_compilation_; |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 bool DeclarationScope::AllowsLazyCompilationWithoutContext() const { | |
| 1114 if (force_eager_compilation_) return false; | |
| 1115 // Disallow lazy compilation without context if any outer scope needs a | |
| 1116 // context. | |
| 1117 for (const Scope* scope = outer_scope_; scope != nullptr; | |
| 1118 scope = scope->outer_scope_) { | |
| 1119 if (scope->NeedsContext()) return false; | |
| 1120 } | |
| 1121 return true; | |
| 1122 } | |
| 1123 | |
| 1124 int Scope::ContextChainLength(Scope* scope) const { | 1113 int Scope::ContextChainLength(Scope* scope) const { |
| 1125 int n = 0; | 1114 int n = 0; |
| 1126 for (const Scope* s = this; s != scope; s = s->outer_scope_) { | 1115 for (const Scope* s = this; s != scope; s = s->outer_scope_) { |
| 1127 DCHECK(s != NULL); // scope must be in the scope chain | 1116 DCHECK(s != NULL); // scope must be in the scope chain |
| 1128 if (s->NeedsContext()) n++; | 1117 if (s->NeedsContext()) n++; |
| 1129 } | 1118 } |
| 1130 return n; | 1119 return n; |
| 1131 } | 1120 } |
| 1132 | 1121 |
| 1133 int Scope::ContextChainLengthUntilOutermostSloppyEval() const { | 1122 int Scope::ContextChainLengthUntilOutermostSloppyEval() const { |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 Variable* function = | 1912 Variable* function = |
| 1924 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1913 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
| 1925 bool is_function_var_in_context = | 1914 bool is_function_var_in_context = |
| 1926 function != nullptr && function->IsContextSlot(); | 1915 function != nullptr && function->IsContextSlot(); |
| 1927 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1916 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1928 (is_function_var_in_context ? 1 : 0); | 1917 (is_function_var_in_context ? 1 : 0); |
| 1929 } | 1918 } |
| 1930 | 1919 |
| 1931 } // namespace internal | 1920 } // namespace internal |
| 1932 } // namespace v8 | 1921 } // namespace v8 |
| OLD | NEW |