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 19794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19805 // Unresolvable. | 19805 // Unresolvable. |
19806 if (must_resolve) { | 19806 if (must_resolve) { |
19807 THROW_NEW_ERROR(isolate, | 19807 THROW_NEW_ERROR(isolate, |
19808 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), | 19808 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), |
19809 Cell); | 19809 Cell); |
19810 } | 19810 } |
19811 return MaybeHandle<Cell>(); | 19811 return MaybeHandle<Cell>(); |
19812 } | 19812 } |
19813 | 19813 |
19814 bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context, | 19814 bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context, |
19815 v8::Module::ResolveCallback callback, | 19815 v8::Module::ResolveCallback callback) { |
19816 v8::Local<v8::Value> callback_data) { | |
19817 // Already instantiated. | 19816 // Already instantiated. |
19818 if (module->code()->IsJSFunction()) return true; | 19817 if (module->code()->IsJSFunction()) return true; |
19819 | 19818 |
19820 Isolate* isolate = module->GetIsolate(); | 19819 Isolate* isolate = module->GetIsolate(); |
19821 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()), | 19820 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()), |
19822 isolate); | 19821 isolate); |
19823 Handle<JSFunction> function = | 19822 Handle<JSFunction> function = |
19824 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 19823 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
19825 shared, | 19824 shared, |
19826 handle(Utils::OpenHandle(*context)->native_context(), isolate)); | 19825 handle(Utils::OpenHandle(*context)->native_context(), isolate)); |
(...skipping 25 matching lines...) Expand all Loading... |
19852 } | 19851 } |
19853 | 19852 |
19854 Handle<FixedArray> module_requests(module_info->module_requests(), isolate); | 19853 Handle<FixedArray> module_requests(module_info->module_requests(), isolate); |
19855 for (int i = 0, length = module_requests->length(); i < length; ++i) { | 19854 for (int i = 0, length = module_requests->length(); i < length; ++i) { |
19856 Handle<String> specifier(String::cast(module_requests->get(i)), isolate); | 19855 Handle<String> specifier(String::cast(module_requests->get(i)), isolate); |
19857 v8::Local<v8::Module> api_requested_module; | 19856 v8::Local<v8::Module> api_requested_module; |
19858 // TODO(adamk): Revisit these failure cases once d8 knows how to | 19857 // TODO(adamk): Revisit these failure cases once d8 knows how to |
19859 // persist a module_map across multiple top-level module loads, as | 19858 // persist a module_map across multiple top-level module loads, as |
19860 // the current module is left in a "half-instantiated" state. | 19859 // the current module is left in a "half-instantiated" state. |
19861 if (!callback(context, v8::Utils::ToLocal(specifier), | 19860 if (!callback(context, v8::Utils::ToLocal(specifier), |
19862 v8::Utils::ToLocal(module), callback_data) | 19861 v8::Utils::ToLocal(module)) |
19863 .ToLocal(&api_requested_module)) { | 19862 .ToLocal(&api_requested_module)) { |
19864 // TODO(adamk): Give this a better error message. But this is a | 19863 // TODO(adamk): Give this a better error message. But this is a |
19865 // misuse of the API anyway. | 19864 // misuse of the API anyway. |
19866 isolate->ThrowIllegalOperation(); | 19865 isolate->ThrowIllegalOperation(); |
19867 return false; | 19866 return false; |
19868 } | 19867 } |
19869 Handle<Module> requested_module = Utils::OpenHandle(*api_requested_module); | 19868 Handle<Module> requested_module = Utils::OpenHandle(*api_requested_module); |
19870 module->requested_modules()->set(i, *requested_module); | 19869 module->requested_modules()->set(i, *requested_module); |
19871 if (!Instantiate(requested_module, context, callback, callback_data)) { | 19870 if (!Instantiate(requested_module, context, callback)) { |
19872 return false; | 19871 return false; |
19873 } | 19872 } |
19874 } | 19873 } |
19875 | 19874 |
19876 Zone zone(isolate->allocator()); | 19875 Zone zone(isolate->allocator()); |
19877 | 19876 |
19878 // Resolve imports. | 19877 // Resolve imports. |
19879 Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate); | 19878 Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate); |
19880 for (int i = 0, n = regular_imports->length(); i < n; ++i) { | 19879 for (int i = 0, n = regular_imports->length(); i < n; ++i) { |
19881 Handle<ModuleInfoEntry> entry( | 19880 Handle<ModuleInfoEntry> entry( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19933 } | 19932 } |
19934 | 19933 |
19935 // Evaluation of module body. | 19934 // Evaluation of module body. |
19936 Handle<JSFunction> resume( | 19935 Handle<JSFunction> resume( |
19937 isolate->native_context()->generator_next_internal(), isolate); | 19936 isolate->native_context()->generator_next_internal(), isolate); |
19938 return Execution::Call(isolate, resume, generator, 0, nullptr); | 19937 return Execution::Call(isolate, resume, generator, 0, nullptr); |
19939 } | 19938 } |
19940 | 19939 |
19941 } // namespace internal | 19940 } // namespace internal |
19942 } // namespace v8 | 19941 } // namespace v8 |
OLD | NEW |