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 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 AllocateScopeInfosRecursively(info->isolate(), mode, outer_scope); | 1107 AllocateScopeInfosRecursively(info->isolate(), mode, outer_scope); |
1108 // The debugger expects all shared function infos to contain a scope info. | 1108 // The debugger expects all shared function infos to contain a scope info. |
1109 // Since the top-most scope will end up in a shared function info, make sure | 1109 // Since the top-most scope will end up in a shared function info, make sure |
1110 // it has one, even if it doesn't need a scope info. | 1110 // it has one, even if it doesn't need a scope info. |
1111 // TODO(jochen|yangguo): Remove this requirement. | 1111 // TODO(jochen|yangguo): Remove this requirement. |
1112 if (scope_info_.is_null()) { | 1112 if (scope_info_.is_null()) { |
1113 scope_info_ = ScopeInfo::Create(info->isolate(), zone(), this, outer_scope); | 1113 scope_info_ = ScopeInfo::Create(info->isolate(), zone(), this, outer_scope); |
1114 } | 1114 } |
1115 } | 1115 } |
1116 | 1116 |
1117 bool Scope::AllowsLazyParsingWithoutUnresolvedVariables() const { | 1117 bool Scope::AllowsLazyParsingWithoutUnresolvedVariables( |
1118 // If we are inside a block scope, we must find unresolved variables in the | 1118 const Scope* outer) const { |
1119 // inner scopes to find out how to allocate variables on the block scope. At | 1119 // If none of the outer scopes need to decide whether to context allocate |
1120 // this point, declarations may not have yet been parsed. | 1120 // specific variables, we can preparse inner functions without unresolved |
1121 for (const Scope* s = this; s != nullptr; s = s->outer_scope_) { | 1121 // variables. Otherwise we need to find unresolved variables to force context |
1122 if (s->is_block_scope()) return false; | 1122 // allocation of the matching declarations. We can stop at the outer scope for |
1123 if (s->is_function_scope()) return false; | 1123 // the parse, since context allocation of those variables is already |
1124 if (s->is_eval_scope() && is_strict(s->language_mode())) return false; | 1124 // guaranteed to be correct. |
| 1125 for (const Scope* s = this; s != outer; s = s->outer_scope_) { |
| 1126 // Eval forces context allocation on all outer scopes, so we don't need to |
| 1127 // look at those scopes. Sloppy eval makes all top-level variables dynamic, |
| 1128 // whereas strict-mode requires context allocation. |
| 1129 if (s->is_eval_scope()) return !is_strict(s->language_mode()); |
| 1130 // Catch scopes force context allocation of all variables. |
| 1131 if (s->is_catch_scope()) continue; |
| 1132 // With scopes do not introduce variables that need allocation. |
| 1133 if (s->is_with_scope()) continue; |
| 1134 // If everything is guaranteed to be context allocated we can ignore the |
| 1135 // scope. |
| 1136 if (s->has_forced_context_allocation()) continue; |
| 1137 // Only block scopes and function scopes should disallow preparsing. |
| 1138 DCHECK(s->is_block_scope() || s->is_function_scope()); |
| 1139 return false; |
1125 } | 1140 } |
1126 return true; | 1141 return true; |
1127 } | 1142 } |
1128 | 1143 |
1129 bool DeclarationScope::AllowsLazyCompilation() const { | 1144 bool DeclarationScope::AllowsLazyCompilation() const { |
1130 return !force_eager_compilation_; | 1145 return !force_eager_compilation_; |
1131 } | 1146 } |
1132 | 1147 |
1133 int Scope::ContextChainLength(Scope* scope) const { | 1148 int Scope::ContextChainLength(Scope* scope) const { |
1134 int n = 0; | 1149 int n = 0; |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 Variable* function = | 1962 Variable* function = |
1948 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1963 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
1949 bool is_function_var_in_context = | 1964 bool is_function_var_in_context = |
1950 function != nullptr && function->IsContextSlot(); | 1965 function != nullptr && function->IsContextSlot(); |
1951 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1966 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1952 (is_function_var_in_context ? 1 : 0); | 1967 (is_function_var_in_context ? 1 : 0); |
1953 } | 1968 } |
1954 | 1969 |
1955 } // namespace internal | 1970 } // namespace internal |
1956 } // namespace v8 | 1971 } // namespace v8 |
OLD | NEW |