| 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 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 | 1084 |
| 1085 bool Scope::MustAllocateInContext(Variable* var) { | 1085 bool Scope::MustAllocateInContext(Variable* var) { |
| 1086 // If var is accessed from an inner scope, or if there is a possibility | 1086 // If var is accessed from an inner scope, or if there is a possibility |
| 1087 // that it might be accessed from the current or an inner scope (through | 1087 // that it might be accessed from the current or an inner scope (through |
| 1088 // an eval() call or a runtime with lookup), it must be allocated in the | 1088 // an eval() call or a runtime with lookup), it must be allocated in the |
| 1089 // context. | 1089 // context. |
| 1090 // | 1090 // |
| 1091 // Exceptions: temporary variables are never allocated in a context; | 1091 // Exceptions: temporary variables are never allocated in a context; |
| 1092 // catch-bound variables are always allocated in a context. | 1092 // catch-bound variables are always allocated in a context. |
| 1093 if (var->mode() == TEMPORARY) return false; | 1093 if (var->mode() == TEMPORARY) return false; |
| 1094 if (is_catch_scope() || is_block_scope()) return true; | 1094 if (is_catch_scope() || is_block_scope() || is_module_scope()) return true; |
| 1095 return var->has_forced_context_allocation() || | 1095 return var->has_forced_context_allocation() || |
| 1096 scope_calls_eval_ || | 1096 scope_calls_eval_ || |
| 1097 inner_scope_calls_eval_ || | 1097 inner_scope_calls_eval_ || |
| 1098 scope_contains_with_ || | 1098 scope_contains_with_ || |
| 1099 var->is_global(); | 1099 var->is_global(); |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 | 1102 |
| 1103 bool Scope::HasArgumentsParameter() { | 1103 bool Scope::HasArgumentsParameter() { |
| 1104 for (int i = 0; i < params_.length(); i++) { | 1104 for (int i = 0; i < params_.length(); i++) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 1228 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
| 1229 | 1229 |
| 1230 // Allocate variables for this scope. | 1230 // Allocate variables for this scope. |
| 1231 // Parameters must be allocated first, if any. | 1231 // Parameters must be allocated first, if any. |
| 1232 if (is_function_scope()) AllocateParameterLocals(); | 1232 if (is_function_scope()) AllocateParameterLocals(); |
| 1233 AllocateNonParameterLocals(); | 1233 AllocateNonParameterLocals(); |
| 1234 | 1234 |
| 1235 // Force allocation of a context for this scope if necessary. For a 'with' | 1235 // Force allocation of a context for this scope if necessary. For a 'with' |
| 1236 // scope and for a function scope that makes an 'eval' call we need a context, | 1236 // scope and for a function scope that makes an 'eval' call we need a context, |
| 1237 // even if no local variables were statically allocated in the scope. | 1237 // even if no local variables were statically allocated in the scope. |
| 1238 bool must_have_context = is_with_scope() || | 1238 // Likewise for modules. |
| 1239 bool must_have_context = is_with_scope() || is_module_scope() || |
| 1239 (is_function_scope() && calls_eval()); | 1240 (is_function_scope() && calls_eval()); |
| 1240 | 1241 |
| 1241 // If we didn't allocate any locals in the local context, then we only | 1242 // If we didn't allocate any locals in the local context, then we only |
| 1242 // need the minimal number of slots if we must have a context. | 1243 // need the minimal number of slots if we must have a context. |
| 1243 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) { | 1244 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) { |
| 1244 num_heap_slots_ = 0; | 1245 num_heap_slots_ = 0; |
| 1245 } | 1246 } |
| 1246 | 1247 |
| 1247 // Allocation done. | 1248 // Allocation done. |
| 1248 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1249 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
| 1249 } | 1250 } |
| 1250 | 1251 |
| 1251 | 1252 |
| 1252 int Scope::StackLocalCount() const { | 1253 int Scope::StackLocalCount() const { |
| 1253 return num_stack_slots() - | 1254 return num_stack_slots() - |
| 1254 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1255 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
| 1255 } | 1256 } |
| 1256 | 1257 |
| 1257 | 1258 |
| 1258 int Scope::ContextLocalCount() const { | 1259 int Scope::ContextLocalCount() const { |
| 1259 if (num_heap_slots() == 0) return 0; | 1260 if (num_heap_slots() == 0) return 0; |
| 1260 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1261 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1261 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1262 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1262 } | 1263 } |
| 1263 | 1264 |
| 1264 } } // namespace v8::internal | 1265 } } // namespace v8::internal |
| OLD | NEW |