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