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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 117 |
118 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) | 118 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) |
119 : zone_(zone), | 119 : zone_(zone), |
120 outer_scope_(outer_scope), | 120 outer_scope_(outer_scope), |
121 variables_(zone), | 121 variables_(zone), |
122 scope_type_(scope_type) { | 122 scope_type_(scope_type) { |
123 DCHECK_NE(SCRIPT_SCOPE, scope_type); | 123 DCHECK_NE(SCRIPT_SCOPE, scope_type); |
124 SetDefaults(); | 124 SetDefaults(); |
125 set_language_mode(outer_scope->language_mode()); | 125 set_language_mode(outer_scope->language_mode()); |
126 force_context_allocation_ = | 126 force_context_allocation_ = |
127 !is_function_scope() && outer_scope->has_forced_context_allocation(); | 127 (!is_function_scope() && outer_scope->has_forced_context_allocation()) || |
128 is_eval_scope(); | |
adamk
2017/01/03 18:33:43
I don't think you want to do this here; "forced co
marja
2017/01/03 19:55:50
Done.
| |
128 outer_scope_->AddInnerScope(this); | 129 outer_scope_->AddInnerScope(this); |
129 } | 130 } |
130 | 131 |
131 Scope::Snapshot::Snapshot(Scope* scope) | 132 Scope::Snapshot::Snapshot(Scope* scope) |
132 : outer_scope_(scope), | 133 : outer_scope_(scope), |
133 top_inner_scope_(scope->inner_scope_), | 134 top_inner_scope_(scope->inner_scope_), |
134 top_unresolved_(scope->unresolved_), | 135 top_unresolved_(scope->unresolved_), |
135 top_local_(scope->GetClosureScope()->locals_.end()), | 136 top_local_(scope->GetClosureScope()->locals_.end()), |
136 top_decl_(scope->GetClosureScope()->decls_.end()) {} | 137 top_decl_(scope->GetClosureScope()->decls_.end()) {} |
137 | 138 |
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1172 | 1173 |
1173 bool Scope::AllowsLazyParsingWithoutUnresolvedVariables( | 1174 bool Scope::AllowsLazyParsingWithoutUnresolvedVariables( |
1174 const Scope* outer) const { | 1175 const Scope* outer) const { |
1175 // If none of the outer scopes need to decide whether to context allocate | 1176 // If none of the outer scopes need to decide whether to context allocate |
1176 // specific variables, we can preparse inner functions without unresolved | 1177 // specific variables, we can preparse inner functions without unresolved |
1177 // variables. Otherwise we need to find unresolved variables to force context | 1178 // 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 | 1179 // allocation of the matching declarations. We can stop at the outer scope for |
1179 // the parse, since context allocation of those variables is already | 1180 // the parse, since context allocation of those variables is already |
1180 // guaranteed to be correct. | 1181 // guaranteed to be correct. |
1181 for (const Scope* s = this; s != outer; s = s->outer_scope_) { | 1182 for (const Scope* s = this; s != outer; s = s->outer_scope_) { |
1182 if (s->is_eval_scope()) return false; | |
1183 // Catch scopes force context allocation of all variables. | 1183 // Catch scopes force context allocation of all variables. |
1184 if (s->is_catch_scope()) continue; | 1184 if (s->is_catch_scope()) continue; |
1185 // With scopes do not introduce variables that need allocation. | 1185 // With scopes do not introduce variables that need allocation. |
1186 if (s->is_with_scope()) continue; | 1186 if (s->is_with_scope()) continue; |
1187 // 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 |
1188 // scope. | 1188 // scope. |
1189 if (s->has_forced_context_allocation()) continue; | 1189 if (s->has_forced_context_allocation()) continue; |
1190 // Only block scopes and function scopes should disallow preparsing. | 1190 // Only block scopes and function scopes should disallow preparsing. |
1191 DCHECK(s->is_block_scope() || s->is_function_scope()); | 1191 DCHECK(s->is_block_scope() || s->is_function_scope()); |
1192 return false; | 1192 return false; |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2123 Variable* function = | 2123 Variable* function = |
2124 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2124 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
2125 bool is_function_var_in_context = | 2125 bool is_function_var_in_context = |
2126 function != nullptr && function->IsContextSlot(); | 2126 function != nullptr && function->IsContextSlot(); |
2127 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2127 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
2128 (is_function_var_in_context ? 1 : 0); | 2128 (is_function_var_in_context ? 1 : 0); |
2129 } | 2129 } |
2130 | 2130 |
2131 } // namespace internal | 2131 } // namespace internal |
2132 } // namespace v8 | 2132 } // namespace v8 |
OLD | NEW |