Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: src/api.cc

Issue 2368393002: [modules] Move implementation of Instantiate to i::Module (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 7fec7da4474a68d28c22c31ce91e63464151ca8b..c9c5210fdfa2a05ba630c7b755e4487540423bfd 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1915,108 +1915,12 @@ Local<Value> Module::GetEmbedderData() const {
i::handle(self->embedder_data(), self->GetIsolate()));
}
-MUST_USE_RESULT
-static bool InstantiateModule(Local<Module> v8_module,
- Local<Context> v8_context,
- Module::ResolveCallback callback,
- Local<Value> callback_data) {
- i::Handle<i::Module> module = Utils::OpenHandle(*v8_module);
- i::Isolate* isolate = module->GetIsolate();
-
- // Already instantiated.
- if (module->code()->IsJSFunction()) return true;
-
- i::Handle<i::SharedFunctionInfo> shared(
- i::SharedFunctionInfo::cast(module->code()), isolate);
- i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
- i::Handle<i::JSFunction> function =
- isolate->factory()->NewFunctionFromSharedFunctionInfo(
- shared, handle(context->native_context(), isolate));
- module->set_code(*function);
-
- i::Handle<i::FixedArray> regular_exports = i::handle(
- shared->scope_info()->ModuleDescriptorInfo()->regular_exports(), isolate);
- i::Handle<i::FixedArray> regular_imports = i::handle(
- shared->scope_info()->ModuleDescriptorInfo()->regular_imports(), isolate);
- i::Handle<i::FixedArray> special_exports = i::handle(
- shared->scope_info()->ModuleDescriptorInfo()->special_exports(), isolate);
-
- // Set up local exports.
- for (int i = 0, n = regular_exports->length(); i < n; i += 2) {
- i::Handle<i::FixedArray> export_names(
- i::FixedArray::cast(regular_exports->get(i + 1)), isolate);
- i::Module::CreateExport(module, export_names);
- }
-
- // Partially set up indirect exports.
- // For each indirect export, we create the appropriate slot in the export
- // table and store its ModuleInfoEntry there. When we later find the correct
- // Cell in the module that actually provides the value, we replace the
- // ModuleInfoEntry by that Cell (see ResolveExport).
- for (int i = 0, n = special_exports->length(); i < n; ++i) {
- i::Handle<i::ModuleInfoEntry> entry(
- i::ModuleInfoEntry::cast(special_exports->get(i)), isolate);
- i::Handle<i::Object> export_name(entry->export_name(), isolate);
- if (export_name->IsUndefined(isolate)) continue; // Star export.
- i::Module::CreateIndirectExport(
- module, i::Handle<i::String>::cast(export_name), entry);
- }
-
- for (int i = 0, length = v8_module->GetModuleRequestsLength(); i < length;
- ++i) {
- Local<Module> requested_module;
- // TODO(adamk): Revisit these failure cases once d8 knows how to
- // persist a module_map across multiple top-level module loads, as
- // the current module is left in a "half-instantiated" state.
- if (!callback(v8_context, v8_module->GetModuleRequest(i), v8_module,
- callback_data)
- .ToLocal(&requested_module)) {
- // TODO(adamk): Give this a better error message. But this is a
- // misuse of the API anyway.
- isolate->ThrowIllegalOperation();
- return false;
- }
- module->requested_modules()->set(i, *Utils::OpenHandle(*requested_module));
- if (!InstantiateModule(requested_module, v8_context, callback,
- callback_data)) {
- return false;
- }
- }
-
- // Resolve imports.
- for (int i = 0, n = regular_imports->length(); i < n; ++i) {
- i::Handle<i::ModuleInfoEntry> entry(
- i::ModuleInfoEntry::cast(regular_imports->get(i)), isolate);
- i::Handle<i::String> name(i::String::cast(entry->import_name()), isolate);
- int module_request = i::Smi::cast(entry->module_request())->value();
- if (i::Module::ResolveImport(module, name, module_request, true)
- .is_null()) {
- return false;
- }
- }
-
- // Resolve indirect exports.
- for (int i = 0, n = special_exports->length(); i < n; ++i) {
- i::Handle<i::ModuleInfoEntry> entry(
- i::ModuleInfoEntry::cast(special_exports->get(i)), isolate);
- i::Handle<i::Object> name(entry->export_name(), isolate);
- if (name->IsUndefined(isolate)) continue; // Star export.
- if (i::Module::ResolveExport(module, i::Handle<i::String>::cast(name), true)
- .is_null()) {
- return false;
- }
- }
-
- return true;
-}
-
bool Module::Instantiate(Local<Context> context,
Module::ResolveCallback callback,
Local<Value> callback_data) {
PREPARE_FOR_EXECUTION_BOOL(context, Module, Instantiate);
- has_pending_exception =
- !InstantiateModule(Utils::ToLocal(Utils::OpenHandle(this)), context,
- callback, callback_data);
+ has_pending_exception = !i::Module::Instantiate(
+ Utils::OpenHandle(this), context, callback, callback_data);
RETURN_ON_FAILED_EXECUTION_BOOL();
return true;
}
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698