| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 : DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) { | 169 : DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) { |
| 170 Zone* zone = avfactory->zone(); | 170 Zone* zone = avfactory->zone(); |
| 171 ModuleInfo* module_info = scope_info->ModuleDescriptorInfo(); | 171 ModuleInfo* module_info = scope_info->ModuleDescriptorInfo(); |
| 172 | 172 |
| 173 set_language_mode(STRICT); | 173 set_language_mode(STRICT); |
| 174 module_descriptor_ = new (zone) ModuleDescriptor(zone); | 174 module_descriptor_ = new (zone) ModuleDescriptor(zone); |
| 175 | 175 |
| 176 // Deserialize special exports. | 176 // Deserialize special exports. |
| 177 Handle<FixedArray> special_exports = handle(module_info->special_exports()); | 177 Handle<FixedArray> special_exports = handle(module_info->special_exports()); |
| 178 for (int i = 0, n = special_exports->length(); i < n; ++i) { | 178 for (int i = 0, n = special_exports->length(); i < n; ++i) { |
| 179 Handle<FixedArray> serialized_entry( | 179 Handle<ModuleInfoEntry> serialized_entry( |
| 180 FixedArray::cast(special_exports->get(i)), isolate); | 180 ModuleInfoEntry::cast(special_exports->get(i)), isolate); |
| 181 module_descriptor_->AddSpecialExport( | 181 module_descriptor_->AddSpecialExport( |
| 182 ModuleDescriptor::Entry::Deserialize(isolate, avfactory, | 182 ModuleDescriptor::Entry::Deserialize(isolate, avfactory, |
| 183 serialized_entry), | 183 serialized_entry), |
| 184 avfactory->zone()); | 184 avfactory->zone()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Deserialize regular exports. | 187 // Deserialize regular exports. |
| 188 Handle<FixedArray> regular_exports = handle(module_info->regular_exports()); | 188 Handle<FixedArray> regular_exports = handle(module_info->regular_exports()); |
| 189 for (int i = 0, n = regular_exports->length(); i < n; ++i) { | 189 for (int i = 0, n = regular_exports->length(); i < n; ++i) { |
| 190 Handle<FixedArray> serialized_entry( | 190 Handle<ModuleInfoEntry> serialized_entry( |
| 191 FixedArray::cast(regular_exports->get(i)), isolate); | 191 ModuleInfoEntry::cast(regular_exports->get(i)), isolate); |
| 192 module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize( | 192 module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize( |
| 193 isolate, avfactory, serialized_entry)); | 193 isolate, avfactory, serialized_entry)); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) | 197 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) |
| 198 : zone_(zone), | 198 : zone_(zone), |
| 199 outer_scope_(nullptr), | 199 outer_scope_(nullptr), |
| 200 variables_(zone), | 200 variables_(zone), |
| 201 locals_(0, zone), | 201 locals_(0, zone), |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 DeclarationScope* scope = info->literal()->scope(); | 454 DeclarationScope* scope = info->literal()->scope(); |
| 455 | 455 |
| 456 // We are compiling one of three cases: | 456 // We are compiling one of three cases: |
| 457 // 1) top-level code, | 457 // 1) top-level code, |
| 458 // 2) a function/eval/module on the top-level | 458 // 2) a function/eval/module on the top-level |
| 459 // 3) a function/eval in a scope that was already resolved. | 459 // 3) a function/eval in a scope that was already resolved. |
| 460 DCHECK(scope->scope_type() == SCRIPT_SCOPE || | 460 DCHECK(scope->scope_type() == SCRIPT_SCOPE || |
| 461 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || | 461 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || |
| 462 scope->outer_scope()->already_resolved_); | 462 scope->outer_scope()->already_resolved_); |
| 463 | 463 |
| 464 // For modules, we want to start variable allocation at the surrounding script | |
| 465 // scope. | |
| 466 if (scope->is_module_scope()) { | |
| 467 scope = scope->outer_scope()->AsDeclarationScope(); | |
| 468 } | |
| 469 | |
| 470 scope->AllocateVariables(info, mode); | 464 scope->AllocateVariables(info, mode); |
| 471 | 465 |
| 472 #ifdef DEBUG | 466 #ifdef DEBUG |
| 473 if (info->script_is_native() ? FLAG_print_builtin_scopes | 467 if (info->script_is_native() ? FLAG_print_builtin_scopes |
| 474 : FLAG_print_scopes) { | 468 : FLAG_print_scopes) { |
| 475 scope->Print(); | 469 scope->Print(); |
| 476 } | 470 } |
| 477 scope->CheckScopePositions(); | 471 scope->CheckScopePositions(); |
| 478 scope->CheckZones(); | 472 scope->CheckZones(); |
| 479 #endif | 473 #endif |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 Variable* var = scope->LookupLocal(name); | 694 Variable* var = scope->LookupLocal(name); |
| 701 if (var != NULL) return var; | 695 if (var != NULL) return var; |
| 702 } | 696 } |
| 703 return NULL; | 697 return NULL; |
| 704 } | 698 } |
| 705 | 699 |
| 706 Variable* DeclarationScope::DeclareParameter( | 700 Variable* DeclarationScope::DeclareParameter( |
| 707 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, | 701 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, |
| 708 bool* is_duplicate, AstValueFactory* ast_value_factory) { | 702 bool* is_duplicate, AstValueFactory* ast_value_factory) { |
| 709 DCHECK(!already_resolved_); | 703 DCHECK(!already_resolved_); |
| 710 DCHECK(is_function_scope()); | 704 DCHECK(is_function_scope() || is_module_scope()); |
| 711 DCHECK(!has_rest_); | 705 DCHECK(!has_rest_); |
| 712 DCHECK(!is_optional || !is_rest); | 706 DCHECK(!is_optional || !is_rest); |
| 713 Variable* var; | 707 Variable* var; |
| 714 if (mode == TEMPORARY) { | 708 if (mode == TEMPORARY) { |
| 715 var = NewTemporary(name); | 709 var = NewTemporary(name); |
| 716 } else { | 710 } else { |
| 717 var = Declare(zone(), this, name, mode, Variable::NORMAL, | 711 var = Declare(zone(), this, name, mode, Variable::NORMAL, |
| 718 kCreatedInitialized); | 712 kCreatedInitialized); |
| 719 // TODO(wingo): Avoid O(n^2) check. | 713 // TODO(wingo): Avoid O(n^2) check. |
| 720 *is_duplicate = IsDeclaredParameter(name); | 714 *is_duplicate = IsDeclaredParameter(name); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 } | 1002 } |
| 1009 | 1003 |
| 1010 DeclarationScope* Scope::GetClosureScope() { | 1004 DeclarationScope* Scope::GetClosureScope() { |
| 1011 Scope* scope = this; | 1005 Scope* scope = this; |
| 1012 while (!scope->is_declaration_scope() || scope->is_block_scope()) { | 1006 while (!scope->is_declaration_scope() || scope->is_block_scope()) { |
| 1013 scope = scope->outer_scope(); | 1007 scope = scope->outer_scope(); |
| 1014 } | 1008 } |
| 1015 return scope->AsDeclarationScope(); | 1009 return scope->AsDeclarationScope(); |
| 1016 } | 1010 } |
| 1017 | 1011 |
| 1012 ModuleScope* Scope::GetModuleScope() { |
| 1013 Scope* scope = this; |
| 1014 DCHECK(!scope->is_script_scope()); |
| 1015 while (!scope->is_module_scope()) { |
| 1016 scope = scope->outer_scope(); |
| 1017 DCHECK_NOT_NULL(scope); |
| 1018 } |
| 1019 return scope->AsModuleScope(); |
| 1020 } |
| 1021 |
| 1018 DeclarationScope* Scope::GetReceiverScope() { | 1022 DeclarationScope* Scope::GetReceiverScope() { |
| 1019 Scope* scope = this; | 1023 Scope* scope = this; |
| 1020 while (!scope->is_script_scope() && | 1024 while (!scope->is_script_scope() && |
| 1021 (!scope->is_function_scope() || | 1025 (!scope->is_function_scope() || |
| 1022 scope->AsDeclarationScope()->is_arrow_scope())) { | 1026 scope->AsDeclarationScope()->is_arrow_scope())) { |
| 1023 scope = scope->outer_scope(); | 1027 scope = scope->outer_scope(); |
| 1024 } | 1028 } |
| 1025 return scope->AsDeclarationScope(); | 1029 return scope->AsDeclarationScope(); |
| 1026 } | 1030 } |
| 1027 | 1031 |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1696 Variable* function = | 1700 Variable* function = |
| 1697 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1701 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
| 1698 bool is_function_var_in_context = | 1702 bool is_function_var_in_context = |
| 1699 function != nullptr && function->IsContextSlot(); | 1703 function != nullptr && function->IsContextSlot(); |
| 1700 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1704 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1701 (is_function_var_in_context ? 1 : 0); | 1705 (is_function_var_in_context ? 1 : 0); |
| 1702 } | 1706 } |
| 1703 | 1707 |
| 1704 } // namespace internal | 1708 } // namespace internal |
| 1705 } // namespace v8 | 1709 } // namespace v8 |
| OLD | NEW |