Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: src/ast/scopeinfo.cc

Issue 2445683002: [modules] Add partial support for debug-scopes. (Closed)
Patch Set: Fix handle bug. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/contexts.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 for (const auto& elem : descr->module_requests()) { 884 for (const auto& elem : descr->module_requests()) {
861 module_requests->set(elem.second, *elem.first->string()); 885 module_requests->set(elem.second, *elem.first->string());
862 } 886 }
863 887
864 // Serialize special exports. 888 // Serialize special exports.
865 Handle<FixedArray> special_exports = 889 Handle<FixedArray> special_exports =
866 isolate->factory()->NewFixedArray(descr->special_exports().length()); 890 isolate->factory()->NewFixedArray(descr->special_exports().length());
867 { 891 {
868 int i = 0; 892 int i = 0;
869 for (auto entry : descr->special_exports()) { 893 for (auto entry : descr->special_exports()) {
870 special_exports->set(i++, *entry->Serialize(isolate)); 894 Handle<ModuleInfoEntry> serialized_entry = entry->Serialize(isolate);
895 special_exports->set(i++, *serialized_entry);
871 } 896 }
872 } 897 }
873 898
874 // Serialize namespace imports. 899 // Serialize namespace imports.
875 Handle<FixedArray> namespace_imports = 900 Handle<FixedArray> namespace_imports =
876 isolate->factory()->NewFixedArray(descr->namespace_imports().length()); 901 isolate->factory()->NewFixedArray(descr->namespace_imports().length());
877 { 902 {
878 int i = 0; 903 int i = 0;
879 for (auto entry : descr->namespace_imports()) { 904 for (auto entry : descr->namespace_imports()) {
880 namespace_imports->set(i++, *entry->Serialize(isolate)); 905 Handle<ModuleInfoEntry> serialized_entry = entry->Serialize(isolate);
906 namespace_imports->set(i++, *serialized_entry);
881 } 907 }
882 } 908 }
883 909
884 // Serialize regular exports. 910 // Serialize regular exports.
885 Handle<FixedArray> regular_exports = 911 Handle<FixedArray> regular_exports =
886 descr->SerializeRegularExports(isolate, zone); 912 descr->SerializeRegularExports(isolate, zone);
887 913
888 // Serialize regular imports. 914 // Serialize regular imports.
889 Handle<FixedArray> regular_imports = isolate->factory()->NewFixedArray( 915 Handle<FixedArray> regular_imports = isolate->factory()->NewFixedArray(
890 static_cast<int>(descr->regular_imports().size())); 916 static_cast<int>(descr->regular_imports().size()));
891 { 917 {
892 int i = 0; 918 int i = 0;
893 for (const auto& elem : descr->regular_imports()) { 919 for (const auto& elem : descr->regular_imports()) {
894 regular_imports->set(i++, *elem.second->Serialize(isolate)); 920 Handle<ModuleInfoEntry> serialized_entry =
921 elem.second->Serialize(isolate);
922 regular_imports->set(i++, *serialized_entry);
895 } 923 }
896 } 924 }
897 925
898 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); 926 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo();
899 result->set(kModuleRequestsIndex, *module_requests); 927 result->set(kModuleRequestsIndex, *module_requests);
900 result->set(kSpecialExportsIndex, *special_exports); 928 result->set(kSpecialExportsIndex, *special_exports);
901 result->set(kRegularExportsIndex, *regular_exports); 929 result->set(kRegularExportsIndex, *regular_exports);
902 result->set(kNamespaceImportsIndex, *namespace_imports); 930 result->set(kNamespaceImportsIndex, *namespace_imports);
903 result->set(kRegularImportsIndex, *regular_imports); 931 result->set(kRegularImportsIndex, *regular_imports);
904 return result; 932 return result;
905 } 933 }
906 934
935 Handle<ModuleInfoEntry> ModuleInfo::LookupRegularImport(
936 Handle<ModuleInfo> info, Handle<String> local_name) {
937 Isolate* isolate = info->GetIsolate();
938 Handle<FixedArray> regular_imports(info->regular_imports(), isolate);
939 for (int i = 0, n = regular_imports->length(); i < n; ++i) {
940 Handle<ModuleInfoEntry> entry(
941 ModuleInfoEntry::cast(regular_imports->get(i)), isolate);
942 if (String::cast(entry->local_name())->Equals(*local_name)) {
943 return entry;
944 }
945 }
946 UNREACHABLE();
947 return Handle<ModuleInfoEntry>();
948 }
949
907 } // namespace internal 950 } // namespace internal
908 } // namespace v8 951 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/contexts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698