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/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 outer_scope_->AddInnerScope(this); | 122 outer_scope_->AddInnerScope(this); |
123 } | 123 } |
124 | 124 |
125 Scope::Snapshot::Snapshot(Scope* scope) | 125 Scope::Snapshot::Snapshot(Scope* scope) |
126 : outer_scope_(scope), | 126 : outer_scope_(scope), |
127 top_inner_scope_(scope->inner_scope_), | 127 top_inner_scope_(scope->inner_scope_), |
128 top_unresolved_(scope->unresolved_), | 128 top_unresolved_(scope->unresolved_), |
129 top_local_(scope->GetClosureScope()->locals_.length()), | 129 top_local_(scope->GetClosureScope()->locals_.length()), |
130 top_decl_(scope->GetClosureScope()->decls_.length()) {} | 130 top_decl_(scope->GetClosureScope()->decls_.length()) {} |
131 | 131 |
132 DeclarationScope::DeclarationScope(Zone* zone) | 132 DeclarationScope::DeclarationScope(Zone* zone, |
133 AstValueFactory* ast_value_factory) | |
133 : Scope(zone), | 134 : Scope(zone), |
134 function_kind_(kNormalFunction), | 135 function_kind_(kNormalFunction), |
135 params_(4, zone), | 136 params_(4, zone), |
136 sloppy_block_function_map_(zone) { | 137 sloppy_block_function_map_(zone) { |
137 SetDefaults(); | 138 SetDefaults(); |
139 | |
marja
2016/08/31 12:27:48
Nit: how about DCHECK_EQ(scope_type, SCRIPT_SCOPE)
| |
140 // Make sure that if we don't find the global 'this', it won't be declared as | |
141 // a regular dynamic global by predeclaring it with the right variable kind. | |
142 DeclareDynamicGlobal(ast_value_factory->this_string(), Variable::THIS); | |
138 } | 143 } |
139 | 144 |
140 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, | 145 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, |
141 ScopeType scope_type, | 146 ScopeType scope_type, |
142 FunctionKind function_kind) | 147 FunctionKind function_kind) |
143 : Scope(zone, outer_scope, scope_type), | 148 : Scope(zone, outer_scope, scope_type), |
144 function_kind_(function_kind), | 149 function_kind_(function_kind), |
145 params_(4, zone), | 150 params_(4, zone), |
146 sloppy_block_function_map_(zone) { | 151 sloppy_block_function_map_(zone) { |
152 DCHECK_NE(scope_type, SCRIPT_SCOPE); | |
147 SetDefaults(); | 153 SetDefaults(); |
148 asm_function_ = outer_scope_->IsAsmModule(); | 154 asm_function_ = outer_scope_->IsAsmModule(); |
149 } | 155 } |
150 | 156 |
151 ModuleScope::ModuleScope(DeclarationScope* script_scope, | 157 ModuleScope::ModuleScope(DeclarationScope* script_scope, |
152 AstValueFactory* ast_value_factory) | 158 AstValueFactory* ast_value_factory) |
153 : DeclarationScope(ast_value_factory->zone(), script_scope, MODULE_SCOPE) { | 159 : DeclarationScope(ast_value_factory->zone(), script_scope, MODULE_SCOPE) { |
154 Zone* zone = ast_value_factory->zone(); | 160 Zone* zone = ast_value_factory->zone(); |
155 module_descriptor_ = new (zone) ModuleDescriptor(zone); | 161 module_descriptor_ = new (zone) ModuleDescriptor(zone); |
156 set_language_mode(STRICT); | 162 set_language_mode(STRICT); |
(...skipping 18 matching lines...) Expand all Loading... | |
175 num_heap_slots_ = scope_info->ContextLength(); | 181 num_heap_slots_ = scope_info->ContextLength(); |
176 DCHECK_LE(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); | 182 DCHECK_LE(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); |
177 } | 183 } |
178 | 184 |
179 DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type, | 185 DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type, |
180 Handle<ScopeInfo> scope_info) | 186 Handle<ScopeInfo> scope_info) |
181 : Scope(zone, scope_type, scope_info), | 187 : Scope(zone, scope_type, scope_info), |
182 function_kind_(scope_info->function_kind()), | 188 function_kind_(scope_info->function_kind()), |
183 params_(0, zone), | 189 params_(0, zone), |
184 sloppy_block_function_map_(zone) { | 190 sloppy_block_function_map_(zone) { |
191 DCHECK_NE(scope_type, SCRIPT_SCOPE); | |
185 SetDefaults(); | 192 SetDefaults(); |
186 } | 193 } |
187 | 194 |
188 Scope::Scope(Zone* zone, const AstRawString* catch_variable_name) | 195 Scope::Scope(Zone* zone, const AstRawString* catch_variable_name) |
189 : zone_(zone), | 196 : zone_(zone), |
190 outer_scope_(nullptr), | 197 outer_scope_(nullptr), |
191 variables_(zone), | 198 variables_(zone), |
192 locals_(0, zone), | 199 locals_(0, zone), |
193 decls_(0, zone), | 200 decls_(0, zone), |
194 scope_type_(CATCH_SCOPE) { | 201 scope_type_(CATCH_SCOPE) { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 DeclarationScope* scope = info->literal()->scope(); | 420 DeclarationScope* scope = info->literal()->scope(); |
414 | 421 |
415 // We are compiling one of three cases: | 422 // We are compiling one of three cases: |
416 // 1) top-level code, | 423 // 1) top-level code, |
417 // 2) a function/eval/module on the top-level | 424 // 2) a function/eval/module on the top-level |
418 // 3) a function/eval in a scope that was already resolved. | 425 // 3) a function/eval in a scope that was already resolved. |
419 DCHECK(scope->scope_type() == SCRIPT_SCOPE || | 426 DCHECK(scope->scope_type() == SCRIPT_SCOPE || |
420 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || | 427 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || |
421 scope->outer_scope()->already_resolved_); | 428 scope->outer_scope()->already_resolved_); |
422 | 429 |
423 // If there's a chance that there's a reference to global 'this', predeclare | |
424 // it as a dynamic global on the script scope. | |
425 if (scope->GetReceiverScope()->is_script_scope()) { | |
426 info->script_scope()->DeclareDynamicGlobal( | |
427 info->ast_value_factory()->this_string(), Variable::THIS); | |
428 } | |
429 | |
430 scope->AllocateVariables(info, mode); | 430 scope->AllocateVariables(info, mode); |
431 | 431 |
432 #ifdef DEBUG | 432 #ifdef DEBUG |
433 if (info->script_is_native() ? FLAG_print_builtin_scopes | 433 if (info->script_is_native() ? FLAG_print_builtin_scopes |
434 : FLAG_print_scopes) { | 434 : FLAG_print_scopes) { |
435 scope->Print(); | 435 scope->Print(); |
436 } | 436 } |
437 scope->CheckScopePositions(); | 437 scope->CheckScopePositions(); |
438 scope->CheckZones(); | 438 scope->CheckZones(); |
439 #endif | 439 #endif |
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1655 Variable* function = | 1655 Variable* function = |
1656 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1656 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
1657 bool is_function_var_in_context = | 1657 bool is_function_var_in_context = |
1658 function != nullptr && function->IsContextSlot(); | 1658 function != nullptr && function->IsContextSlot(); |
1659 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1659 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1660 (is_function_var_in_context ? 1 : 0); | 1660 (is_function_var_in_context ? 1 : 0); |
1661 } | 1661 } |
1662 | 1662 |
1663 } // namespace internal | 1663 } // namespace internal |
1664 } // namespace v8 | 1664 } // namespace v8 |
OLD | NEW |