Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 params_(4), | 147 params_(4), |
| 148 unresolved_(16), | 148 unresolved_(16), |
| 149 decls_(4) { | 149 decls_(4) { |
| 150 ASSERT(scope_info != NULL); | 150 ASSERT(scope_info != NULL); |
| 151 SetDefaults(FUNCTION_SCOPE, inner_scope->outer_scope(), scope_info); | 151 SetDefaults(FUNCTION_SCOPE, inner_scope->outer_scope(), scope_info); |
| 152 ASSERT(resolved()); | 152 ASSERT(resolved()); |
| 153 InsertAfterScope(inner_scope); | 153 InsertAfterScope(inner_scope); |
| 154 if (scope_info->HasHeapAllocatedLocals()) { | 154 if (scope_info->HasHeapAllocatedLocals()) { |
| 155 num_heap_slots_ = scope_info_->NumberOfContextSlots(); | 155 num_heap_slots_ = scope_info_->NumberOfContextSlots(); |
| 156 } | 156 } |
| 157 | |
| 158 // arguments shadow would be saved to the list of context slots | |
| 159 // only if inner scopes access some parameters. Prepare to | |
| 160 // this situation by allocating arguments_shadow_ object | |
| 161 // and thread access to this scope's parameters via arguments shadow. | |
|
Kevin Millikin (Chromium)
2011/01/19 07:39:57
Suggested rewording, something like:
This scope's
antonm
2011/01/19 08:18:19
Done.
| |
| 162 Variable::Mode mode; | |
| 163 int arguments_shadow_index = | |
| 164 scope_info_->ContextSlotIndex(Heap::arguments_shadow_symbol(), &mode); | |
| 165 if (arguments_shadow_index >= 0) { | |
| 166 ASSERT(mode == Variable::INTERNAL); | |
| 167 arguments_shadow_ = new Variable(this, | |
| 168 Factory::arguments_shadow_symbol(), | |
| 169 Variable::INTERNAL, | |
| 170 true, | |
| 171 Variable::ARGUMENTS); | |
| 172 arguments_shadow_->set_rewrite( | |
| 173 new Slot(arguments_shadow_, Slot::CONTEXT, arguments_shadow_index)); | |
| 174 arguments_shadow_->set_is_used(true); | |
| 175 } | |
| 157 } | 176 } |
| 158 | 177 |
| 159 | 178 |
| 160 | 179 |
| 161 bool Scope::Analyze(CompilationInfo* info) { | 180 bool Scope::Analyze(CompilationInfo* info) { |
| 162 ASSERT(info->function() != NULL); | 181 ASSERT(info->function() != NULL); |
| 163 Scope* top = info->function()->scope(); | 182 Scope* top = info->function()->scope(); |
| 164 | 183 |
| 165 // If we have a serialized scope info, reuse it. | 184 // If we have a serialized scope info, reuse it. |
| 166 if (!info->closure().is_null()) { | 185 if (!info->closure().is_null()) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 251 |
| 233 | 252 |
| 234 Variable* Scope::LocalLookup(Handle<String> name) { | 253 Variable* Scope::LocalLookup(Handle<String> name) { |
| 235 Variable* result = variables_.Lookup(name); | 254 Variable* result = variables_.Lookup(name); |
| 236 if (result != NULL || !resolved()) { | 255 if (result != NULL || !resolved()) { |
| 237 return result; | 256 return result; |
| 238 } | 257 } |
| 239 // If the scope is resolved, we can find a variable in serialized scope info. | 258 // If the scope is resolved, we can find a variable in serialized scope info. |
| 240 | 259 |
| 241 // We should never lookup 'arguments' in this scope | 260 // We should never lookup 'arguments' in this scope |
| 242 // as it is impllicitly present in any scope. | 261 // as it is impllicitly present in any scope. |
|
Kevin Millikin (Chromium)
2011/01/19 07:39:57
Could you fix the spelling of "implicitly"?
antonm
2011/01/19 08:18:19
Done.
| |
| 243 ASSERT(*name != *Factory::arguments_symbol()); | 262 ASSERT(*name != *Factory::arguments_symbol()); |
| 244 | 263 |
| 245 // Check context slot lookup. | 264 // Check context slot lookup. |
| 246 Variable::Mode mode; | 265 Variable::Mode mode; |
| 247 int index = scope_info_->ContextSlotIndex(*name, &mode); | 266 int index = scope_info_->ContextSlotIndex(*name, &mode); |
| 248 if (index < 0) { | 267 if (index >= 0) { |
| 249 return NULL; | 268 // Check that there is no local slot with the given name. |
| 269 ASSERT(scope_info_->StackSlotIndex(*name) < 0); | |
|
Kevin Millikin (Chromium)
2011/01/19 07:39:57
This assert could be lifted higher (up to the prev
antonm
2011/01/19 08:18:19
Done.
| |
| 270 Variable* var = | |
| 271 variables_.Declare(this, name, mode, true, Variable::NORMAL); | |
| 272 var->set_rewrite(new Slot(var, Slot::CONTEXT, index)); | |
| 273 return var; | |
| 250 } | 274 } |
| 251 | 275 |
| 252 // Check that there is no local slot with the given name. | 276 index = scope_info_->ParameterIndex(*name); |
| 253 ASSERT(scope_info_->StackSlotIndex(*name) < 0); | 277 if (index >= 0) { |
| 254 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL); | 278 // ".arguments" must be present in context slots. |
| 255 var->set_rewrite(new Slot(var, Slot::CONTEXT, index)); | 279 ASSERT(arguments_shadow_ != NULL); |
| 256 return var; | 280 // Check that there is no local slot with the given name. |
| 281 ASSERT(scope_info_->StackSlotIndex(*name) < 0); | |
| 282 Variable* var = | |
| 283 variables_.Declare(this, name, Variable::VAR, true, Variable::NORMAL); | |
| 284 Property* rewrite = | |
| 285 new Property(new VariableProxy(arguments_shadow_), | |
| 286 new Literal(Handle<Object>(Smi::FromInt(index))), | |
|
Kevin Millikin (Chromium)
2011/01/19 07:39:57
Indentation is a bit off here.
antonm
2011/01/19 08:18:19
Done.
| |
| 287 RelocInfo::kNoPosition, | |
| 288 Property::SYNTHETIC); | |
| 289 rewrite->set_is_arguments_access(true); | |
| 290 var->set_rewrite(rewrite); | |
| 291 return var; | |
| 292 } | |
| 293 | |
| 294 index = scope_info_->FunctionContextSlotIndex(*name); | |
| 295 if (index >= 0) { | |
| 296 // Check that there is no local slot with the given name. | |
| 297 ASSERT(scope_info_->StackSlotIndex(*name) < 0); | |
| 298 Variable* var = | |
| 299 variables_.Declare(this, name, mode, true, Variable::NORMAL); | |
|
Kevin Millikin (Chromium)
2011/01/19 07:39:57
Will this be the right mode?
antonm
2011/01/19 08:18:19
Oops, thanks a lot for spotting this. Now passing
| |
| 300 var->set_rewrite(new Slot(var, Slot::CONTEXT, index)); | |
| 301 return var; | |
| 302 } | |
| 303 | |
| 304 return NULL; | |
| 257 } | 305 } |
| 258 | 306 |
| 259 | 307 |
| 260 Variable* Scope::Lookup(Handle<String> name) { | 308 Variable* Scope::Lookup(Handle<String> name) { |
| 261 for (Scope* scope = this; | 309 for (Scope* scope = this; |
| 262 scope != NULL; | 310 scope != NULL; |
| 263 scope = scope->outer_scope()) { | 311 scope = scope->outer_scope()) { |
| 264 Variable* var = scope->LocalLookup(name); | 312 Variable* var = scope->LocalLookup(name); |
| 265 if (var != NULL) return var; | 313 if (var != NULL) return var; |
| 266 } | 314 } |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1057 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
| 1010 !must_have_local_context) { | 1058 !must_have_local_context) { |
| 1011 num_heap_slots_ = 0; | 1059 num_heap_slots_ = 0; |
| 1012 } | 1060 } |
| 1013 | 1061 |
| 1014 // Allocation done. | 1062 // Allocation done. |
| 1015 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1063 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
| 1016 } | 1064 } |
| 1017 | 1065 |
| 1018 } } // namespace v8::internal | 1066 } } // namespace v8::internal |
| OLD | NEW |