Commit c604eae3 authored by adamk's avatar adamk Committed by Commit bot

[modules] Add a requested_modules field to Module

Also simplify Factory::NewModule to take only the SharedFunctionInfo.

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

Review-Url: https://codereview.chromium.org/2355033002
Cr-Commit-Position: refs/heads/master@{#39563}
parent 5deb0bc1
......@@ -2048,19 +2048,16 @@ MaybeLocal<Module> ScriptCompiler::CompileModule(Isolate* isolate,
if (!maybe.ToLocal(&unbound)) return MaybeLocal<Module>();
i::Handle<i::SharedFunctionInfo> shared = Utils::OpenHandle(*unbound);
i::Handle<i::FixedArray> regular_exports =
i::handle(shared->scope_info()->ModuleDescriptorInfo()->regular_exports(),
i_isolate);
int regular_exports_length = regular_exports->length();
i::Handle<i::Module> module =
i_isolate->factory()->NewModule(shared, regular_exports_length);
i::Handle<i::Module> module = i_isolate->factory()->NewModule(shared);
// TODO(neis): This will create multiple cells for the same local variable if
// exported under multiple names, which is wrong but cannot be observed at the
// moment. This will be fixed by doing the full-fledged linking here once we
// get there.
for (int i = 0; i < regular_exports_length; ++i) {
i::Handle<i::FixedArray> regular_exports =
i::handle(shared->scope_info()->ModuleDescriptorInfo()->regular_exports(),
i_isolate);
for (int i = 0, length = regular_exports->length(); i < length; ++i) {
i::Handle<i::ModuleInfoEntry> entry =
i::handle(i::ModuleInfoEntry::cast(regular_exports->get(i)), i_isolate);
DCHECK(entry->import_name()->IsUndefined(i_isolate));
......
......@@ -1712,12 +1712,20 @@ Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
JSGeneratorObject);
}
Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code,
int min_size) {
Handle<ObjectHashTable> exports = ObjectHashTable::New(isolate(), min_size);
Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) {
Handle<ModuleInfo> module_info(code->scope_info()->ModuleDescriptorInfo(),
isolate());
Handle<ObjectHashTable> exports =
ObjectHashTable::New(isolate(), module_info->regular_exports()->length());
int requested_modules_length = module_info->module_requests()->length();
Handle<FixedArray> requested_modules =
requested_modules_length > 0 ? NewFixedArray(requested_modules_length)
: empty_fixed_array();
Handle<Module> module = Handle<Module>::cast(NewStruct(MODULE_TYPE));
module->set_code(*code);
module->set_exports(*exports);
module->set_requested_modules(*requested_modules);
return module;
}
......
......@@ -475,7 +475,7 @@ class Factory final {
Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
Handle<Module> NewModule(Handle<SharedFunctionInfo> code, int min_size);
Handle<Module> NewModule(Handle<SharedFunctionInfo> code);
Handle<JSArrayBuffer> NewJSArrayBuffer(
SharedFlag shared = SharedFlag::kNotShared,
......
......@@ -905,6 +905,7 @@ void Module::ModuleVerify() {
CHECK(code()->IsSharedFunctionInfo() || code()->IsJSFunction());
code()->ObjectVerify();
exports()->ObjectVerify();
requested_modules()->ObjectVerify();
// TODO(neis): Check more.
}
......
......@@ -5703,6 +5703,7 @@ ACCESSORS(ContextExtension, extension, Object, kExtensionOffset)
ACCESSORS(Module, code, Object, kCodeOffset)
ACCESSORS(Module, exports, ObjectHashTable, kExportsOffset)
ACCESSORS(Module, requested_modules, FixedArray, kRequestedModulesOffset)
ACCESSORS(AccessorPair, getter, Object, kGetterOffset)
ACCESSORS(AccessorPair, setter, Object, kSetterOffset)
......
......@@ -1159,6 +1159,7 @@ void Module::ModulePrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "Module");
os << "\n - code: " << Brief(code());
os << "\n - exports: " << Brief(exports());
os << "\n - requested_modules: " << Brief(requested_modules());
os << "\n";
}
......
......@@ -7889,6 +7889,11 @@ class Module : public Struct {
DECL_ACCESSORS(exports, ObjectHashTable)
// [[RequestedModules]]: Modules imported or re-exported by this module.
// Corresponds 1-to-1 to the module specifier strings in
// ModuleInfo::module_requests.
DECL_ACCESSORS(requested_modules, FixedArray)
static void CreateExport(Handle<Module> module, Handle<String> name);
static void StoreExport(Handle<Module> module, Handle<String> name,
Handle<Object> value);
......@@ -7896,7 +7901,8 @@ class Module : public Struct {
static const int kCodeOffset = HeapObject::kHeaderSize;
static const int kExportsOffset = kCodeOffset + kPointerSize;
static const int kSize = kExportsOffset + kPointerSize;
static const int kRequestedModulesOffset = kExportsOffset + kPointerSize;
static const int kSize = kRequestedModulesOffset + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Module);
......
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