| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 illegal_redecl_ = NULL; | 190 illegal_redecl_ = NULL; |
| 191 scope_inside_with_ = false; | 191 scope_inside_with_ = false; |
| 192 scope_contains_with_ = false; | 192 scope_contains_with_ = false; |
| 193 scope_calls_eval_ = false; | 193 scope_calls_eval_ = false; |
| 194 // Inherit the strict mode from the parent scope. | 194 // Inherit the strict mode from the parent scope. |
| 195 language_mode_ = (outer_scope != NULL) | 195 language_mode_ = (outer_scope != NULL) |
| 196 ? outer_scope->language_mode_ : CLASSIC_MODE; | 196 ? outer_scope->language_mode_ : CLASSIC_MODE; |
| 197 outer_scope_calls_non_strict_eval_ = false; | 197 outer_scope_calls_non_strict_eval_ = false; |
| 198 inner_scope_calls_eval_ = false; | 198 inner_scope_calls_eval_ = false; |
| 199 force_eager_compilation_ = false; | 199 force_eager_compilation_ = false; |
| 200 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
| 201 ? outer_scope->has_forced_context_allocation() : false; |
| 200 num_var_or_const_ = 0; | 202 num_var_or_const_ = 0; |
| 201 num_stack_slots_ = 0; | 203 num_stack_slots_ = 0; |
| 202 num_heap_slots_ = 0; | 204 num_heap_slots_ = 0; |
| 203 num_modules_ = 0; | 205 num_modules_ = 0; |
| 204 module_var_ = NULL, | 206 module_var_ = NULL, |
| 205 scope_info_ = scope_info; | 207 scope_info_ = scope_info; |
| 206 start_position_ = RelocInfo::kNoPosition; | 208 start_position_ = RelocInfo::kNoPosition; |
| 207 end_position_ = RelocInfo::kNoPosition; | 209 end_position_ = RelocInfo::kNoPosition; |
| 208 if (!scope_info.is_null()) { | 210 if (!scope_info.is_null()) { |
| 209 scope_calls_eval_ = scope_info->CallsEval(); | 211 scope_calls_eval_ = scope_info->CallsEval(); |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 598 |
| 597 // Collect internals which are always allocated on the heap. | 599 // Collect internals which are always allocated on the heap. |
| 598 for (int i = 0; i < internals_.length(); i++) { | 600 for (int i = 0; i < internals_.length(); i++) { |
| 599 Variable* var = internals_[i]; | 601 Variable* var = internals_[i]; |
| 600 if (var->is_used()) { | 602 if (var->is_used()) { |
| 601 ASSERT(var->IsContextSlot()); | 603 ASSERT(var->IsContextSlot()); |
| 602 context_locals->Add(var, zone()); | 604 context_locals->Add(var, zone()); |
| 603 } | 605 } |
| 604 } | 606 } |
| 605 | 607 |
| 606 // Collect temporaries which are always allocated on the stack. | 608 // Collect temporaries which are always allocated on the stack, unless the |
| 609 // context as a whole has forced context allocation. |
| 607 for (int i = 0; i < temps_.length(); i++) { | 610 for (int i = 0; i < temps_.length(); i++) { |
| 608 Variable* var = temps_[i]; | 611 Variable* var = temps_[i]; |
| 609 if (var->is_used()) { | 612 if (var->is_used()) { |
| 610 ASSERT(var->IsStackLocal()); | 613 if (var->IsContextSlot()) { |
| 611 stack_locals->Add(var, zone()); | 614 ASSERT(has_forced_context_allocation()); |
| 615 context_locals->Add(var, zone()); |
| 616 } else { |
| 617 ASSERT(var->IsStackLocal()); |
| 618 stack_locals->Add(var, zone()); |
| 619 } |
| 612 } | 620 } |
| 613 } | 621 } |
| 614 | 622 |
| 615 // Collect declared local variables. | 623 // Collect declared local variables. |
| 616 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); | 624 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); |
| 617 for (VariableMap::Entry* p = variables_.Start(); | 625 for (VariableMap::Entry* p = variables_.Start(); |
| 618 p != NULL; | 626 p != NULL; |
| 619 p = variables_.Next(p)) { | 627 p = variables_.Next(p)) { |
| 620 Variable* var = reinterpret_cast<Variable*>(p->value); | 628 Variable* var = reinterpret_cast<Variable*>(p->value); |
| 621 if (var->is_used()) { | 629 if (var->is_used()) { |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 return !var->IsGlobalObjectProperty() && var->is_used(); | 1183 return !var->IsGlobalObjectProperty() && var->is_used(); |
| 1176 } | 1184 } |
| 1177 | 1185 |
| 1178 | 1186 |
| 1179 bool Scope::MustAllocateInContext(Variable* var) { | 1187 bool Scope::MustAllocateInContext(Variable* var) { |
| 1180 // If var is accessed from an inner scope, or if there is a possibility | 1188 // 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 | 1189 // 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 | 1190 // an eval() call or a runtime with lookup), it must be allocated in the |
| 1183 // context. | 1191 // context. |
| 1184 // | 1192 // |
| 1185 // Exceptions: temporary variables are never allocated in a context; | 1193 // Exceptions: If the scope as a whole has forced context allocation, all |
| 1186 // catch-bound variables are always allocated in a context. | 1194 // variables will have context allocation, even temporaries. Otherwise |
| 1195 // temporary variables are always stack-allocated. Catch-bound variables are |
| 1196 // always context-allocated. |
| 1197 if (has_forced_context_allocation()) return true; |
| 1187 if (var->mode() == TEMPORARY) return false; | 1198 if (var->mode() == TEMPORARY) return false; |
| 1188 if (var->mode() == INTERNAL) return true; | 1199 if (var->mode() == INTERNAL) return true; |
| 1189 if (is_catch_scope() || is_block_scope() || is_module_scope()) return true; | 1200 if (is_catch_scope() || is_block_scope() || is_module_scope()) return true; |
| 1190 if (is_global_scope() && IsLexicalVariableMode(var->mode())) return true; | 1201 if (is_global_scope() && IsLexicalVariableMode(var->mode())) return true; |
| 1191 return var->has_forced_context_allocation() || | 1202 return var->has_forced_context_allocation() || |
| 1192 scope_calls_eval_ || | 1203 scope_calls_eval_ || |
| 1193 inner_scope_calls_eval_ || | 1204 inner_scope_calls_eval_ || |
| 1194 scope_contains_with_; | 1205 scope_contains_with_; |
| 1195 } | 1206 } |
| 1196 | 1207 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 } | 1390 } |
| 1380 | 1391 |
| 1381 | 1392 |
| 1382 int Scope::ContextLocalCount() const { | 1393 int Scope::ContextLocalCount() const { |
| 1383 if (num_heap_slots() == 0) return 0; | 1394 if (num_heap_slots() == 0) return 0; |
| 1384 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1395 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1385 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1396 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1386 } | 1397 } |
| 1387 | 1398 |
| 1388 } } // namespace v8::internal | 1399 } } // namespace v8::internal |
| OLD | NEW |