Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 temps_(4, zone), | 112 temps_(4, zone), |
| 113 params_(4, zone), | 113 params_(4, zone), |
| 114 unresolved_(16, zone), | 114 unresolved_(16, zone), |
| 115 decls_(4, zone), | 115 decls_(4, zone), |
| 116 interface_(FLAG_harmony_modules && | 116 interface_(FLAG_harmony_modules && |
| 117 (type == MODULE_SCOPE || type == GLOBAL_SCOPE) | 117 (type == MODULE_SCOPE || type == GLOBAL_SCOPE) |
| 118 ? Interface::NewModule(zone) : NULL), | 118 ? Interface::NewModule(zone) : NULL), |
| 119 already_resolved_(false), | 119 already_resolved_(false), |
| 120 zone_(zone) { | 120 zone_(zone) { |
| 121 SetDefaults(type, outer_scope, Handle<ScopeInfo>::null()); | 121 SetDefaults(type, outer_scope, Handle<ScopeInfo>::null()); |
| 122 if (!is_function_scope() && | |
|
Michael Starzinger
2013/04/05 11:38:42
I would feel more comfortable if we could move thi
wingo
2013/04/05 12:25:06
Done. I assume you meant !is_function_scope() her
Michael Starzinger
2013/04/05 13:06:56
Yep, that was a typo on my end.
| |
| 123 outer_scope && | |
| 124 outer_scope->has_forced_context_allocation()) | |
| 125 ForceContextAllocation(); | |
| 122 // The outermost scope must be a global scope. | 126 // The outermost scope must be a global scope. |
| 123 ASSERT(type == GLOBAL_SCOPE || outer_scope != NULL); | 127 ASSERT(type == GLOBAL_SCOPE || outer_scope != NULL); |
| 124 ASSERT(!HasIllegalRedeclaration()); | 128 ASSERT(!HasIllegalRedeclaration()); |
| 125 } | 129 } |
| 126 | 130 |
| 127 | 131 |
| 128 Scope::Scope(Scope* inner_scope, | 132 Scope::Scope(Scope* inner_scope, |
| 129 ScopeType type, | 133 ScopeType type, |
| 130 Handle<ScopeInfo> scope_info, | 134 Handle<ScopeInfo> scope_info, |
| 131 Zone* zone) | 135 Zone* zone) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 illegal_redecl_ = NULL; | 194 illegal_redecl_ = NULL; |
| 191 scope_inside_with_ = false; | 195 scope_inside_with_ = false; |
| 192 scope_contains_with_ = false; | 196 scope_contains_with_ = false; |
| 193 scope_calls_eval_ = false; | 197 scope_calls_eval_ = false; |
| 194 // Inherit the strict mode from the parent scope. | 198 // Inherit the strict mode from the parent scope. |
| 195 language_mode_ = (outer_scope != NULL) | 199 language_mode_ = (outer_scope != NULL) |
| 196 ? outer_scope->language_mode_ : CLASSIC_MODE; | 200 ? outer_scope->language_mode_ : CLASSIC_MODE; |
| 197 outer_scope_calls_non_strict_eval_ = false; | 201 outer_scope_calls_non_strict_eval_ = false; |
| 198 inner_scope_calls_eval_ = false; | 202 inner_scope_calls_eval_ = false; |
| 199 force_eager_compilation_ = false; | 203 force_eager_compilation_ = false; |
| 204 force_context_allocation_ = false; | |
| 200 num_var_or_const_ = 0; | 205 num_var_or_const_ = 0; |
| 201 num_stack_slots_ = 0; | 206 num_stack_slots_ = 0; |
| 202 num_heap_slots_ = 0; | 207 num_heap_slots_ = 0; |
| 203 num_modules_ = 0; | 208 num_modules_ = 0; |
| 204 module_var_ = NULL, | 209 module_var_ = NULL, |
| 205 scope_info_ = scope_info; | 210 scope_info_ = scope_info; |
| 206 start_position_ = RelocInfo::kNoPosition; | 211 start_position_ = RelocInfo::kNoPosition; |
| 207 end_position_ = RelocInfo::kNoPosition; | 212 end_position_ = RelocInfo::kNoPosition; |
| 208 if (!scope_info.is_null()) { | 213 if (!scope_info.is_null()) { |
| 209 scope_calls_eval_ = scope_info->CallsEval(); | 214 scope_calls_eval_ = scope_info->CallsEval(); |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 | 601 |
| 597 // Collect internals which are always allocated on the heap. | 602 // Collect internals which are always allocated on the heap. |
| 598 for (int i = 0; i < internals_.length(); i++) { | 603 for (int i = 0; i < internals_.length(); i++) { |
| 599 Variable* var = internals_[i]; | 604 Variable* var = internals_[i]; |
| 600 if (var->is_used()) { | 605 if (var->is_used()) { |
| 601 ASSERT(var->IsContextSlot()); | 606 ASSERT(var->IsContextSlot()); |
| 602 context_locals->Add(var, zone()); | 607 context_locals->Add(var, zone()); |
| 603 } | 608 } |
| 604 } | 609 } |
| 605 | 610 |
| 606 // Collect temporaries which are always allocated on the stack. | 611 // Collect temporaries which are always allocated on the stack, unless the |
| 612 // context as a whole has forced context allocation. | |
| 607 for (int i = 0; i < temps_.length(); i++) { | 613 for (int i = 0; i < temps_.length(); i++) { |
| 608 Variable* var = temps_[i]; | 614 Variable* var = temps_[i]; |
| 609 if (var->is_used()) { | 615 if (var->is_used()) { |
| 610 ASSERT(var->IsStackLocal()); | 616 if (var->IsContextSlot()) { |
| 611 stack_locals->Add(var, zone()); | 617 ASSERT(has_forced_context_allocation()); |
| 618 context_locals->Add(var, zone()); | |
| 619 } else { | |
| 620 ASSERT(var->IsStackLocal()); | |
| 621 stack_locals->Add(var, zone()); | |
| 622 } | |
| 612 } | 623 } |
| 613 } | 624 } |
| 614 | 625 |
| 615 // Collect declared local variables. | 626 // Collect declared local variables. |
| 616 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); | 627 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); |
| 617 for (VariableMap::Entry* p = variables_.Start(); | 628 for (VariableMap::Entry* p = variables_.Start(); |
| 618 p != NULL; | 629 p != NULL; |
| 619 p = variables_.Next(p)) { | 630 p = variables_.Next(p)) { |
| 620 Variable* var = reinterpret_cast<Variable*>(p->value); | 631 Variable* var = reinterpret_cast<Variable*>(p->value); |
| 621 if (var->is_used()) { | 632 if (var->is_used()) { |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1175 return !var->IsGlobalObjectProperty() && var->is_used(); | 1186 return !var->IsGlobalObjectProperty() && var->is_used(); |
| 1176 } | 1187 } |
| 1177 | 1188 |
| 1178 | 1189 |
| 1179 bool Scope::MustAllocateInContext(Variable* var) { | 1190 bool Scope::MustAllocateInContext(Variable* var) { |
| 1180 // If var is accessed from an inner scope, or if there is a possibility | 1191 // If var is accessed from an inner scope, or if there is a possibility |
| 1181 // that it might be accessed from the current or an inner scope (through | 1192 // that it might be accessed from the current or an inner scope (through |
| 1182 // an eval() call or a runtime with lookup), it must be allocated in the | 1193 // an eval() call or a runtime with lookup), it must be allocated in the |
| 1183 // context. | 1194 // context. |
| 1184 // | 1195 // |
| 1185 // Exceptions: temporary variables are never allocated in a context; | 1196 // Exceptions: If the scope as a whole has forced context allocation, all |
| 1186 // catch-bound variables are always allocated in a context. | 1197 // variables will have context allocation, even temporaries. Otherwise |
| 1198 // temporary variables are always stack-allocated. Catch-bound variables are | |
| 1199 // always context-allocated. | |
| 1200 if (has_forced_context_allocation()) return true; | |
| 1187 if (var->mode() == TEMPORARY) return false; | 1201 if (var->mode() == TEMPORARY) return false; |
| 1188 if (var->mode() == INTERNAL) return true; | 1202 if (var->mode() == INTERNAL) return true; |
| 1189 if (is_catch_scope() || is_block_scope() || is_module_scope()) return true; | 1203 if (is_catch_scope() || is_block_scope() || is_module_scope()) return true; |
| 1190 if (is_global_scope() && IsLexicalVariableMode(var->mode())) return true; | 1204 if (is_global_scope() && IsLexicalVariableMode(var->mode())) return true; |
| 1191 return var->has_forced_context_allocation() || | 1205 return var->has_forced_context_allocation() || |
| 1192 scope_calls_eval_ || | 1206 scope_calls_eval_ || |
| 1193 inner_scope_calls_eval_ || | 1207 inner_scope_calls_eval_ || |
| 1194 scope_contains_with_; | 1208 scope_contains_with_; |
| 1195 } | 1209 } |
| 1196 | 1210 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1379 } | 1393 } |
| 1380 | 1394 |
| 1381 | 1395 |
| 1382 int Scope::ContextLocalCount() const { | 1396 int Scope::ContextLocalCount() const { |
| 1383 if (num_heap_slots() == 0) return 0; | 1397 if (num_heap_slots() == 0) return 0; |
| 1384 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1398 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1385 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1399 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1386 } | 1400 } |
| 1387 | 1401 |
| 1388 } } // namespace v8::internal | 1402 } } // namespace v8::internal |
| OLD | NEW |