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 "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/ast/scopeinfo.h" | 8 #include "src/ast/scopeinfo.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 variables_(zone), | 91 variables_(zone), |
92 temps_(4, zone), | 92 temps_(4, zone), |
93 params_(4, zone), | 93 params_(4, zone), |
94 decls_(4, zone), | 94 decls_(4, zone), |
95 module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) | 95 module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) |
96 ModuleDescriptor(zone) | 96 ModuleDescriptor(zone) |
97 : NULL), | 97 : NULL), |
98 sloppy_block_function_map_(zone), | 98 sloppy_block_function_map_(zone), |
99 already_resolved_(false) { | 99 already_resolved_(false) { |
100 SetDefaults(); | 100 SetDefaults(); |
101 if (outer_scope != nullptr) { | 101 if (outer_scope == nullptr) { |
| 102 // If the outer scope is null, this cannot be a with scope. The outermost |
| 103 // scope must be a script scope. |
| 104 DCHECK_EQ(SCRIPT_SCOPE, scope_type); |
| 105 } else { |
102 asm_function_ = outer_scope_->asm_module_; | 106 asm_function_ = outer_scope_->asm_module_; |
103 // Inherit the language mode from the parent scope unless we're a module | 107 // Inherit the language mode from the parent scope unless we're a module |
104 // scope. | 108 // scope. |
105 if (!is_module_scope()) language_mode_ = outer_scope->language_mode_; | 109 if (!is_module_scope()) language_mode_ = outer_scope->language_mode_; |
106 force_context_allocation_ = | 110 force_context_allocation_ = |
107 !is_function_scope() && outer_scope->has_forced_context_allocation(); | 111 !is_function_scope() && outer_scope->has_forced_context_allocation(); |
| 112 outer_scope_->inner_scopes_.Add(this, zone); |
| 113 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); |
108 } | 114 } |
109 | |
110 // The outermost scope must be a script scope. | |
111 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != nullptr); | |
112 } | 115 } |
113 | 116 |
114 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 117 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
115 Handle<ScopeInfo> scope_info) | 118 Handle<ScopeInfo> scope_info) |
116 : outer_scope_(nullptr), | 119 : outer_scope_(nullptr), |
117 inner_scopes_(4, zone), | 120 inner_scopes_(4, zone), |
118 scope_type_(scope_type), | 121 scope_type_(scope_type), |
119 function_kind_(scope_info.is_null() ? kNormalFunction | 122 function_kind_(scope_info.is_null() ? kNormalFunction |
120 : scope_info->function_kind()), | 123 : scope_info->function_kind()), |
121 variables_(zone), | 124 variables_(zone), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 : FLAG_print_scopes) { | 280 : FLAG_print_scopes) { |
278 scope->Print(); | 281 scope->Print(); |
279 } | 282 } |
280 scope->CheckScopePositions(); | 283 scope->CheckScopePositions(); |
281 #endif | 284 #endif |
282 | 285 |
283 info->set_scope(scope); | 286 info->set_scope(scope); |
284 return true; | 287 return true; |
285 } | 288 } |
286 | 289 |
287 | |
288 void Scope::Initialize() { | |
289 DCHECK(!already_resolved()); | |
290 if (outer_scope_ == nullptr) { | |
291 scope_inside_with_ = is_with_scope(); | |
292 } else { | |
293 outer_scope_->inner_scopes_.Add(this, zone()); | |
294 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); | |
295 } | |
296 } | |
297 | |
298 void Scope::DeclareThis(AstValueFactory* ast_value_factory) { | 290 void Scope::DeclareThis(AstValueFactory* ast_value_factory) { |
299 DCHECK(!already_resolved()); | 291 DCHECK(!already_resolved()); |
300 DCHECK(is_declaration_scope()); | 292 DCHECK(is_declaration_scope()); |
301 DCHECK(has_this_declaration()); | 293 DCHECK(has_this_declaration()); |
302 | 294 |
303 bool subclass_constructor = IsSubclassConstructor(function_kind_); | 295 bool subclass_constructor = IsSubclassConstructor(function_kind_); |
304 Variable* var = variables_.Declare( | 296 Variable* var = variables_.Declare( |
305 this, ast_value_factory->this_string(), | 297 this, ast_value_factory->this_string(), |
306 subclass_constructor ? CONST : VAR, Variable::THIS, | 298 subclass_constructor ? CONST : VAR, Variable::THIS, |
307 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); | 299 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1537 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1546 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1538 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1547 (is_function_var_in_context ? 1 : 0); | 1539 (is_function_var_in_context ? 1 : 0); |
1548 } | 1540 } |
1549 | 1541 |
1550 | 1542 |
1551 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1543 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1552 | 1544 |
1553 } // namespace internal | 1545 } // namespace internal |
1554 } // namespace v8 | 1546 } // namespace v8 |
OLD | NEW |