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

Side by Side Diff: src/objects.cc

Issue 2368393002: [modules] Move implementation of Instantiate to i::Module (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 19709 matching lines...) Expand 10 before | Expand all | Expand 10 after
19720 19720
19721 // Unresolvable. 19721 // Unresolvable.
19722 if (must_resolve) { 19722 if (must_resolve) {
19723 THROW_NEW_ERROR(isolate, 19723 THROW_NEW_ERROR(isolate,
19724 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), 19724 NewSyntaxError(MessageTemplate::kUnresolvableExport, name),
19725 Cell); 19725 Cell);
19726 } 19726 }
19727 return MaybeHandle<Cell>(); 19727 return MaybeHandle<Cell>();
19728 } 19728 }
19729 19729
19730 bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context,
19731 v8::Module::ResolveCallback callback,
19732 v8::Local<v8::Value> callback_data) {
19733 // Already instantiated.
19734 if (module->code()->IsJSFunction()) return true;
19735
19736 Isolate* isolate = module->GetIsolate();
19737 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()),
19738 isolate);
19739 Handle<JSFunction> function =
19740 isolate->factory()->NewFunctionFromSharedFunctionInfo(
19741 shared,
19742 handle(Utils::OpenHandle(*context)->native_context(), isolate));
19743 module->set_code(*function);
19744
19745 Handle<ModuleInfo> module_info(shared->scope_info()->ModuleDescriptorInfo(),
19746 isolate);
19747
19748 // Set up local exports.
19749 Handle<FixedArray> regular_exports(module_info->regular_exports(), isolate);
19750 for (int i = 0, n = regular_exports->length(); i < n; i += 2) {
19751 Handle<FixedArray> export_names(
19752 FixedArray::cast(regular_exports->get(i + 1)), isolate);
19753 CreateExport(module, export_names);
19754 }
19755
19756 // Partially set up indirect exports.
19757 // For each indirect export, we create the appropriate slot in the export
19758 // table and store its ModuleInfoEntry there. When we later find the correct
19759 // Cell in the module that actually provides the value, we replace the
19760 // ModuleInfoEntry by that Cell (see ResolveExport).
19761 Handle<FixedArray> special_exports(module_info->special_exports(), isolate);
19762 for (int i = 0, n = special_exports->length(); i < n; ++i) {
19763 Handle<ModuleInfoEntry> entry(
19764 ModuleInfoEntry::cast(special_exports->get(i)), isolate);
19765 Handle<Object> export_name(entry->export_name(), isolate);
19766 if (export_name->IsUndefined(isolate)) continue; // Star export.
19767 CreateIndirectExport(module, Handle<String>::cast(export_name), entry);
19768 }
19769
19770 Handle<FixedArray> module_requests(module_info->module_requests(), isolate);
19771 for (int i = 0, length = module_requests->length(); i < length; ++i) {
19772 Handle<String> specifier(String::cast(module_requests->get(i)), isolate);
19773 v8::Local<v8::Module> api_requested_module;
19774 // TODO(adamk): Revisit these failure cases once d8 knows how to
19775 // persist a module_map across multiple top-level module loads, as
19776 // the current module is left in a "half-instantiated" state.
19777 if (!callback(context, v8::Utils::ToLocal(specifier),
19778 v8::Utils::ToLocal(module), callback_data)
19779 .ToLocal(&api_requested_module)) {
19780 // TODO(adamk): Give this a better error message. But this is a
19781 // misuse of the API anyway.
19782 isolate->ThrowIllegalOperation();
19783 return false;
19784 }
19785 Handle<Module> requested_module = Utils::OpenHandle(*api_requested_module);
19786 module->requested_modules()->set(i, *requested_module);
19787 if (!Instantiate(requested_module, context, callback, callback_data)) {
19788 return false;
19789 }
19790 }
19791
19792 // Resolve imports.
19793 Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate);
19794 for (int i = 0, n = regular_imports->length(); i < n; ++i) {
19795 Handle<ModuleInfoEntry> entry(
19796 ModuleInfoEntry::cast(regular_imports->get(i)), isolate);
19797 Handle<String> name(String::cast(entry->import_name()), isolate);
19798 int module_request = Smi::cast(entry->module_request())->value();
19799 if (ResolveImport(module, name, module_request, true).is_null()) {
19800 return false;
19801 }
19802 }
19803
19804 // Resolve indirect exports.
19805 for (int i = 0, n = special_exports->length(); i < n; ++i) {
19806 Handle<ModuleInfoEntry> entry(
19807 ModuleInfoEntry::cast(special_exports->get(i)), isolate);
19808 Handle<Object> name(entry->export_name(), isolate);
19809 if (name->IsUndefined(isolate)) continue; // Star export.
19810 if (ResolveExport(module, Handle<String>::cast(name), true).is_null()) {
19811 return false;
19812 }
19813 }
19814
19815 return true;
19816 }
19817
19730 } // namespace internal 19818 } // namespace internal
19731 } // namespace v8 19819 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698