Index: src/ast/modules.cc |
diff --git a/src/ast/modules.cc b/src/ast/modules.cc |
index 1367942245c0e4b3206664f62b102f595f4878ef..f0cb18bc627be13d3fd251231f98dbf6b136431c 100644 |
--- a/src/ast/modules.cc |
+++ b/src/ast/modules.cc |
@@ -12,16 +12,11 @@ namespace internal { |
void ModuleDescriptor::AddImport( |
const AstRawString* import_name, const AstRawString* local_name, |
const AstRawString* module_request, Scanner::Location loc, Zone* zone) { |
- DCHECK_NOT_NULL(import_name); |
- DCHECK_NOT_NULL(local_name); |
- DCHECK_NOT_NULL(module_request); |
Entry* entry = new (zone) Entry(loc); |
entry->local_name = local_name; |
entry->import_name = import_name; |
entry->module_request = module_request; |
- regular_imports_.insert(std::make_pair(entry->local_name, entry)); |
- // We don't care if there's already an entry for this local name, as in that |
- // case we will report an error when declaring the variable. |
+ AddRegularImport(entry); |
} |
@@ -33,28 +28,25 @@ void ModuleDescriptor::AddStarImport( |
Entry* entry = new (zone) Entry(loc); |
entry->local_name = local_name; |
entry->module_request = module_request; |
- special_imports_.Add(entry, zone); |
+ AddSpecialImport(entry, zone); |
} |
void ModuleDescriptor::AddEmptyImport( |
const AstRawString* module_request, Scanner::Location loc, Zone* zone) { |
- DCHECK_NOT_NULL(module_request); |
Entry* entry = new (zone) Entry(loc); |
entry->module_request = module_request; |
- special_imports_.Add(entry, zone); |
+ AddSpecialImport(entry, zone); |
} |
void ModuleDescriptor::AddExport( |
const AstRawString* local_name, const AstRawString* export_name, |
Scanner::Location loc, Zone* zone) { |
- DCHECK_NOT_NULL(local_name); |
- DCHECK_NOT_NULL(export_name); |
Entry* entry = new (zone) Entry(loc); |
entry->export_name = export_name; |
entry->local_name = local_name; |
- regular_exports_.insert(std::make_pair(entry->local_name, entry)); |
+ AddRegularExport(entry); |
} |
@@ -63,21 +55,59 @@ void ModuleDescriptor::AddExport( |
const AstRawString* module_request, Scanner::Location loc, Zone* zone) { |
DCHECK_NOT_NULL(import_name); |
DCHECK_NOT_NULL(export_name); |
- DCHECK_NOT_NULL(module_request); |
Entry* entry = new (zone) Entry(loc); |
entry->export_name = export_name; |
entry->import_name = import_name; |
entry->module_request = module_request; |
- special_exports_.Add(entry, zone); |
+ AddSpecialExport(entry, zone); |
} |
void ModuleDescriptor::AddStarExport( |
const AstRawString* module_request, Scanner::Location loc, Zone* zone) { |
- DCHECK_NOT_NULL(module_request); |
Entry* entry = new (zone) Entry(loc); |
entry->module_request = module_request; |
- special_exports_.Add(entry, zone); |
+ AddSpecialExport(entry, zone); |
+} |
+ |
+namespace { |
+ |
+Handle<Object> ToStringOrUndefined(Isolate* isolate, const AstRawString* s) { |
+ return (s == nullptr) |
+ ? Handle<Object>::cast(isolate->factory()->undefined_value()) |
+ : Handle<Object>::cast(s->string()); |
+} |
+ |
+const AstRawString* FromStringOrUndefined(Isolate* isolate, |
+ AstValueFactory* avfactory, |
+ Handle<Object> object) { |
+ if (object->IsUndefined(isolate)) return nullptr; |
+ return avfactory->GetString(Handle<String>::cast(object)); |
+} |
+ |
+} // namespace |
+ |
+Handle<FixedArray> ModuleDescriptor::Entry::Serialize(Isolate* isolate) const { |
+ Handle<FixedArray> result = isolate->factory()->NewFixedArray(4); |
+ result->set(0, *ToStringOrUndefined(isolate, export_name)); |
+ result->set(1, *ToStringOrUndefined(isolate, local_name)); |
+ result->set(2, *ToStringOrUndefined(isolate, import_name)); |
+ result->set(3, *ToStringOrUndefined(isolate, module_request)); |
+ return result; |
+} |
+ |
+ModuleDescriptor::Entry* ModuleDescriptor::Entry::Deserialize( |
+ Isolate* isolate, AstValueFactory* avfactory, Handle<FixedArray> data) { |
+ Entry* entry = new (avfactory->zone()) Entry(Scanner::Location::invalid()); |
+ entry->export_name = |
+ FromStringOrUndefined(isolate, avfactory, handle(data->get(0), isolate)); |
+ entry->local_name = |
+ FromStringOrUndefined(isolate, avfactory, handle(data->get(1), isolate)); |
+ entry->import_name = |
+ FromStringOrUndefined(isolate, avfactory, handle(data->get(2), isolate)); |
+ entry->module_request = |
+ FromStringOrUndefined(isolate, avfactory, handle(data->get(3), isolate)); |
+ return entry; |
} |
void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) { |