Commit a037f350 authored by neis's avatar neis Committed by Commit bot

[modules] Also (de-)serialize imports.

This is in preparation for basic support of import statements.

R=adamk@chromium.org
BUG=v8:1569

Review-Url: https://codereview.chromium.org/2357003002
Cr-Commit-Position: refs/heads/master@{#39568}
parent dcd61b90
...@@ -870,6 +870,16 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, ModuleDescriptor* descr) { ...@@ -870,6 +870,16 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, ModuleDescriptor* descr) {
} }
} }
// Serialize special imports.
Handle<FixedArray> special_imports =
isolate->factory()->NewFixedArray(descr->special_imports().length());
{
int i = 0;
for (auto entry : descr->special_imports()) {
special_imports->set(i++, *entry->Serialize(isolate));
}
}
// Serialize regular exports. // Serialize regular exports.
Handle<FixedArray> regular_exports = isolate->factory()->NewFixedArray( Handle<FixedArray> regular_exports = isolate->factory()->NewFixedArray(
static_cast<int>(descr->regular_exports().size())); static_cast<int>(descr->regular_exports().size()));
...@@ -880,10 +890,22 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, ModuleDescriptor* descr) { ...@@ -880,10 +890,22 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, ModuleDescriptor* descr) {
} }
} }
// Serialize regular imports.
Handle<FixedArray> regular_imports = isolate->factory()->NewFixedArray(
static_cast<int>(descr->regular_imports().size()));
{
int i = 0;
for (const auto& elem : descr->regular_imports()) {
regular_imports->set(i++, *elem.second->Serialize(isolate));
}
}
Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo();
result->set(kModuleRequestsIndex, *module_requests); result->set(kModuleRequestsIndex, *module_requests);
result->set(kSpecialExportsIndex, *special_exports); result->set(kSpecialExportsIndex, *special_exports);
result->set(kRegularExportsIndex, *regular_exports); result->set(kRegularExportsIndex, *regular_exports);
result->set(kSpecialImportsIndex, *special_imports);
result->set(kRegularImportsIndex, *regular_imports);
return result; return result;
} }
......
...@@ -185,6 +185,26 @@ ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info, ...@@ -185,6 +185,26 @@ ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info,
module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize( module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize(
isolate, avfactory, serialized_entry)); isolate, avfactory, serialized_entry));
} }
// Deserialize special imports.
Handle<FixedArray> special_imports = handle(module_info->special_imports());
for (int i = 0, n = special_imports->length(); i < n; ++i) {
Handle<ModuleInfoEntry> serialized_entry(
ModuleInfoEntry::cast(special_imports->get(i)), isolate);
module_descriptor_->AddSpecialImport(
ModuleDescriptor::Entry::Deserialize(isolate, avfactory,
serialized_entry),
avfactory->zone());
}
// Deserialize regular imports.
Handle<FixedArray> regular_imports = handle(module_info->regular_imports());
for (int i = 0, n = regular_imports->length(); i < n; ++i) {
Handle<ModuleInfoEntry> serialized_entry(
ModuleInfoEntry::cast(regular_imports->get(i)), isolate);
module_descriptor_->AddRegularImport(ModuleDescriptor::Entry::Deserialize(
isolate, avfactory, serialized_entry));
}
} }
Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info)
......
...@@ -7959,10 +7959,20 @@ FixedArray* ModuleInfo::regular_exports() const { ...@@ -7959,10 +7959,20 @@ FixedArray* ModuleInfo::regular_exports() const {
return FixedArray::cast(get(kRegularExportsIndex)); return FixedArray::cast(get(kRegularExportsIndex));
} }
FixedArray* ModuleInfo::regular_imports() const {
return FixedArray::cast(get(kRegularImportsIndex));
}
FixedArray* ModuleInfo::special_imports() const {
return FixedArray::cast(get(kSpecialImportsIndex));
}
#ifdef DEBUG #ifdef DEBUG
bool ModuleInfo::Equals(ModuleInfo* other) const { bool ModuleInfo::Equals(ModuleInfo* other) const {
return get(kSpecialExportsIndex) == other->get(kSpecialExportsIndex) && return regular_exports() == other->regular_exports() &&
get(kRegularExportsIndex) == other->get(kRegularExportsIndex); regular_imports() == other->regular_imports() &&
special_exports() == other->special_exports() &&
special_imports() == other->special_imports();
} }
#endif #endif
......
...@@ -4575,6 +4575,8 @@ class ModuleInfo : public FixedArray { ...@@ -4575,6 +4575,8 @@ class ModuleInfo : public FixedArray {
inline FixedArray* module_requests() const; inline FixedArray* module_requests() const;
inline FixedArray* special_exports() const; inline FixedArray* special_exports() const;
inline FixedArray* regular_exports() const; inline FixedArray* regular_exports() const;
inline FixedArray* special_imports() const;
inline FixedArray* regular_imports() const;
#ifdef DEBUG #ifdef DEBUG
inline bool Equals(ModuleInfo* other) const; inline bool Equals(ModuleInfo* other) const;
...@@ -4586,6 +4588,8 @@ class ModuleInfo : public FixedArray { ...@@ -4586,6 +4588,8 @@ class ModuleInfo : public FixedArray {
kModuleRequestsIndex, kModuleRequestsIndex,
kSpecialExportsIndex, kSpecialExportsIndex,
kRegularExportsIndex, kRegularExportsIndex,
kSpecialImportsIndex,
kRegularImportsIndex,
kLength kLength
}; };
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment