| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 delegates->push_back(stmt); | 78 delegates->push_back(stmt); |
| 79 } | 79 } |
| 80 | 80 |
| 81 | 81 |
| 82 // ---------------------------------------------------------------------------- | 82 // ---------------------------------------------------------------------------- |
| 83 // Implementation of Scope | 83 // Implementation of Scope |
| 84 | 84 |
| 85 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 85 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
| 86 FunctionKind function_kind) | 86 FunctionKind function_kind) |
| 87 : outer_scope_(outer_scope), | 87 : outer_scope_(outer_scope), |
| 88 inner_scopes_(4, zone), | |
| 89 scope_type_(scope_type), | 88 scope_type_(scope_type), |
| 90 function_kind_(function_kind), | 89 function_kind_(function_kind), |
| 91 variables_(zone), | 90 variables_(zone), |
| 92 temps_(4, zone), | 91 temps_(4, zone), |
| 93 params_(4, zone), | 92 params_(4, zone), |
| 94 decls_(4, zone), | 93 decls_(4, zone), |
| 95 module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) | 94 module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) |
| 96 ModuleDescriptor(zone) | 95 ModuleDescriptor(zone) |
| 97 : NULL), | 96 : NULL), |
| 98 sloppy_block_function_map_(zone), | 97 sloppy_block_function_map_(zone), |
| 99 already_resolved_(false) { | 98 already_resolved_(false) { |
| 100 SetDefaults(); | 99 SetDefaults(); |
| 101 if (outer_scope == nullptr) { | 100 if (outer_scope == nullptr) { |
| 102 // If the outer scope is null, this cannot be a with scope. The outermost | 101 // If the outer scope is null, this cannot be a with scope. The outermost |
| 103 // scope must be a script scope. | 102 // scope must be a script scope. |
| 104 DCHECK_EQ(SCRIPT_SCOPE, scope_type); | 103 DCHECK_EQ(SCRIPT_SCOPE, scope_type); |
| 105 } else { | 104 } else { |
| 106 asm_function_ = outer_scope_->asm_module_; | 105 asm_function_ = outer_scope_->asm_module_; |
| 107 // Inherit the language mode from the parent scope unless we're a module | 106 // Inherit the language mode from the parent scope unless we're a module |
| 108 // scope. | 107 // scope. |
| 109 if (!is_module_scope()) language_mode_ = outer_scope->language_mode_; | 108 if (!is_module_scope()) language_mode_ = outer_scope->language_mode_; |
| 110 force_context_allocation_ = | 109 force_context_allocation_ = |
| 111 !is_function_scope() && outer_scope->has_forced_context_allocation(); | 110 !is_function_scope() && outer_scope->has_forced_context_allocation(); |
| 112 outer_scope_->inner_scopes_.Add(this, zone); | 111 outer_scope_->AddInnerScope(this); |
| 113 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); | 112 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); |
| 114 } | 113 } |
| 115 } | 114 } |
| 116 | 115 |
| 117 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 116 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
| 118 Handle<ScopeInfo> scope_info) | 117 Handle<ScopeInfo> scope_info) |
| 119 : outer_scope_(nullptr), | 118 : outer_scope_(nullptr), |
| 120 inner_scopes_(4, zone), | |
| 121 scope_type_(scope_type), | 119 scope_type_(scope_type), |
| 122 function_kind_(scope_info.is_null() ? kNormalFunction | 120 function_kind_(scope_info.is_null() ? kNormalFunction |
| 123 : scope_info->function_kind()), | 121 : scope_info->function_kind()), |
| 124 variables_(zone), | 122 variables_(zone), |
| 125 temps_(4, zone), | 123 temps_(4, zone), |
| 126 params_(4, zone), | 124 params_(4, zone), |
| 127 decls_(4, zone), | 125 decls_(4, zone), |
| 128 module_descriptor_(nullptr), | 126 module_descriptor_(nullptr), |
| 129 sloppy_block_function_map_(zone), | 127 sloppy_block_function_map_(zone), |
| 130 already_resolved_(true), | 128 already_resolved_(true), |
| 131 scope_info_(scope_info) { | 129 scope_info_(scope_info) { |
| 132 SetDefaults(); | 130 SetDefaults(); |
| 133 if (!scope_info.is_null()) { | 131 if (!scope_info.is_null()) { |
| 134 scope_calls_eval_ = scope_info->CallsEval(); | 132 scope_calls_eval_ = scope_info->CallsEval(); |
| 135 language_mode_ = scope_info->language_mode(); | 133 language_mode_ = scope_info->language_mode(); |
| 136 is_declaration_scope_ = scope_info->is_declaration_scope(); | 134 is_declaration_scope_ = scope_info->is_declaration_scope(); |
| 137 num_heap_slots_ = scope_info_->ContextLength(); | 135 num_heap_slots_ = scope_info_->ContextLength(); |
| 138 } | 136 } |
| 139 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 137 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. |
| 140 num_heap_slots_ = Max(num_heap_slots_, | 138 num_heap_slots_ = Max(num_heap_slots_, |
| 141 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 139 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); |
| 142 AddInnerScope(inner_scope); | 140 AddInnerScope(inner_scope); |
| 143 } | 141 } |
| 144 | 142 |
| 145 Scope::Scope(Zone* zone, Scope* inner_scope, | 143 Scope::Scope(Zone* zone, Scope* inner_scope, |
| 146 const AstRawString* catch_variable_name) | 144 const AstRawString* catch_variable_name) |
| 147 : outer_scope_(nullptr), | 145 : outer_scope_(nullptr), |
| 148 inner_scopes_(1, zone), | |
| 149 scope_type_(CATCH_SCOPE), | 146 scope_type_(CATCH_SCOPE), |
| 150 function_kind_(kNormalFunction), | 147 function_kind_(kNormalFunction), |
| 151 variables_(zone), | 148 variables_(zone), |
| 152 temps_(0, zone), | 149 temps_(0, zone), |
| 153 params_(0, zone), | 150 params_(0, zone), |
| 154 decls_(0, zone), | 151 decls_(0, zone), |
| 155 module_descriptor_(nullptr), | 152 module_descriptor_(nullptr), |
| 156 sloppy_block_function_map_(zone), | 153 sloppy_block_function_map_(zone), |
| 157 already_resolved_(true) { | 154 already_resolved_(true) { |
| 158 SetDefaults(); | 155 SetDefaults(); |
| 159 AddInnerScope(inner_scope); | 156 AddInnerScope(inner_scope); |
| 160 ++num_var_; | 157 ++num_var_; |
| 161 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 158 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
| 162 Variable* variable = variables_.Declare(this, | 159 Variable* variable = variables_.Declare(this, |
| 163 catch_variable_name, | 160 catch_variable_name, |
| 164 VAR, | 161 VAR, |
| 165 Variable::NORMAL, | 162 Variable::NORMAL, |
| 166 kCreatedInitialized); | 163 kCreatedInitialized); |
| 167 AllocateHeapSlot(variable); | 164 AllocateHeapSlot(variable); |
| 168 } | 165 } |
| 169 | 166 |
| 170 void Scope::SetDefaults() { | 167 void Scope::SetDefaults() { |
| 171 is_declaration_scope_ = | 168 is_declaration_scope_ = |
| 172 is_eval_scope() || is_function_scope() || | 169 is_eval_scope() || is_function_scope() || |
| 173 is_module_scope() || is_script_scope(); | 170 is_module_scope() || is_script_scope(); |
| 171 inner_scope_ = nullptr; |
| 172 sibling_ = nullptr; |
| 174 unresolved_ = nullptr; | 173 unresolved_ = nullptr; |
| 175 scope_name_ = nullptr; | 174 scope_name_ = nullptr; |
| 176 dynamics_ = nullptr; | 175 dynamics_ = nullptr; |
| 177 receiver_ = nullptr; | 176 receiver_ = nullptr; |
| 178 new_target_ = nullptr; | 177 new_target_ = nullptr; |
| 179 function_ = nullptr; | 178 function_ = nullptr; |
| 180 arguments_ = nullptr; | 179 arguments_ = nullptr; |
| 181 this_function_ = nullptr; | 180 this_function_ = nullptr; |
| 182 scope_inside_with_ = false; | 181 scope_inside_with_ = false; |
| 183 scope_calls_eval_ = false; | 182 scope_calls_eval_ = false; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 DCHECK(params_.is_empty()); | 330 DCHECK(params_.is_empty()); |
| 332 | 331 |
| 333 if (num_var() > 0 || (is_declaration_scope() && calls_sloppy_eval())) { | 332 if (num_var() > 0 || (is_declaration_scope() && calls_sloppy_eval())) { |
| 334 return this; | 333 return this; |
| 335 } | 334 } |
| 336 | 335 |
| 337 // Remove this scope from outer scope. | 336 // Remove this scope from outer scope. |
| 338 outer_scope()->RemoveInnerScope(this); | 337 outer_scope()->RemoveInnerScope(this); |
| 339 | 338 |
| 340 // Reparent inner scopes. | 339 // Reparent inner scopes. |
| 341 for (int i = 0; i < inner_scopes_.length(); i++) { | 340 if (inner_scope_ != nullptr) { |
| 342 outer_scope()->AddInnerScope(inner_scopes_[i]); | 341 Scope* scope = inner_scope_; |
| 342 scope->outer_scope_ = outer_scope(); |
| 343 while (scope->sibling_ != nullptr) { |
| 344 scope = scope->sibling_; |
| 345 scope->outer_scope_ = outer_scope(); |
| 346 } |
| 347 scope->sibling_ = outer_scope()->inner_scope_; |
| 348 outer_scope()->inner_scope_ = inner_scope_; |
| 349 inner_scope_ = nullptr; |
| 343 } | 350 } |
| 344 | 351 |
| 345 // Move unresolved variables | 352 // Move unresolved variables |
| 346 VariableProxy* unresolved = unresolved_; | 353 if (unresolved_ != nullptr) { |
| 347 if (outer_scope()->unresolved_ == nullptr) { | 354 if (outer_scope()->unresolved_ != nullptr) { |
| 348 outer_scope()->unresolved_ = unresolved; | 355 VariableProxy* unresolved = unresolved_; |
| 349 } else if (unresolved != nullptr) { | 356 while (unresolved->next_unresolved() != nullptr) { |
| 350 while (unresolved->next_unresolved() != nullptr) { | 357 unresolved = unresolved->next_unresolved(); |
| 351 unresolved = unresolved->next_unresolved(); | 358 } |
| 359 unresolved->set_next_unresolved(outer_scope()->unresolved_); |
| 352 } | 360 } |
| 353 unresolved->set_next_unresolved(outer_scope()->unresolved_); | |
| 354 outer_scope()->unresolved_ = unresolved_; | 361 outer_scope()->unresolved_ = unresolved_; |
| 362 unresolved_ = nullptr; |
| 355 } | 363 } |
| 356 | 364 |
| 357 PropagateUsageFlagsToScope(outer_scope_); | 365 PropagateUsageFlagsToScope(outer_scope_); |
| 358 | 366 |
| 359 return NULL; | 367 return NULL; |
| 360 } | 368 } |
| 361 | 369 |
| 362 | 370 |
| 363 void Scope::ReplaceOuterScope(Scope* outer) { | 371 void Scope::ReplaceOuterScope(Scope* outer) { |
| 364 DCHECK_NOT_NULL(outer); | 372 DCHECK_NOT_NULL(outer); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 for (Scope* s = this; s != scope; s = s->outer_scope_) { | 777 for (Scope* s = this; s != scope; s = s->outer_scope_) { |
| 770 DCHECK(s != NULL); // scope must be in the scope chain | 778 DCHECK(s != NULL); // scope must be in the scope chain |
| 771 if (s->NeedsContext()) n++; | 779 if (s->NeedsContext()) n++; |
| 772 } | 780 } |
| 773 return n; | 781 return n; |
| 774 } | 782 } |
| 775 | 783 |
| 776 | 784 |
| 777 int Scope::MaxNestedContextChainLength() { | 785 int Scope::MaxNestedContextChainLength() { |
| 778 int max_context_chain_length = 0; | 786 int max_context_chain_length = 0; |
| 779 for (int i = 0; i < inner_scopes_.length(); i++) { | 787 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
| 780 Scope* scope = inner_scopes_[i]; | |
| 781 max_context_chain_length = std::max(scope->MaxNestedContextChainLength(), | 788 max_context_chain_length = std::max(scope->MaxNestedContextChainLength(), |
| 782 max_context_chain_length); | 789 max_context_chain_length); |
| 783 } | 790 } |
| 784 if (NeedsContext()) { | 791 if (NeedsContext()) { |
| 785 max_context_chain_length += 1; | 792 max_context_chain_length += 1; |
| 786 } | 793 } |
| 787 return max_context_chain_length; | 794 return max_context_chain_length; |
| 788 } | 795 } |
| 789 | 796 |
| 790 | 797 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 Handle<StringSet> Scope::CollectNonLocals(Handle<StringSet> non_locals) { | 834 Handle<StringSet> Scope::CollectNonLocals(Handle<StringSet> non_locals) { |
| 828 // Collect non-local variables referenced in the scope. | 835 // Collect non-local variables referenced in the scope. |
| 829 // TODO(yangguo): store non-local variables explicitly if we can no longer | 836 // TODO(yangguo): store non-local variables explicitly if we can no longer |
| 830 // rely on unresolved_ to find them. | 837 // rely on unresolved_ to find them. |
| 831 for (VariableProxy* proxy = unresolved_; proxy != nullptr; | 838 for (VariableProxy* proxy = unresolved_; proxy != nullptr; |
| 832 proxy = proxy->next_unresolved()) { | 839 proxy = proxy->next_unresolved()) { |
| 833 if (proxy->is_resolved() && proxy->var()->IsStackAllocated()) continue; | 840 if (proxy->is_resolved() && proxy->var()->IsStackAllocated()) continue; |
| 834 Handle<String> name = proxy->name(); | 841 Handle<String> name = proxy->name(); |
| 835 non_locals = StringSet::Add(non_locals, name); | 842 non_locals = StringSet::Add(non_locals, name); |
| 836 } | 843 } |
| 837 for (int i = 0; i < inner_scopes_.length(); i++) { | 844 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
| 838 non_locals = inner_scopes_[i]->CollectNonLocals(non_locals); | 845 non_locals = scope->CollectNonLocals(non_locals); |
| 839 } | 846 } |
| 840 return non_locals; | 847 return non_locals; |
| 841 } | 848 } |
| 842 | 849 |
| 843 | 850 |
| 844 #ifdef DEBUG | 851 #ifdef DEBUG |
| 845 static const char* Header(ScopeType scope_type, FunctionKind function_kind, | 852 static const char* Header(ScopeType scope_type, FunctionKind function_kind, |
| 846 bool is_declaration_scope) { | 853 bool is_declaration_scope) { |
| 847 switch (scope_type) { | 854 switch (scope_type) { |
| 848 case EVAL_SCOPE: return "eval"; | 855 case EVAL_SCOPE: return "eval"; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1028 |
| 1022 if (dynamics_ != NULL) { | 1029 if (dynamics_ != NULL) { |
| 1023 Indent(n1, "// dynamic vars:\n"); | 1030 Indent(n1, "// dynamic vars:\n"); |
| 1024 PrintMap(n1, dynamics_->GetMap(DYNAMIC)); | 1031 PrintMap(n1, dynamics_->GetMap(DYNAMIC)); |
| 1025 PrintMap(n1, dynamics_->GetMap(DYNAMIC_LOCAL)); | 1032 PrintMap(n1, dynamics_->GetMap(DYNAMIC_LOCAL)); |
| 1026 PrintMap(n1, dynamics_->GetMap(DYNAMIC_GLOBAL)); | 1033 PrintMap(n1, dynamics_->GetMap(DYNAMIC_GLOBAL)); |
| 1027 } | 1034 } |
| 1028 | 1035 |
| 1029 // Print inner scopes (disable by providing negative n). | 1036 // Print inner scopes (disable by providing negative n). |
| 1030 if (n >= 0) { | 1037 if (n >= 0) { |
| 1031 for (int i = 0; i < inner_scopes_.length(); i++) { | 1038 for (Scope* scope = inner_scope_; scope != nullptr; |
| 1039 scope = scope->sibling_) { |
| 1032 PrintF("\n"); | 1040 PrintF("\n"); |
| 1033 inner_scopes_[i]->Print(n1); | 1041 scope->Print(n1); |
| 1034 } | 1042 } |
| 1035 } | 1043 } |
| 1036 | 1044 |
| 1037 Indent(n0, "}\n"); | 1045 Indent(n0, "}\n"); |
| 1038 } | 1046 } |
| 1039 | 1047 |
| 1040 void Scope::CheckScopePositions() { | 1048 void Scope::CheckScopePositions() { |
| 1041 // A scope is allowed to have invalid positions if it is hidden and has no | 1049 // A scope is allowed to have invalid positions if it is hidden and has no |
| 1042 // inner scopes | 1050 // inner scopes |
| 1043 if (!is_hidden() && inner_scopes_.length() == 0) { | 1051 if (!is_hidden() && inner_scope_ == nullptr) { |
| 1044 CHECK_NE(kNoSourcePosition, start_position()); | 1052 CHECK_NE(kNoSourcePosition, start_position()); |
| 1045 CHECK_NE(kNoSourcePosition, end_position()); | 1053 CHECK_NE(kNoSourcePosition, end_position()); |
| 1046 } | 1054 } |
| 1047 for (Scope* scope : inner_scopes_) scope->CheckScopePositions(); | 1055 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
| 1056 scope->CheckScopePositions(); |
| 1057 } |
| 1048 } | 1058 } |
| 1049 #endif // DEBUG | 1059 #endif // DEBUG |
| 1050 | 1060 |
| 1051 | 1061 |
| 1052 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { | 1062 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { |
| 1053 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); | 1063 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); |
| 1054 VariableMap* map = dynamics_->GetMap(mode); | 1064 VariableMap* map = dynamics_->GetMap(mode); |
| 1055 Variable* var = map->Lookup(name); | 1065 Variable* var = map->Lookup(name); |
| 1056 if (var == NULL) { | 1066 if (var == NULL) { |
| 1057 // Declare a new non-local. | 1067 // Declare a new non-local. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 AstNodeFactory* factory) { | 1233 AstNodeFactory* factory) { |
| 1224 DCHECK(info->script_scope()->is_script_scope()); | 1234 DCHECK(info->script_scope()->is_script_scope()); |
| 1225 | 1235 |
| 1226 // Resolve unresolved variables for this scope. | 1236 // Resolve unresolved variables for this scope. |
| 1227 for (VariableProxy* proxy = unresolved_; proxy != nullptr; | 1237 for (VariableProxy* proxy = unresolved_; proxy != nullptr; |
| 1228 proxy = proxy->next_unresolved()) { | 1238 proxy = proxy->next_unresolved()) { |
| 1229 if (!ResolveVariable(info, proxy, factory)) return false; | 1239 if (!ResolveVariable(info, proxy, factory)) return false; |
| 1230 } | 1240 } |
| 1231 | 1241 |
| 1232 // Resolve unresolved variables for inner scopes. | 1242 // Resolve unresolved variables for inner scopes. |
| 1233 for (int i = 0; i < inner_scopes_.length(); i++) { | 1243 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
| 1234 if (!inner_scopes_[i]->ResolveVariablesRecursively(info, factory)) | 1244 if (!scope->ResolveVariablesRecursively(info, factory)) return false; |
| 1235 return false; | |
| 1236 } | 1245 } |
| 1237 | 1246 |
| 1238 return true; | 1247 return true; |
| 1239 } | 1248 } |
| 1240 | 1249 |
| 1241 | 1250 |
| 1242 void Scope::PropagateScopeInfo(bool outer_scope_calls_sloppy_eval ) { | 1251 void Scope::PropagateScopeInfo(bool outer_scope_calls_sloppy_eval ) { |
| 1243 if (outer_scope_calls_sloppy_eval) { | 1252 if (outer_scope_calls_sloppy_eval) { |
| 1244 outer_scope_calls_sloppy_eval_ = true; | 1253 outer_scope_calls_sloppy_eval_ = true; |
| 1245 } | 1254 } |
| 1246 | 1255 |
| 1247 bool calls_sloppy_eval = | 1256 bool calls_sloppy_eval = |
| 1248 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; | 1257 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; |
| 1249 for (int i = 0; i < inner_scopes_.length(); i++) { | 1258 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) { |
| 1250 Scope* inner = inner_scopes_[i]; | |
| 1251 inner->PropagateScopeInfo(calls_sloppy_eval); | 1259 inner->PropagateScopeInfo(calls_sloppy_eval); |
| 1252 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { | 1260 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { |
| 1253 inner_scope_calls_eval_ = true; | 1261 inner_scope_calls_eval_ = true; |
| 1254 } | 1262 } |
| 1255 if (inner->force_eager_compilation_) { | 1263 if (inner->force_eager_compilation_) { |
| 1256 force_eager_compilation_ = true; | 1264 force_eager_compilation_ = true; |
| 1257 } | 1265 } |
| 1258 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { | 1266 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { |
| 1259 inner->asm_function_ = true; | 1267 inner->asm_function_ = true; |
| 1260 } | 1268 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 if (this_function_ != nullptr && !MustAllocate(this_function_)) { | 1480 if (this_function_ != nullptr && !MustAllocate(this_function_)) { |
| 1473 this_function_ = nullptr; | 1481 this_function_ = nullptr; |
| 1474 } | 1482 } |
| 1475 } | 1483 } |
| 1476 | 1484 |
| 1477 void Scope::AllocateVariablesRecursively(AstValueFactory* ast_value_factory) { | 1485 void Scope::AllocateVariablesRecursively(AstValueFactory* ast_value_factory) { |
| 1478 if (!already_resolved()) { | 1486 if (!already_resolved()) { |
| 1479 num_stack_slots_ = 0; | 1487 num_stack_slots_ = 0; |
| 1480 } | 1488 } |
| 1481 // Allocate variables for inner scopes. | 1489 // Allocate variables for inner scopes. |
| 1482 for (int i = 0; i < inner_scopes_.length(); i++) { | 1490 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
| 1483 inner_scopes_[i]->AllocateVariablesRecursively(ast_value_factory); | 1491 scope->AllocateVariablesRecursively(ast_value_factory); |
| 1484 } | 1492 } |
| 1485 | 1493 |
| 1486 // If scope is already resolved, we still need to allocate | 1494 // If scope is already resolved, we still need to allocate |
| 1487 // variables in inner scopes which might not have been resolved yet. | 1495 // variables in inner scopes which might not have been resolved yet. |
| 1488 if (already_resolved()) return; | 1496 if (already_resolved()) return; |
| 1489 // The number of slots required for variables. | 1497 // The number of slots required for variables. |
| 1490 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 1498 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
| 1491 | 1499 |
| 1492 // Allocate variables for this scope. | 1500 // Allocate variables for this scope. |
| 1493 // Parameters must be allocated first, if any. | 1501 // Parameters must be allocated first, if any. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1535 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
| 1528 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1536 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1529 (is_function_var_in_context ? 1 : 0); | 1537 (is_function_var_in_context ? 1 : 0); |
| 1530 } | 1538 } |
| 1531 | 1539 |
| 1532 | 1540 |
| 1533 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1541 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1534 | 1542 |
| 1535 } // namespace internal | 1543 } // namespace internal |
| 1536 } // namespace v8 | 1544 } // namespace v8 |
| OLD | NEW |