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