OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 if (is_catch_scope()) { | 297 if (is_catch_scope()) { |
298 ASSERT(outer_scope() != NULL); | 298 ASSERT(outer_scope() != NULL); |
299 receiver_ = outer_scope()->receiver(); | 299 receiver_ = outer_scope()->receiver(); |
300 } else { | 300 } else { |
301 Variable* var = | 301 Variable* var = |
302 variables_.Declare(this, | 302 variables_.Declare(this, |
303 isolate_->factory()->this_symbol(), | 303 isolate_->factory()->this_symbol(), |
304 Variable::VAR, | 304 Variable::VAR, |
305 false, | 305 false, |
306 Variable::THIS); | 306 Variable::THIS); |
307 var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::PARAMETER, -1)); | 307 var->set_rewrite(new(isolate_->zone()) Slot( |
| 308 isolate_, var, Slot::PARAMETER, -1)); |
308 receiver_ = var; | 309 receiver_ = var; |
309 } | 310 } |
310 | 311 |
311 if (is_function_scope()) { | 312 if (is_function_scope()) { |
312 // Declare 'arguments' variable which exists in all functions. | 313 // Declare 'arguments' variable which exists in all functions. |
313 // Note that it might never be accessed, in which case it won't be | 314 // Note that it might never be accessed, in which case it won't be |
314 // allocated during variable allocation. | 315 // allocated during variable allocation. |
315 variables_.Declare(this, | 316 variables_.Declare(this, |
316 isolate_->factory()->arguments_symbol(), | 317 isolate_->factory()->arguments_symbol(), |
317 Variable::VAR, | 318 Variable::VAR, |
(...skipping 25 matching lines...) Expand all Loading... |
343 index = scope_info_->ParameterIndex(*name); | 344 index = scope_info_->ParameterIndex(*name); |
344 if (index < 0) { | 345 if (index < 0) { |
345 // Check the function name. | 346 // Check the function name. |
346 index = scope_info_->FunctionContextSlotIndex(*name); | 347 index = scope_info_->FunctionContextSlotIndex(*name); |
347 if (index < 0) return NULL; | 348 if (index < 0) return NULL; |
348 } | 349 } |
349 } | 350 } |
350 | 351 |
351 Variable* var = | 352 Variable* var = |
352 variables_.Declare(this, name, mode, true, Variable::NORMAL); | 353 variables_.Declare(this, name, mode, true, Variable::NORMAL); |
353 var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::CONTEXT, index)); | 354 var->set_rewrite( |
| 355 new(isolate_->zone()) Slot(isolate_, var, Slot::CONTEXT, index)); |
354 return var; | 356 return var; |
355 } | 357 } |
356 | 358 |
357 | 359 |
358 Variable* Scope::Lookup(Handle<String> name) { | 360 Variable* Scope::Lookup(Handle<String> name) { |
359 for (Scope* scope = this; | 361 for (Scope* scope = this; |
360 scope != NULL; | 362 scope != NULL; |
361 scope = scope->outer_scope()) { | 363 scope = scope->outer_scope()) { |
362 Variable* var = scope->LocalLookup(name); | 364 Variable* var = scope->LocalLookup(name); |
363 if (var != NULL) return var; | 365 if (var != NULL) return var; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 402 } |
401 | 403 |
402 | 404 |
403 VariableProxy* Scope::NewUnresolved(Handle<String> name, | 405 VariableProxy* Scope::NewUnresolved(Handle<String> name, |
404 bool inside_with, | 406 bool inside_with, |
405 int position) { | 407 int position) { |
406 // Note that we must not share the unresolved variables with | 408 // Note that we must not share the unresolved variables with |
407 // the same name because they may be removed selectively via | 409 // the same name because they may be removed selectively via |
408 // RemoveUnresolved(). | 410 // RemoveUnresolved(). |
409 ASSERT(!already_resolved()); | 411 ASSERT(!already_resolved()); |
410 VariableProxy* proxy = | 412 VariableProxy* proxy = new(isolate_->zone()) VariableProxy( |
411 new(isolate_->zone()) VariableProxy(name, false, inside_with, position); | 413 isolate_, name, false, inside_with, position); |
412 unresolved_.Add(proxy); | 414 unresolved_.Add(proxy); |
413 return proxy; | 415 return proxy; |
414 } | 416 } |
415 | 417 |
416 | 418 |
417 void Scope::RemoveUnresolved(VariableProxy* var) { | 419 void Scope::RemoveUnresolved(VariableProxy* var) { |
418 // Most likely (always?) any variable we want to remove | 420 // Most likely (always?) any variable we want to remove |
419 // was just added before, so we search backwards. | 421 // was just added before, so we search backwards. |
420 for (int i = unresolved_.length(); i-- > 0;) { | 422 for (int i = unresolved_.length(); i-- > 0;) { |
421 if (unresolved_[i] == var) { | 423 if (unresolved_[i] == var) { |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 | 703 |
702 | 704 |
703 Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) { | 705 Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) { |
704 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart(); | 706 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart(); |
705 VariableMap* map = dynamics_->GetMap(mode); | 707 VariableMap* map = dynamics_->GetMap(mode); |
706 Variable* var = map->Lookup(name); | 708 Variable* var = map->Lookup(name); |
707 if (var == NULL) { | 709 if (var == NULL) { |
708 // Declare a new non-local. | 710 // Declare a new non-local. |
709 var = map->Declare(NULL, name, mode, true, Variable::NORMAL); | 711 var = map->Declare(NULL, name, mode, true, Variable::NORMAL); |
710 // Allocate it by giving it a dynamic lookup. | 712 // Allocate it by giving it a dynamic lookup. |
711 var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::LOOKUP, -1)); | 713 var->set_rewrite( |
| 714 new(isolate_->zone()) Slot(isolate_, var, Slot::LOOKUP, -1)); |
712 } | 715 } |
713 return var; | 716 return var; |
714 } | 717 } |
715 | 718 |
716 | 719 |
717 // Lookup a variable starting with this scope. The result is either | 720 // Lookup a variable starting with this scope. The result is either |
718 // the statically resolved variable belonging to an outer scope, or | 721 // the statically resolved variable belonging to an outer scope, or |
719 // NULL. It may be NULL because a) we couldn't find a variable, or b) | 722 // NULL. It may be NULL because a) we couldn't find a variable, or b) |
720 // because the variable is just a guess (and may be shadowed by | 723 // because the variable is just a guess (and may be shadowed by |
721 // another variable that is introduced dynamically via an 'eval' call | 724 // another variable that is introduced dynamically via an 'eval' call |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 if (params_[i]->name().is_identical_to( | 960 if (params_[i]->name().is_identical_to( |
958 isolate_->factory()->arguments_symbol())) { | 961 isolate_->factory()->arguments_symbol())) { |
959 return true; | 962 return true; |
960 } | 963 } |
961 } | 964 } |
962 return false; | 965 return false; |
963 } | 966 } |
964 | 967 |
965 | 968 |
966 void Scope::AllocateStackSlot(Variable* var) { | 969 void Scope::AllocateStackSlot(Variable* var) { |
967 var->set_rewrite( | 970 var->set_rewrite(new(isolate_->zone()) Slot( |
968 new(isolate_->zone()) Slot(var, Slot::LOCAL, num_stack_slots_++)); | 971 isolate_, var, Slot::LOCAL, num_stack_slots_++)); |
969 } | 972 } |
970 | 973 |
971 | 974 |
972 void Scope::AllocateHeapSlot(Variable* var) { | 975 void Scope::AllocateHeapSlot(Variable* var) { |
973 var->set_rewrite( | 976 var->set_rewrite(new(isolate_->zone()) Slot( |
974 new(isolate_->zone()) Slot(var, Slot::CONTEXT, num_heap_slots_++)); | 977 isolate_, var, Slot::CONTEXT, num_heap_slots_++)); |
975 } | 978 } |
976 | 979 |
977 | 980 |
978 void Scope::AllocateParameterLocals() { | 981 void Scope::AllocateParameterLocals() { |
979 ASSERT(is_function_scope()); | 982 ASSERT(is_function_scope()); |
980 Variable* arguments = LocalLookup(isolate_->factory()->arguments_symbol()); | 983 Variable* arguments = LocalLookup(isolate_->factory()->arguments_symbol()); |
981 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly | 984 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly |
982 | 985 |
983 bool uses_nonstrict_arguments = false; | 986 bool uses_nonstrict_arguments = false; |
984 | 987 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 | 1020 |
1018 if (MustAllocate(var)) { | 1021 if (MustAllocate(var)) { |
1019 if (MustAllocateInContext(var)) { | 1022 if (MustAllocateInContext(var)) { |
1020 ASSERT(var->rewrite() == NULL || var->IsContextSlot()); | 1023 ASSERT(var->rewrite() == NULL || var->IsContextSlot()); |
1021 if (var->rewrite() == NULL) { | 1024 if (var->rewrite() == NULL) { |
1022 AllocateHeapSlot(var); | 1025 AllocateHeapSlot(var); |
1023 } | 1026 } |
1024 } else { | 1027 } else { |
1025 ASSERT(var->rewrite() == NULL || var->IsParameter()); | 1028 ASSERT(var->rewrite() == NULL || var->IsParameter()); |
1026 if (var->rewrite() == NULL) { | 1029 if (var->rewrite() == NULL) { |
1027 var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::PARAMETER, i)); | 1030 var->set_rewrite( |
| 1031 new(isolate_->zone()) Slot(isolate_, var, Slot::PARAMETER, i)); |
1028 } | 1032 } |
1029 } | 1033 } |
1030 } | 1034 } |
1031 } | 1035 } |
1032 } | 1036 } |
1033 | 1037 |
1034 | 1038 |
1035 void Scope::AllocateNonParameterLocal(Variable* var) { | 1039 void Scope::AllocateNonParameterLocal(Variable* var) { |
1036 ASSERT(var->scope() == this); | 1040 ASSERT(var->scope() == this); |
1037 ASSERT(var->rewrite() == NULL || | 1041 ASSERT(var->rewrite() == NULL || |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1109 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
1106 !must_have_local_context) { | 1110 !must_have_local_context) { |
1107 num_heap_slots_ = 0; | 1111 num_heap_slots_ = 0; |
1108 } | 1112 } |
1109 | 1113 |
1110 // Allocation done. | 1114 // Allocation done. |
1111 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1115 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
1112 } | 1116 } |
1113 | 1117 |
1114 } } // namespace v8::internal | 1118 } } // namespace v8::internal |
OLD | NEW |