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/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 // We are compiling one of three cases: | 529 // We are compiling one of three cases: |
530 // 1) top-level code, | 530 // 1) top-level code, |
531 // 2) a function/eval/module on the top-level | 531 // 2) a function/eval/module on the top-level |
532 // 3) a function/eval in a scope that was already resolved. | 532 // 3) a function/eval in a scope that was already resolved. |
533 DCHECK(scope->scope_type() == SCRIPT_SCOPE || | 533 DCHECK(scope->scope_type() == SCRIPT_SCOPE || |
534 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || | 534 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || |
535 scope->outer_scope()->already_resolved_); | 535 scope->outer_scope()->already_resolved_); |
536 | 536 |
537 scope->AllocateVariables(info, mode); | 537 scope->AllocateVariables(info, mode); |
538 | 538 |
| 539 // Ensuring that the outer script scope has a scope info avoids having |
| 540 // special case for native contexts vs other contexts. |
| 541 if (info->script_scope()->scope_info_.is_null()) { |
| 542 info->script_scope()->scope_info_ = |
| 543 handle(ScopeInfo::Empty(info->isolate())); |
| 544 } |
| 545 |
539 #ifdef DEBUG | 546 #ifdef DEBUG |
540 if (info->script_is_native() ? FLAG_print_builtin_scopes | 547 if (info->script_is_native() ? FLAG_print_builtin_scopes |
541 : FLAG_print_scopes) { | 548 : FLAG_print_scopes) { |
542 scope->Print(); | 549 scope->Print(); |
543 } | 550 } |
544 scope->CheckScopePositions(); | 551 scope->CheckScopePositions(); |
545 scope->CheckZones(); | 552 scope->CheckZones(); |
546 #endif | 553 #endif |
547 } | 554 } |
548 | 555 |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 DeclarationScope* Scope::GetReceiverScope() { | 1143 DeclarationScope* Scope::GetReceiverScope() { |
1137 Scope* scope = this; | 1144 Scope* scope = this; |
1138 while (!scope->is_script_scope() && | 1145 while (!scope->is_script_scope() && |
1139 (!scope->is_function_scope() || | 1146 (!scope->is_function_scope() || |
1140 scope->AsDeclarationScope()->is_arrow_scope())) { | 1147 scope->AsDeclarationScope()->is_arrow_scope())) { |
1141 scope = scope->outer_scope(); | 1148 scope = scope->outer_scope(); |
1142 } | 1149 } |
1143 return scope->AsDeclarationScope(); | 1150 return scope->AsDeclarationScope(); |
1144 } | 1151 } |
1145 | 1152 |
| 1153 Scope* Scope::GetOuterScopeWithContext() { |
| 1154 Scope* scope = outer_scope_; |
| 1155 while (scope && !scope->NeedsContext()) { |
| 1156 scope = scope->outer_scope(); |
| 1157 } |
| 1158 return scope; |
| 1159 } |
| 1160 |
1146 Handle<StringSet> DeclarationScope::CollectNonLocals( | 1161 Handle<StringSet> DeclarationScope::CollectNonLocals( |
1147 ParseInfo* info, Handle<StringSet> non_locals) { | 1162 ParseInfo* info, Handle<StringSet> non_locals) { |
1148 VariableProxy* free_variables = FetchFreeVariables(this, info); | 1163 VariableProxy* free_variables = FetchFreeVariables(this, info); |
1149 for (VariableProxy* proxy = free_variables; proxy != nullptr; | 1164 for (VariableProxy* proxy = free_variables; proxy != nullptr; |
1150 proxy = proxy->next_unresolved()) { | 1165 proxy = proxy->next_unresolved()) { |
1151 non_locals = StringSet::Add(non_locals, proxy->name()); | 1166 non_locals = StringSet::Add(non_locals, proxy->name()); |
1152 } | 1167 } |
1153 return non_locals; | 1168 return non_locals; |
1154 } | 1169 } |
1155 | 1170 |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 Variable* function = | 1821 Variable* function = |
1807 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1822 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
1808 bool is_function_var_in_context = | 1823 bool is_function_var_in_context = |
1809 function != nullptr && function->IsContextSlot(); | 1824 function != nullptr && function->IsContextSlot(); |
1810 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1825 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1811 (is_function_var_in_context ? 1 : 0); | 1826 (is_function_var_in_context ? 1 : 0); |
1812 } | 1827 } |
1813 | 1828 |
1814 } // namespace internal | 1829 } // namespace internal |
1815 } // namespace v8 | 1830 } // namespace v8 |
OLD | NEW |