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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 Variable* result = variables_.Lookup(name); | 381 Variable* result = variables_.Lookup(name); |
| 382 if (result != NULL || scope_info_.is_null()) { | 382 if (result != NULL || scope_info_.is_null()) { |
| 383 return result; | 383 return result; |
| 384 } | 384 } |
| 385 // If we have a serialized scope info, we might find the variable there. | 385 // If we have a serialized scope info, we might find the variable there. |
| 386 // There should be no local slot with the given name. | 386 // There should be no local slot with the given name. |
| 387 ASSERT(scope_info_->StackSlotIndex(*name) < 0); | 387 ASSERT(scope_info_->StackSlotIndex(*name) < 0); |
| 388 | 388 |
| 389 // Check context slot lookup. | 389 // Check context slot lookup. |
| 390 VariableMode mode; | 390 VariableMode mode; |
| 391 Variable::Location location = Variable::CONTEXT; | |
| 391 InitializationFlag init_flag; | 392 InitializationFlag init_flag; |
| 392 int index = scope_info_->ContextSlotIndex(*name, &mode, &init_flag); | 393 int index = scope_info_->ContextSlotIndex(*name, &mode, &init_flag); |
| 393 if (index < 0) { | 394 if (index < 0) { |
| 394 // Check parameters. | 395 // Check parameters. |
| 395 mode = VAR; | |
| 396 init_flag = kCreatedInitialized; | |
| 397 index = scope_info_->ParameterIndex(*name); | 396 index = scope_info_->ParameterIndex(*name); |
| 398 if (index < 0) return NULL; | 397 if (index < 0) return NULL; |
| 398 | |
| 399 mode = DYNAMIC; | |
| 400 location = Variable::LOOKUP; | |
| 401 init_flag = kCreatedInitialized; | |
| 399 } | 402 } |
| 400 | 403 |
| 401 Variable* var = | 404 Variable* var = |
| 402 variables_.Declare(this, | 405 variables_.Declare(this, |
| 403 name, | 406 name, |
| 404 mode, | 407 mode, |
| 405 true, | 408 true, |
| 406 Variable::NORMAL, | 409 Variable::NORMAL, |
| 407 init_flag); | 410 init_flag); |
| 408 var->AllocateTo(Variable::CONTEXT, index); | 411 var->AllocateTo(location, index); |
| 409 return var; | 412 return var; |
| 410 } | 413 } |
| 411 | 414 |
| 412 | 415 |
| 413 Variable* Scope::LookupFunctionVar(Handle<String> name, | 416 Variable* Scope::LookupFunctionVar(Handle<String> name, |
| 414 AstNodeFactory<AstNullVisitor>* factory) { | 417 AstNodeFactory<AstNullVisitor>* factory) { |
| 415 if (function_ != NULL && function_->name().is_identical_to(name)) { | 418 if (function_ != NULL && function_->name().is_identical_to(name)) { |
| 416 return function_->var(); | 419 return function_->var(); |
| 417 } else if (!scope_info_.is_null()) { | 420 } else if (!scope_info_.is_null()) { |
| 418 // If we are backed by a scope info, try to lookup the variable there. | 421 // If we are backed by a scope info, try to lookup the variable there. |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 | 945 |
| 943 // Otherwise, try to resolve the variable. | 946 // Otherwise, try to resolve the variable. |
| 944 BindingKind binding_kind; | 947 BindingKind binding_kind; |
| 945 Variable* var = LookupRecursive(proxy->name(), &binding_kind, factory); | 948 Variable* var = LookupRecursive(proxy->name(), &binding_kind, factory); |
| 946 switch (binding_kind) { | 949 switch (binding_kind) { |
| 947 case BOUND: | 950 case BOUND: |
| 948 // We found a variable binding. | 951 // We found a variable binding. |
| 949 break; | 952 break; |
| 950 | 953 |
| 951 case BOUND_EVAL_SHADOWED: | 954 case BOUND_EVAL_SHADOWED: |
| 952 // We found a variable variable binding that might be shadowed | 955 // We found a variable variable binding that might be shadowed |
|
Kevin Millikin (Google)
2012/04/12 15:43:15
Only one "variable".
| |
| 953 // by 'eval' introduced variable bindings. | 956 // by 'eval' introduced variable bindings. |
| 954 if (var->is_global()) { | 957 if (var->is_global()) { |
| 955 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL); | 958 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL); |
| 959 } else if (var->is_dynamic()) { | |
|
Kevin Millikin (Google)
2012/04/12 15:43:15
This is kind of subtle and doesn't jive with the c
| |
| 960 var = NonLocal(proxy->name(), DYNAMIC); | |
| 956 } else { | 961 } else { |
| 957 Variable* invalidated = var; | 962 Variable* invalidated = var; |
| 958 var = NonLocal(proxy->name(), DYNAMIC_LOCAL); | 963 var = NonLocal(proxy->name(), DYNAMIC_LOCAL); |
| 959 var->set_local_if_not_shadowed(invalidated); | 964 var->set_local_if_not_shadowed(invalidated); |
| 960 } | 965 } |
| 961 break; | 966 break; |
| 962 | 967 |
| 963 case UNBOUND: | 968 case UNBOUND: |
| 964 // No binding has been found. Declare a variable in global scope. | 969 // No binding has been found. Declare a variable in global scope. |
| 965 var = info->global_scope()->DeclareGlobal(proxy->name()); | 970 var = info->global_scope()->DeclareGlobal(proxy->name()); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 } | 1255 } |
| 1251 | 1256 |
| 1252 | 1257 |
| 1253 int Scope::ContextLocalCount() const { | 1258 int Scope::ContextLocalCount() const { |
| 1254 if (num_heap_slots() == 0) return 0; | 1259 if (num_heap_slots() == 0) return 0; |
| 1255 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1260 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1256 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); | 1261 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); |
| 1257 } | 1262 } |
| 1258 | 1263 |
| 1259 } } // namespace v8::internal | 1264 } } // namespace v8::internal |
| OLD | NEW |