OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/ast/context-slot-cache.h" | 7 #include "src/ast/context-slot-cache.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/ast/variables.h" | 9 #include "src/ast/variables.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 DCHECK_EQ(scope_type(), MODULE_SCOPE); | 640 DCHECK_EQ(scope_type(), MODULE_SCOPE); |
641 DCHECK(name->IsInternalizedString()); | 641 DCHECK(name->IsInternalizedString()); |
642 DCHECK_NOT_NULL(mode); | 642 DCHECK_NOT_NULL(mode); |
643 DCHECK_NOT_NULL(init_flag); | 643 DCHECK_NOT_NULL(init_flag); |
644 DCHECK_NOT_NULL(maybe_assigned_flag); | 644 DCHECK_NOT_NULL(maybe_assigned_flag); |
645 | 645 |
646 int module_vars_count = Smi::cast(get(ModuleVariableCountIndex()))->value(); | 646 int module_vars_count = Smi::cast(get(ModuleVariableCountIndex()))->value(); |
647 int entry = ModuleVariablesIndex(); | 647 int entry = ModuleVariablesIndex(); |
648 for (int i = 0; i < module_vars_count; ++i) { | 648 for (int i = 0; i < module_vars_count; ++i) { |
649 if (*name == get(entry + kModuleVariableNameOffset)) { | 649 if (*name == get(entry + kModuleVariableNameOffset)) { |
650 int index = Smi::cast(get(entry + kModuleVariableIndexOffset))->value(); | 650 int index; |
651 int properties = | 651 ModuleVariable(i, nullptr, &index, mode, init_flag, maybe_assigned_flag); |
652 Smi::cast(get(entry + kModuleVariablePropertiesOffset))->value(); | |
653 *mode = VariableModeField::decode(properties); | |
654 *init_flag = InitFlagField::decode(properties); | |
655 *maybe_assigned_flag = MaybeAssignedFlagField::decode(properties); | |
656 return index; | 652 return index; |
657 } | 653 } |
658 entry += kModuleVariableEntryLength; | 654 entry += kModuleVariableEntryLength; |
659 } | 655 } |
660 | 656 |
661 return -1; | 657 return -1; |
662 } | 658 } |
663 | 659 |
664 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, | 660 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, |
665 Handle<String> name, VariableMode* mode, | 661 Handle<String> name, VariableMode* mode, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 } | 783 } |
788 | 784 |
789 int ScopeInfo::ModuleInfoIndex() { | 785 int ScopeInfo::ModuleInfoIndex() { |
790 return OuterScopeInfoIndex() + (HasOuterScopeInfo() ? 1 : 0); | 786 return OuterScopeInfoIndex() + (HasOuterScopeInfo() ? 1 : 0); |
791 } | 787 } |
792 | 788 |
793 int ScopeInfo::ModuleVariableCountIndex() { return ModuleInfoIndex() + 1; } | 789 int ScopeInfo::ModuleVariableCountIndex() { return ModuleInfoIndex() + 1; } |
794 | 790 |
795 int ScopeInfo::ModuleVariablesIndex() { return ModuleVariableCountIndex() + 1; } | 791 int ScopeInfo::ModuleVariablesIndex() { return ModuleVariableCountIndex() + 1; } |
796 | 792 |
| 793 void ScopeInfo::ModuleVariable(int i, String** name, int* index, |
| 794 VariableMode* mode, |
| 795 InitializationFlag* init_flag, |
| 796 MaybeAssignedFlag* maybe_assigned_flag) { |
| 797 DCHECK_LE(0, i); |
| 798 DCHECK_LT(i, Smi::cast(get(ModuleVariableCountIndex()))->value()); |
| 799 |
| 800 int entry = ModuleVariablesIndex() + i * kModuleVariableEntryLength; |
| 801 int properties = |
| 802 Smi::cast(get(entry + kModuleVariablePropertiesOffset))->value(); |
| 803 |
| 804 if (name != nullptr) { |
| 805 *name = String::cast(get(entry + kModuleVariableNameOffset)); |
| 806 } |
| 807 if (index != nullptr) { |
| 808 *index = Smi::cast(get(entry + kModuleVariableIndexOffset))->value(); |
| 809 } |
| 810 if (mode != nullptr) { |
| 811 *mode = VariableModeField::decode(properties); |
| 812 } |
| 813 if (init_flag != nullptr) { |
| 814 *init_flag = InitFlagField::decode(properties); |
| 815 } |
| 816 if (maybe_assigned_flag != nullptr) { |
| 817 *maybe_assigned_flag = MaybeAssignedFlagField::decode(properties); |
| 818 } |
| 819 } |
| 820 |
797 #ifdef DEBUG | 821 #ifdef DEBUG |
798 | 822 |
799 static void PrintList(const char* list_name, | 823 static void PrintList(const char* list_name, |
800 int nof_internal_slots, | 824 int nof_internal_slots, |
801 int start, | 825 int start, |
802 int end, | 826 int end, |
803 ScopeInfo* scope_info) { | 827 ScopeInfo* scope_info) { |
804 if (start < end) { | 828 if (start < end) { |
805 PrintF("\n // %s\n", list_name); | 829 PrintF("\n // %s\n", list_name); |
806 if (nof_internal_slots > 0) { | 830 if (nof_internal_slots > 0) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 | 921 |
898 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); | 922 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); |
899 result->set(kModuleRequestsIndex, *module_requests); | 923 result->set(kModuleRequestsIndex, *module_requests); |
900 result->set(kSpecialExportsIndex, *special_exports); | 924 result->set(kSpecialExportsIndex, *special_exports); |
901 result->set(kRegularExportsIndex, *regular_exports); | 925 result->set(kRegularExportsIndex, *regular_exports); |
902 result->set(kNamespaceImportsIndex, *namespace_imports); | 926 result->set(kNamespaceImportsIndex, *namespace_imports); |
903 result->set(kRegularImportsIndex, *regular_imports); | 927 result->set(kRegularImportsIndex, *regular_imports); |
904 return result; | 928 return result; |
905 } | 929 } |
906 | 930 |
| 931 Handle<ModuleInfoEntry> ModuleInfo::LookupRegularImport( |
| 932 Handle<ModuleInfo> info, Handle<String> local_name) { |
| 933 Isolate* isolate = info->GetIsolate(); |
| 934 Handle<FixedArray> regular_imports(info->regular_imports(), isolate); |
| 935 for (int i = 0, n = regular_imports->length(); i < n; ++i) { |
| 936 Handle<ModuleInfoEntry> entry( |
| 937 ModuleInfoEntry::cast(regular_imports->get(i)), isolate); |
| 938 if (String::cast(entry->local_name())->Equals(*local_name)) { |
| 939 return entry; |
| 940 } |
| 941 } |
| 942 UNREACHABLE(); |
| 943 return Handle<ModuleInfoEntry>(); |
| 944 } |
| 945 |
907 } // namespace internal | 946 } // namespace internal |
908 } // namespace v8 | 947 } // namespace v8 |
OLD | NEW |