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/modules.h" | 5 #include "src/ast/modules.h" |
6 #include "src/ast/ast-value-factory.h" | 6 #include "src/ast/ast-value-factory.h" |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 const AstRawString* FromStringOrUndefined(Isolate* isolate, | 81 const AstRawString* FromStringOrUndefined(Isolate* isolate, |
82 AstValueFactory* avfactory, | 82 AstValueFactory* avfactory, |
83 Handle<Object> object) { | 83 Handle<Object> object) { |
84 if (object->IsUndefined(isolate)) return nullptr; | 84 if (object->IsUndefined(isolate)) return nullptr; |
85 return avfactory->GetString(Handle<String>::cast(object)); | 85 return avfactory->GetString(Handle<String>::cast(object)); |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 Handle<FixedArray> ModuleDescriptor::Entry::Serialize(Isolate* isolate) const { | 90 Handle<ModuleInfoEntry> ModuleDescriptor::Entry::Serialize( |
91 Handle<FixedArray> result = isolate->factory()->NewFixedArray(4); | 91 Isolate* isolate) const { |
92 result->set(0, *ToStringOrUndefined(isolate, export_name)); | 92 return ModuleInfoEntry::New(isolate, |
93 result->set(1, *ToStringOrUndefined(isolate, local_name)); | 93 ToStringOrUndefined(isolate, export_name), |
94 result->set(2, *ToStringOrUndefined(isolate, import_name)); | 94 ToStringOrUndefined(isolate, local_name), |
95 result->set(3, *ToStringOrUndefined(isolate, module_request)); | 95 ToStringOrUndefined(isolate, import_name), |
| 96 ToStringOrUndefined(isolate, module_request)); |
| 97 } |
| 98 |
| 99 ModuleDescriptor::Entry* ModuleDescriptor::Entry::Deserialize( |
| 100 Isolate* isolate, AstValueFactory* avfactory, |
| 101 Handle<ModuleInfoEntry> entry) { |
| 102 Entry* result = new (avfactory->zone()) Entry(Scanner::Location::invalid()); |
| 103 result->export_name = FromStringOrUndefined( |
| 104 isolate, avfactory, handle(entry->export_name(), isolate)); |
| 105 result->local_name = FromStringOrUndefined( |
| 106 isolate, avfactory, handle(entry->local_name(), isolate)); |
| 107 result->import_name = FromStringOrUndefined( |
| 108 isolate, avfactory, handle(entry->import_name(), isolate)); |
| 109 result->module_request = FromStringOrUndefined( |
| 110 isolate, avfactory, handle(entry->module_request(), isolate)); |
96 return result; | 111 return result; |
97 } | 112 } |
98 | 113 |
99 ModuleDescriptor::Entry* ModuleDescriptor::Entry::Deserialize( | |
100 Isolate* isolate, AstValueFactory* avfactory, Handle<FixedArray> data) { | |
101 Entry* entry = new (avfactory->zone()) Entry(Scanner::Location::invalid()); | |
102 entry->export_name = | |
103 FromStringOrUndefined(isolate, avfactory, handle(data->get(0), isolate)); | |
104 entry->local_name = | |
105 FromStringOrUndefined(isolate, avfactory, handle(data->get(1), isolate)); | |
106 entry->import_name = | |
107 FromStringOrUndefined(isolate, avfactory, handle(data->get(2), isolate)); | |
108 entry->module_request = | |
109 FromStringOrUndefined(isolate, avfactory, handle(data->get(3), isolate)); | |
110 return entry; | |
111 } | |
112 | |
113 void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) { | 114 void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) { |
114 for (auto it = regular_exports_.begin(); it != regular_exports_.end();) { | 115 for (auto it = regular_exports_.begin(); it != regular_exports_.end();) { |
115 Entry* entry = it->second; | 116 Entry* entry = it->second; |
116 DCHECK_NOT_NULL(entry->local_name); | 117 DCHECK_NOT_NULL(entry->local_name); |
117 auto import = regular_imports_.find(entry->local_name); | 118 auto import = regular_imports_.find(entry->local_name); |
118 if (import != regular_imports_.end()) { | 119 if (import != regular_imports_.end()) { |
119 // Found an indirect export. Patch export entry and move it from regular | 120 // Found an indirect export. Patch export entry and move it from regular |
120 // to special. | 121 // to special. |
121 DCHECK_NULL(entry->import_name); | 122 DCHECK_NULL(entry->import_name); |
122 DCHECK_NULL(entry->module_request); | 123 DCHECK_NULL(entry->module_request); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 const Entry* entry = it.second; | 171 const Entry* entry = it.second; |
171 DCHECK_NOT_NULL(entry->local_name); | 172 DCHECK_NOT_NULL(entry->local_name); |
172 if (module_scope->LookupLocal(entry->local_name) == nullptr) { | 173 if (module_scope->LookupLocal(entry->local_name) == nullptr) { |
173 error_handler->ReportMessageAt( | 174 error_handler->ReportMessageAt( |
174 entry->location.beg_pos, entry->location.end_pos, | 175 entry->location.beg_pos, entry->location.end_pos, |
175 MessageTemplate::kModuleExportUndefined, entry->local_name); | 176 MessageTemplate::kModuleExportUndefined, entry->local_name); |
176 return false; | 177 return false; |
177 } | 178 } |
178 } | 179 } |
179 | 180 |
| 181 #ifdef DEBUG |
| 182 // TODO: Remove before landing. |
| 183 Print(); |
| 184 #endif // DEBUG |
| 185 |
180 MakeIndirectExportsExplicit(zone); | 186 MakeIndirectExportsExplicit(zone); |
181 return true; | 187 return true; |
182 } | 188 } |
183 | 189 |
| 190 #ifdef DEBUG |
| 191 void ModuleDescriptor::Print() const { |
| 192 PrintF("Regular exports:\n"); |
| 193 for (const auto& it : regular_exports_) it.second->Print(); |
| 194 } |
| 195 #endif // DEBUG |
| 196 |
184 } // namespace internal | 197 } // namespace internal |
185 } // namespace v8 | 198 } // namespace v8 |
OLD | NEW |