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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 num_stack_slots_ = 0; | 186 num_stack_slots_ = 0; |
187 num_heap_slots_ = 0; | 187 num_heap_slots_ = 0; |
188 num_global_slots_ = 0; | 188 num_global_slots_ = 0; |
189 arity_ = 0; | 189 arity_ = 0; |
190 has_simple_parameters_ = true; | 190 has_simple_parameters_ = true; |
191 rest_parameter_ = NULL; | 191 rest_parameter_ = NULL; |
192 rest_index_ = -1; | 192 rest_index_ = -1; |
193 scope_info_ = scope_info; | 193 scope_info_ = scope_info; |
194 start_position_ = RelocInfo::kNoPosition; | 194 start_position_ = RelocInfo::kNoPosition; |
195 end_position_ = RelocInfo::kNoPosition; | 195 end_position_ = RelocInfo::kNoPosition; |
| 196 is_hidden_ = false; |
196 if (!scope_info.is_null()) { | 197 if (!scope_info.is_null()) { |
197 scope_calls_eval_ = scope_info->CallsEval(); | 198 scope_calls_eval_ = scope_info->CallsEval(); |
198 language_mode_ = scope_info->language_mode(); | 199 language_mode_ = scope_info->language_mode(); |
199 is_declaration_scope_ = scope_info->is_declaration_scope(); | 200 is_declaration_scope_ = scope_info->is_declaration_scope(); |
200 function_kind_ = scope_info->function_kind(); | 201 function_kind_ = scope_info->function_kind(); |
201 } | 202 } |
202 } | 203 } |
203 | 204 |
204 | 205 |
205 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, | 206 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 info->script()); | 281 info->script()); |
281 return false; | 282 return false; |
282 } | 283 } |
283 } | 284 } |
284 | 285 |
285 #ifdef DEBUG | 286 #ifdef DEBUG |
286 if (info->script_is_native() ? FLAG_print_builtin_scopes | 287 if (info->script_is_native() ? FLAG_print_builtin_scopes |
287 : FLAG_print_scopes) { | 288 : FLAG_print_scopes) { |
288 scope->Print(); | 289 scope->Print(); |
289 } | 290 } |
| 291 scope->CheckScopePositions(); |
290 #endif | 292 #endif |
291 | 293 |
292 info->set_scope(scope); | 294 info->set_scope(scope); |
293 return true; | 295 return true; |
294 } | 296 } |
295 | 297 |
296 | 298 |
297 void Scope::Initialize() { | 299 void Scope::Initialize() { |
298 DCHECK(!already_resolved()); | 300 DCHECK(!already_resolved()); |
299 | 301 |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 // Print inner scopes (disable by providing negative n). | 1002 // Print inner scopes (disable by providing negative n). |
1001 if (n >= 0) { | 1003 if (n >= 0) { |
1002 for (int i = 0; i < inner_scopes_.length(); i++) { | 1004 for (int i = 0; i < inner_scopes_.length(); i++) { |
1003 PrintF("\n"); | 1005 PrintF("\n"); |
1004 inner_scopes_[i]->Print(n1); | 1006 inner_scopes_[i]->Print(n1); |
1005 } | 1007 } |
1006 } | 1008 } |
1007 | 1009 |
1008 Indent(n0, "}\n"); | 1010 Indent(n0, "}\n"); |
1009 } | 1011 } |
| 1012 |
| 1013 void Scope::CheckScopePositions() { |
| 1014 // A scope is allowed to have invalid positions if it is hidden and has no |
| 1015 // inner scopes |
| 1016 if (!is_hidden() && inner_scopes_.length() == 0) { |
| 1017 CHECK_NE(RelocInfo::kNoPosition, start_position()); |
| 1018 CHECK_NE(RelocInfo::kNoPosition, end_position()); |
| 1019 } |
| 1020 for (Scope* scope : inner_scopes_) scope->CheckScopePositions(); |
| 1021 } |
1010 #endif // DEBUG | 1022 #endif // DEBUG |
1011 | 1023 |
1012 | 1024 |
1013 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { | 1025 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { |
1014 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); | 1026 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); |
1015 VariableMap* map = dynamics_->GetMap(mode); | 1027 VariableMap* map = dynamics_->GetMap(mode); |
1016 Variable* var = map->Lookup(name); | 1028 Variable* var = map->Lookup(name); |
1017 if (var == NULL) { | 1029 if (var == NULL) { |
1018 // Declare a new non-local. | 1030 // Declare a new non-local. |
1019 InitializationFlag init_flag = (mode == VAR) | 1031 InitializationFlag init_flag = (mode == VAR) |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1511 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1500 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1512 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1501 (is_function_var_in_context ? 1 : 0); | 1513 (is_function_var_in_context ? 1 : 0); |
1502 } | 1514 } |
1503 | 1515 |
1504 | 1516 |
1505 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1517 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1506 | 1518 |
1507 } // namespace internal | 1519 } // namespace internal |
1508 } // namespace v8 | 1520 } // namespace v8 |
OLD | NEW |