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 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 | 1172 |
1173 bool Scope::AllowsLazyParsingWithoutUnresolvedVariables( | 1173 bool Scope::AllowsLazyParsingWithoutUnresolvedVariables( |
1174 const Scope* outer) const { | 1174 const Scope* outer) const { |
1175 // If none of the outer scopes need to decide whether to context allocate | 1175 // If none of the outer scopes need to decide whether to context allocate |
1176 // specific variables, we can preparse inner functions without unresolved | 1176 // specific variables, we can preparse inner functions without unresolved |
1177 // variables. Otherwise we need to find unresolved variables to force context | 1177 // variables. Otherwise we need to find unresolved variables to force context |
1178 // allocation of the matching declarations. We can stop at the outer scope for | 1178 // allocation of the matching declarations. We can stop at the outer scope for |
1179 // the parse, since context allocation of those variables is already | 1179 // the parse, since context allocation of those variables is already |
1180 // guaranteed to be correct. | 1180 // guaranteed to be correct. |
1181 for (const Scope* s = this; s != outer; s = s->outer_scope_) { | 1181 for (const Scope* s = this; s != outer; s = s->outer_scope_) { |
1182 // Eval forces context allocation on all outer scopes, so we don't need to | 1182 if (s->is_eval_scope()) return false; |
1183 // look at those scopes. Sloppy eval makes all top-level variables dynamic, | |
1184 // whereas strict-mode requires context allocation. | |
1185 if (s->is_eval_scope()) return !is_strict(s->language_mode()); | |
1186 // Catch scopes force context allocation of all variables. | 1183 // Catch scopes force context allocation of all variables. |
1187 if (s->is_catch_scope()) continue; | 1184 if (s->is_catch_scope()) continue; |
1188 // With scopes do not introduce variables that need allocation. | 1185 // With scopes do not introduce variables that need allocation. |
1189 if (s->is_with_scope()) continue; | 1186 if (s->is_with_scope()) continue; |
1190 // If everything is guaranteed to be context allocated we can ignore the | 1187 // If everything is guaranteed to be context allocated we can ignore the |
1191 // scope. | 1188 // scope. |
1192 if (s->has_forced_context_allocation()) continue; | 1189 if (s->has_forced_context_allocation()) continue; |
1193 // Only block scopes and function scopes should disallow preparsing. | 1190 // Only block scopes and function scopes should disallow preparsing. |
1194 DCHECK(s->is_block_scope() || s->is_function_scope()); | 1191 DCHECK(s->is_block_scope() || s->is_function_scope()); |
1195 return false; | 1192 return false; |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 Variable* function = | 2100 Variable* function = |
2104 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2101 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
2105 bool is_function_var_in_context = | 2102 bool is_function_var_in_context = |
2106 function != nullptr && function->IsContextSlot(); | 2103 function != nullptr && function->IsContextSlot(); |
2107 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2104 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
2108 (is_function_var_in_context ? 1 : 0); | 2105 (is_function_var_in_context ? 1 : 0); |
2109 } | 2106 } |
2110 | 2107 |
2111 } // namespace internal | 2108 } // namespace internal |
2112 } // namespace v8 | 2109 } // namespace v8 |
OLD | NEW |