| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 // We are not inside a local 'with' statement. | 601 // We are not inside a local 'with' statement. |
| 602 | 602 |
| 603 if (var == NULL) { | 603 if (var == NULL) { |
| 604 // We did not find the variable. We have a global variable | 604 // We did not find the variable. We have a global variable |
| 605 // if we are in the global scope (we know already that we | 605 // if we are in the global scope (we know already that we |
| 606 // are outside a 'with' statement) or if there is no way | 606 // are outside a 'with' statement) or if there is no way |
| 607 // that the variable might be introduced dynamically (through | 607 // that the variable might be introduced dynamically (through |
| 608 // a local or outer eval() call, or an outer 'with' statement), | 608 // a local or outer eval() call, or an outer 'with' statement), |
| 609 // or we don't know about the outer scope (because we are | 609 // or we don't know about the outer scope (because we are |
| 610 // in an eval scope). | 610 // in an eval scope). |
| 611 if (!is_global_scope() && | 611 if (is_global_scope() || |
| 612 (scope_inside_with_ || outer_scope_is_eval_scope_)) { | 612 !(scope_inside_with_ || outer_scope_is_eval_scope_ || |
| 613 // If we are inside a with statement or the code is executed | 613 scope_calls_eval_ || outer_scope_calls_eval_)) { |
| 614 // using eval, we give up and look up the variable at runtime. | |
| 615 var = NonLocal(proxy->name(), Variable::DYNAMIC); | |
| 616 | |
| 617 } else if (!is_global_scope() && | |
| 618 (scope_calls_eval_ || outer_scope_calls_eval_)) { | |
| 619 // If the code is not executed using eval and there are no | |
| 620 // with scopes, either we have a local or a global variable | |
| 621 // that might be shadowed by an eval-introduced variable. | |
| 622 if (invalidated_local != NULL) { | |
| 623 var = NonLocal(proxy->name(), Variable::DYNAMIC_LOCAL); | |
| 624 var->set_local_if_not_shadowed(invalidated_local); | |
| 625 } else { | |
| 626 var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL); | |
| 627 } | |
| 628 | |
| 629 } else { | |
| 630 // We must have a global variable. | 614 // We must have a global variable. |
| 631 ASSERT(global_scope != NULL); | 615 ASSERT(global_scope != NULL); |
| 632 var = new Variable(global_scope, proxy->name(), | 616 var = new Variable(global_scope, proxy->name(), |
| 633 Variable::DYNAMIC, true, false); | 617 Variable::DYNAMIC, true, false); |
| 634 // Ideally we simply rewrite these variables into property | 618 // Ideally we simply rewrite these variables into property |
| 635 // accesses. Unfortunately, we cannot do this here at the | 619 // accesses. Unfortunately, we cannot do this here at the |
| 636 // moment because then we can't differentiate between | 620 // moment because then we can't differentiate between |
| 637 // global variable ('x') and global property ('this.x') access. | 621 // global variable ('x') and global property ('this.x') access. |
| 638 // If 'x' doesn't exist, the former leads to an error, while the | 622 // If 'x' doesn't exist, the former leads to an error, while the |
| 639 // latter returns undefined. Sigh... | 623 // latter returns undefined. Sigh... |
| 640 // var->rewrite_ = new Property(new Literal(env_->global()), | 624 // var->rewrite_ = new Property(new Literal(env_->global()), |
| 641 // new Literal(proxy->name())); | 625 // new Literal(proxy->name())); |
| 626 |
| 627 } else if (scope_inside_with_) { |
| 628 // If we are inside a with statement we give up and look up |
| 629 // the variable at runtime. |
| 630 var = NonLocal(proxy->name(), Variable::DYNAMIC); |
| 631 |
| 632 } else if (invalidated_local != NULL) { |
| 633 // No with statements are involved and we found a local |
| 634 // variable that might be shadowed by eval introduced |
| 635 // variables. |
| 636 var = NonLocal(proxy->name(), Variable::DYNAMIC_LOCAL); |
| 637 var->set_local_if_not_shadowed(invalidated_local); |
| 638 |
| 639 } else if (outer_scope_is_eval_scope_) { |
| 640 // No with statements and we did not find a local and the code |
| 641 // is executed with a call to eval. We don't know anything |
| 642 // because we do not have information about the scopes |
| 643 // surrounding the eval call. |
| 644 var = NonLocal(proxy->name(), Variable::DYNAMIC); |
| 645 |
| 646 } else { |
| 647 // No with statements and we did not find a local and the code |
| 648 // is not executed with a call to eval. We know that this |
| 649 // variable is global unless it is shadowed by eval-introduced |
| 650 // variables. |
| 651 var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL); |
| 642 } | 652 } |
| 643 } | 653 } |
| 644 } | 654 } |
| 645 | 655 |
| 646 proxy->BindTo(var); | 656 proxy->BindTo(var); |
| 647 } | 657 } |
| 648 | 658 |
| 649 | 659 |
| 650 void Scope::ResolveVariablesRecursively(Scope* global_scope) { | 660 void Scope::ResolveVariablesRecursively(Scope* global_scope) { |
| 651 ASSERT(global_scope == NULL || global_scope->is_global_scope()); | 661 ASSERT(global_scope == NULL || global_scope->is_global_scope()); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 927 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
| 918 !must_have_local_context) { | 928 !must_have_local_context) { |
| 919 num_heap_slots_ = 0; | 929 num_heap_slots_ = 0; |
| 920 } | 930 } |
| 921 | 931 |
| 922 // Allocation done. | 932 // Allocation done. |
| 923 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 933 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
| 924 } | 934 } |
| 925 | 935 |
| 926 } } // namespace v8::internal | 936 } } // namespace v8::internal |
| OLD | NEW |