OLD | NEW |
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 19833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19844 // Unresolvable. | 19844 // Unresolvable. |
19845 if (must_resolve) { | 19845 if (must_resolve) { |
19846 THROW_NEW_ERROR(isolate, | 19846 THROW_NEW_ERROR(isolate, |
19847 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), | 19847 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), |
19848 Cell); | 19848 Cell); |
19849 } | 19849 } |
19850 return MaybeHandle<Cell>(); | 19850 return MaybeHandle<Cell>(); |
19851 } | 19851 } |
19852 | 19852 |
19853 bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context, | 19853 bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context, |
19854 v8::Module::ResolveCallback callback, | 19854 v8::Module::ResolveCallback callback) { |
19855 v8::Local<v8::Value> callback_data) { | |
19856 // Already instantiated. | 19855 // Already instantiated. |
19857 if (module->code()->IsJSFunction()) return true; | 19856 if (module->code()->IsJSFunction()) return true; |
19858 | 19857 |
19859 Isolate* isolate = module->GetIsolate(); | 19858 Isolate* isolate = module->GetIsolate(); |
19860 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()), | 19859 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()), |
19861 isolate); | 19860 isolate); |
19862 Handle<JSFunction> function = | 19861 Handle<JSFunction> function = |
19863 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 19862 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
19864 shared, | 19863 shared, |
19865 handle(Utils::OpenHandle(*context)->native_context(), isolate)); | 19864 handle(Utils::OpenHandle(*context)->native_context(), isolate)); |
(...skipping 25 matching lines...) Expand all Loading... |
19891 } | 19890 } |
19892 | 19891 |
19893 Handle<FixedArray> module_requests(module_info->module_requests(), isolate); | 19892 Handle<FixedArray> module_requests(module_info->module_requests(), isolate); |
19894 for (int i = 0, length = module_requests->length(); i < length; ++i) { | 19893 for (int i = 0, length = module_requests->length(); i < length; ++i) { |
19895 Handle<String> specifier(String::cast(module_requests->get(i)), isolate); | 19894 Handle<String> specifier(String::cast(module_requests->get(i)), isolate); |
19896 v8::Local<v8::Module> api_requested_module; | 19895 v8::Local<v8::Module> api_requested_module; |
19897 // TODO(adamk): Revisit these failure cases once d8 knows how to | 19896 // TODO(adamk): Revisit these failure cases once d8 knows how to |
19898 // persist a module_map across multiple top-level module loads, as | 19897 // persist a module_map across multiple top-level module loads, as |
19899 // the current module is left in a "half-instantiated" state. | 19898 // the current module is left in a "half-instantiated" state. |
19900 if (!callback(context, v8::Utils::ToLocal(specifier), | 19899 if (!callback(context, v8::Utils::ToLocal(specifier), |
19901 v8::Utils::ToLocal(module), callback_data) | 19900 v8::Utils::ToLocal(module)) |
19902 .ToLocal(&api_requested_module)) { | 19901 .ToLocal(&api_requested_module)) { |
19903 // TODO(adamk): Give this a better error message. But this is a | 19902 // TODO(adamk): Give this a better error message. But this is a |
19904 // misuse of the API anyway. | 19903 // misuse of the API anyway. |
19905 isolate->ThrowIllegalOperation(); | 19904 isolate->ThrowIllegalOperation(); |
19906 return false; | 19905 return false; |
19907 } | 19906 } |
19908 Handle<Module> requested_module = Utils::OpenHandle(*api_requested_module); | 19907 Handle<Module> requested_module = Utils::OpenHandle(*api_requested_module); |
19909 module->requested_modules()->set(i, *requested_module); | 19908 module->requested_modules()->set(i, *requested_module); |
19910 if (!Instantiate(requested_module, context, callback, callback_data)) { | 19909 if (!Instantiate(requested_module, context, callback)) { |
19911 return false; | 19910 return false; |
19912 } | 19911 } |
19913 } | 19912 } |
19914 | 19913 |
19915 Zone zone(isolate->allocator()); | 19914 Zone zone(isolate->allocator()); |
19916 | 19915 |
19917 // Resolve imports. | 19916 // Resolve imports. |
19918 Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate); | 19917 Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate); |
19919 for (int i = 0, n = regular_imports->length(); i < n; ++i) { | 19918 for (int i = 0, n = regular_imports->length(); i < n; ++i) { |
19920 Handle<ModuleInfoEntry> entry( | 19919 Handle<ModuleInfoEntry> entry( |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20105 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) | 20104 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) |
20106 .Check(); | 20105 .Check(); |
20107 } | 20106 } |
20108 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); | 20107 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); |
20109 | 20108 |
20110 return ns; | 20109 return ns; |
20111 } | 20110 } |
20112 | 20111 |
20113 } // namespace internal | 20112 } // namespace internal |
20114 } // namespace v8 | 20113 } // namespace v8 |
OLD | NEW |