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 19926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19937 if (must_resolve) { | 19937 if (must_resolve) { |
19938 THROW_NEW_ERROR(isolate, | 19938 THROW_NEW_ERROR(isolate, |
19939 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), | 19939 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), |
19940 Cell); | 19940 Cell); |
19941 } | 19941 } |
19942 return MaybeHandle<Cell>(); | 19942 return MaybeHandle<Cell>(); |
19943 } | 19943 } |
19944 | 19944 |
19945 bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context, | 19945 bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context, |
19946 v8::Module::ResolveCallback callback) { | 19946 v8::Module::ResolveCallback callback) { |
19947 // Already instantiated. | 19947 if (module->instantiated()) return true; |
19948 if (module->code()->IsJSFunction()) return true; | |
19949 | 19948 |
19950 Isolate* isolate = module->GetIsolate(); | 19949 Isolate* isolate = module->GetIsolate(); |
19951 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()), | 19950 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()), |
19952 isolate); | 19951 isolate); |
19953 Handle<JSFunction> function = | 19952 Handle<JSFunction> function = |
19954 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 19953 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
19955 shared, | 19954 shared, |
19956 handle(Utils::OpenHandle(*context)->native_context(), isolate)); | 19955 handle(Utils::OpenHandle(*context)->native_context(), isolate)); |
19957 module->set_code(*function); | 19956 module->set_code(*function); |
| 19957 DCHECK(module->instantiated()); |
19958 | 19958 |
19959 Handle<ModuleInfo> module_info(shared->scope_info()->ModuleDescriptorInfo(), | 19959 Handle<ModuleInfo> module_info(shared->scope_info()->ModuleDescriptorInfo(), |
19960 isolate); | 19960 isolate); |
19961 | 19961 |
19962 // Set up local exports. | 19962 // Set up local exports. |
19963 Handle<FixedArray> regular_exports(module_info->regular_exports(), isolate); | 19963 Handle<FixedArray> regular_exports(module_info->regular_exports(), isolate); |
19964 for (int i = 0, n = regular_exports->length(); i < n; i += 2) { | 19964 for (int i = 0, n = regular_exports->length(); i < n; i += 2) { |
19965 Handle<FixedArray> export_names( | 19965 Handle<FixedArray> export_names( |
19966 FixedArray::cast(regular_exports->get(i + 1)), isolate); | 19966 FixedArray::cast(regular_exports->get(i + 1)), isolate); |
19967 CreateExport(module, export_names); | 19967 CreateExport(module, export_names); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20029 if (ResolveExport(module, Handle<String>::cast(name), true, &resolve_set) | 20029 if (ResolveExport(module, Handle<String>::cast(name), true, &resolve_set) |
20030 .is_null()) { | 20030 .is_null()) { |
20031 return false; | 20031 return false; |
20032 } | 20032 } |
20033 } | 20033 } |
20034 | 20034 |
20035 return true; | 20035 return true; |
20036 } | 20036 } |
20037 | 20037 |
20038 MaybeHandle<Object> Module::Evaluate(Handle<Module> module) { | 20038 MaybeHandle<Object> Module::Evaluate(Handle<Module> module) { |
20039 DCHECK(module->code()->IsJSFunction()); // Instantiated. | 20039 DCHECK(module->instantiated()); |
20040 | |
20041 Isolate* isolate = module->GetIsolate(); | |
20042 | 20040 |
20043 // Each module can only be evaluated once. | 20041 // Each module can only be evaluated once. |
| 20042 Isolate* isolate = module->GetIsolate(); |
20044 if (module->evaluated()) return isolate->factory()->undefined_value(); | 20043 if (module->evaluated()) return isolate->factory()->undefined_value(); |
20045 module->set_evaluated(true); | 20044 Handle<JSFunction> function(JSFunction::cast(module->code()), isolate); |
| 20045 module->set_evaluated(); |
20046 | 20046 |
20047 // Initialization. | 20047 // Initialization. |
20048 Handle<JSFunction> function(JSFunction::cast(module->code()), isolate); | |
20049 DCHECK_EQ(MODULE_SCOPE, function->shared()->scope_info()->scope_type()); | 20048 DCHECK_EQ(MODULE_SCOPE, function->shared()->scope_info()->scope_type()); |
20050 Handle<Object> receiver = isolate->factory()->undefined_value(); | 20049 Handle<Object> receiver = isolate->factory()->undefined_value(); |
20051 Handle<Object> argv[] = {module}; | 20050 Handle<Object> argv[] = {module}; |
20052 Handle<Object> generator; | 20051 Handle<Object> generator; |
20053 ASSIGN_RETURN_ON_EXCEPTION( | 20052 ASSIGN_RETURN_ON_EXCEPTION( |
20054 isolate, generator, | 20053 isolate, generator, |
20055 Execution::Call(isolate, function, receiver, arraysize(argv), argv), | 20054 Execution::Call(isolate, function, receiver, arraysize(argv), argv), |
20056 Object); | 20055 Object); |
20057 | 20056 |
20058 // Recursion. | 20057 // Recursion. |
20059 Handle<FixedArray> requested_modules(module->requested_modules(), isolate); | 20058 Handle<FixedArray> requested_modules(module->requested_modules(), isolate); |
20060 for (int i = 0, length = requested_modules->length(); i < length; ++i) { | 20059 for (int i = 0, length = requested_modules->length(); i < length; ++i) { |
20061 Handle<Module> import(Module::cast(requested_modules->get(i)), isolate); | 20060 Handle<Module> import(Module::cast(requested_modules->get(i)), isolate); |
20062 RETURN_ON_EXCEPTION(isolate, Evaluate(import), Object); | 20061 RETURN_ON_EXCEPTION(isolate, Evaluate(import), Object); |
20063 } | 20062 } |
20064 | 20063 |
20065 // Evaluation of module body. | 20064 // Evaluation of module body. |
20066 Handle<JSFunction> resume( | 20065 Handle<JSFunction> resume( |
20067 isolate->native_context()->generator_next_internal(), isolate); | 20066 isolate->native_context()->generator_next_internal(), isolate); |
20068 return Execution::Call(isolate, resume, generator, 0, nullptr); | 20067 return Execution::Call(isolate, resume, generator, 0, nullptr); |
20069 } | 20068 } |
20070 | 20069 |
20071 namespace { | 20070 namespace { |
20072 | 20071 |
20073 void FetchStarExports(Handle<Module> module, Zone* zone, | 20072 void FetchStarExports(Handle<Module> module, Zone* zone, |
20074 UnorderedModuleSet* visited) { | 20073 UnorderedModuleSet* visited) { |
20075 DCHECK(module->code()->IsJSFunction()); // Instantiated. | 20074 DCHECK(module->instantiated()); |
20076 | 20075 |
20077 bool cycle = !visited->insert(module).second; | 20076 bool cycle = !visited->insert(module).second; |
20078 if (cycle) return; | 20077 if (cycle) return; |
20079 | 20078 |
20080 Isolate* isolate = module->GetIsolate(); | 20079 Isolate* isolate = module->GetIsolate(); |
20081 Handle<ObjectHashTable> exports(module->exports(), isolate); | 20080 Handle<ObjectHashTable> exports(module->exports(), isolate); |
20082 UnorderedStringMap more_exports(zone); | 20081 UnorderedStringMap more_exports(zone); |
20083 | 20082 |
20084 // TODO(neis): Only allocate more_exports if there are star exports. | 20083 // TODO(neis): Only allocate more_exports if there are star exports. |
20085 // Maybe split special_exports into indirect_exports and star_exports. | 20084 // Maybe split special_exports into indirect_exports and star_exports. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20196 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) | 20195 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) |
20197 .Check(); | 20196 .Check(); |
20198 } | 20197 } |
20199 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); | 20198 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); |
20200 | 20199 |
20201 return ns; | 20200 return ns; |
20202 } | 20201 } |
20203 | 20202 |
20204 } // namespace internal | 20203 } // namespace internal |
20205 } // namespace v8 | 20204 } // namespace v8 |
OLD | NEW |