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 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 if (decls_[j]->proxy()->raw_name() == name) { | 817 if (decls_[j]->proxy()->raw_name() == name) { |
| 818 return decls_[j]; | 818 return decls_[j]; |
| 819 } | 819 } |
| 820 } | 820 } |
| 821 DCHECK(false); | 821 DCHECK(false); |
| 822 } | 822 } |
| 823 } | 823 } |
| 824 return nullptr; | 824 return nullptr; |
| 825 } | 825 } |
| 826 | 826 |
| 827 Scope* Scope::GetOuterScopeWithContext() const { | |
| 828 Scope* scope = outer_scope(); | |
| 829 while (scope) { | |
|
marja
2016/08/29 07:53:00
Style nit: while (scope != nullptr) seems to be th
| |
| 830 // If we hit a SCRIPT_SCOPE that isn't backed by a scope_info, it's the | |
| 831 // SCRIPT_SCOPE corresponding to the native context. This also means, | |
| 832 // that the variables in that scope never get resolved (they should be all | |
| 833 // dynamic lookups), and so NeedsContext() incorrectly returns true. To | |
| 834 // avoid this, we bail out here. | |
| 835 if (scope->scope_type() == SCRIPT_SCOPE && scope->scope_info_.is_null()) { | |
|
Toon Verwaest
2016/08/26 12:07:01
How does this work for let variables in top-level
jochen (gone - plz use gerrit)
2016/08/26 13:14:11
For a top-level script, we'll invoke GetScopeInfo(
marja
2016/08/29 07:53:00
I don't get this answer at all..
| |
| 836 return nullptr; | |
| 837 } | |
| 838 if (scope->NeedsContext()) return scope; | |
|
Toon Verwaest
2016/08/26 12:04:37
I guess this happens for outer function scopes fro
jochen (gone - plz use gerrit)
2016/08/26 13:14:10
I guess in practice, this should be always true.
| |
| 839 scope = scope->outer_scope(); | |
| 840 } | |
| 841 return nullptr; | |
| 842 } | |
| 843 | |
| 827 void Scope::CollectVariables(ZoneList<Variable*>* stack_locals, | 844 void Scope::CollectVariables(ZoneList<Variable*>* stack_locals, |
| 828 ZoneList<Variable*>* context_locals, | 845 ZoneList<Variable*>* context_locals, |
| 829 ZoneList<Variable*>* context_globals) { | 846 ZoneList<Variable*>* context_globals) { |
| 830 // TODO(verwaest): Just pass out locals_ directly and walk it? | 847 // TODO(verwaest): Just pass out locals_ directly and walk it? |
| 831 DCHECK_NOT_NULL(stack_locals); | 848 DCHECK_NOT_NULL(stack_locals); |
| 832 DCHECK_NOT_NULL(context_locals); | 849 DCHECK_NOT_NULL(context_locals); |
| 833 DCHECK_NOT_NULL(context_globals); | 850 DCHECK_NOT_NULL(context_globals); |
| 834 | 851 |
| 835 for (int i = 0; i < locals_.length(); i++) { | 852 for (int i = 0; i < locals_.length(); i++) { |
| 836 Variable* var = locals_[i]; | 853 Variable* var = locals_[i]; |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1650 function != nullptr && function->IsContextSlot(); | 1667 function != nullptr && function->IsContextSlot(); |
| 1651 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1668 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1652 (is_function_var_in_context ? 1 : 0); | 1669 (is_function_var_in_context ? 1 : 0); |
| 1653 } | 1670 } |
| 1654 | 1671 |
| 1655 | 1672 |
| 1656 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1673 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1657 | 1674 |
| 1658 } // namespace internal | 1675 } // namespace internal |
| 1659 } // namespace v8 | 1676 } // namespace v8 |
| OLD | NEW |