Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 1f54decb599d962117d6b6aa84bbbb99fd5dff30..0060c9684133967d6518da89d03af7f8cb346e23 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -19816,6 +19816,22 @@ class Module::ResolveSet |
Zone* zone_; |
}; |
+namespace { |
+ |
+int ExportIndex(int cell_index) { |
+ DCHECK_EQ(ModuleDescriptor::cell_index_kind(cell_index), |
+ ModuleDescriptor::kExport); |
+ return cell_index - 1; |
+} |
+ |
+int ImportIndex(int cell_index) { |
+ DCHECK_EQ(ModuleDescriptor::cell_index_kind(cell_index), |
+ ModuleDescriptor::kImport); |
+ return -cell_index - 1; |
+} |
+ |
+} // anonymous namespace |
+ |
void Module::CreateIndirectExport(Handle<Module> module, Handle<String> name, |
Handle<ModuleInfoEntry> entry) { |
Isolate* isolate = module->GetIsolate(); |
@@ -19825,11 +19841,15 @@ void Module::CreateIndirectExport(Handle<Module> module, Handle<String> name, |
module->set_exports(*exports); |
} |
-void Module::CreateExport(Handle<Module> module, Handle<FixedArray> names) { |
+void Module::CreateExport(Handle<Module> module, int index, |
adamk
2016/11/03 18:30:45
Curious why you sometimes say "index" and sometime
neis
2016/11/04 10:14:39
Not here at least. Changed these to cell_index.
|
+ Handle<FixedArray> names) { |
DCHECK_LT(0, names->length()); |
Isolate* isolate = module->GetIsolate(); |
+ |
Handle<Cell> cell = |
isolate->factory()->NewCell(isolate->factory()->undefined_value()); |
+ module->regular_exports()->set(ExportIndex(index), *cell); |
+ |
Handle<ObjectHashTable> exports(module->exports(), isolate); |
for (int i = 0, n = names->length(); i < n; ++i) { |
Handle<String> name(String::cast(names->get(i)), isolate); |
@@ -19839,24 +19859,33 @@ void Module::CreateExport(Handle<Module> module, Handle<FixedArray> names) { |
module->set_exports(*exports); |
} |
-void Module::StoreExport(Handle<Module> module, Handle<String> name, |
- Handle<Object> value) { |
- Handle<Cell> cell(Cell::cast(module->exports()->Lookup(name))); |
- cell->set_value(*value); |
-} |
- |
-Handle<Object> Module::LoadExport(Handle<Module> module, Handle<String> name) { |
+Handle<Object> Module::LoadVariable(Handle<Module> module, int index) { |
Isolate* isolate = module->GetIsolate(); |
- Handle<Object> object(module->exports()->Lookup(name), isolate); |
+ Handle<Object> object; |
+ switch (ModuleDescriptor::cell_index_kind(index)) { |
+ case ModuleDescriptor::kImport: |
+ object = |
+ handle(module->regular_imports()->get(ImportIndex(index)), isolate); |
+ break; |
+ case ModuleDescriptor::kExport: |
+ object = |
+ handle(module->regular_exports()->get(ExportIndex(index)), isolate); |
+ break; |
+ case ModuleDescriptor::kInvalid: |
+ UNREACHABLE(); |
+ break; |
+ } |
return handle(Handle<Cell>::cast(object)->value(), isolate); |
} |
-Handle<Object> Module::LoadImport(Handle<Module> module, Handle<String> name, |
- int module_request) { |
+void Module::StoreVariable(Handle<Module> module, int index, |
+ Handle<Object> value) { |
Isolate* isolate = module->GetIsolate(); |
- Handle<Module> requested_module( |
- Module::cast(module->requested_modules()->get(module_request)), isolate); |
- return Module::LoadExport(requested_module, name); |
+ DCHECK_EQ(ModuleDescriptor::cell_index_kind(index), |
+ ModuleDescriptor::kExport); |
+ Handle<Object> object(module->regular_exports()->get(ExportIndex(index)), |
+ isolate); |
+ Handle<Cell>::cast(object)->set_value(*value); |
} |
MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module, |
@@ -20011,10 +20040,12 @@ bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context, |
isolate); |
// Set up local exports. |
+ // TODO(neis): Create regular_exports array here instead of in factory method? |
for (int i = 0, n = module_info->RegularExportCount(); i < n; ++i) { |
+ int cell_index = module_info->RegularExportCellIndex(i); |
Handle<FixedArray> export_names(module_info->RegularExportExportNames(i), |
isolate); |
- CreateExport(module, export_names); |
+ CreateExport(module, cell_index, export_names); |
} |
// Partially set up indirect exports. |
@@ -20066,11 +20097,13 @@ bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context, |
isolate); |
MessageLocation loc(script, entry->beg_pos(), entry->end_pos()); |
ResolveSet resolve_set(&zone); |
- if (ResolveImport(module, name, entry->module_request(), loc, true, |
- &resolve_set) |
- .is_null()) { |
+ Handle<Cell> cell; |
+ if (!ResolveImport(module, name, entry->module_request(), loc, true, |
+ &resolve_set) |
+ .ToHandle(&cell)) { |
return false; |
} |
+ module->regular_imports()->set(ImportIndex(entry->cell_index()), *cell); |
} |
// Resolve indirect exports. |