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 19888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19899 if (ResolveExport(module, Handle<String>::cast(name), true, &resolve_set) | 19899 if (ResolveExport(module, Handle<String>::cast(name), true, &resolve_set) |
19900 .is_null()) { | 19900 .is_null()) { |
19901 return false; | 19901 return false; |
19902 } | 19902 } |
19903 } | 19903 } |
19904 | 19904 |
19905 return true; | 19905 return true; |
19906 } | 19906 } |
19907 | 19907 |
19908 MaybeHandle<Object> Module::Evaluate(Handle<Module> module) { | 19908 MaybeHandle<Object> Module::Evaluate(Handle<Module> module) { |
19909 DCHECK(module->code()->IsJSFunction()); // Instantiated. | 19909 DCHECK(module->code()->IsJSFunction()); |
19910 | 19910 |
19911 Isolate* isolate = module->GetIsolate(); | 19911 Isolate* isolate = module->GetIsolate(); |
19912 | 19912 |
19913 // Each module can only be evaluated once. | 19913 // Each module can only be evaluated once. |
19914 if (module->evaluated()) return isolate->factory()->undefined_value(); | 19914 if (module->evaluated()) return isolate->factory()->undefined_value(); |
19915 module->set_evaluated(true); | 19915 module->set_evaluated(true); |
19916 | 19916 |
19917 // Initialization. | |
19918 Handle<JSFunction> function(JSFunction::cast(module->code()), isolate); | |
19919 DCHECK_EQ(MODULE_SCOPE, function->shared()->scope_info()->scope_type()); | |
19920 Handle<Object> receiver = isolate->factory()->undefined_value(); | |
19921 Handle<Object> argv[] = {module}; | |
19922 Handle<Object> generator; | |
19923 ASSIGN_RETURN_ON_EXCEPTION( | |
19924 isolate, generator, | |
19925 Execution::Call(isolate, function, receiver, arraysize(argv), argv), | |
19926 Object); | |
19927 | |
19928 // Recursion. | |
19929 Handle<FixedArray> requested_modules(module->requested_modules(), isolate); | 19917 Handle<FixedArray> requested_modules(module->requested_modules(), isolate); |
19930 for (int i = 0, length = requested_modules->length(); i < length; ++i) { | 19918 for (int i = 0, length = requested_modules->length(); i < length; ++i) { |
19931 Handle<Module> import(Module::cast(requested_modules->get(i)), isolate); | 19919 Handle<Module> import(Module::cast(requested_modules->get(i)), isolate); |
19932 RETURN_ON_EXCEPTION(isolate, Evaluate(import), Object); | 19920 RETURN_ON_EXCEPTION(isolate, Evaluate(import), Object); |
19933 } | 19921 } |
19934 | 19922 |
19935 // Evaluation of module body. | 19923 Handle<JSFunction> function(JSFunction::cast(module->code()), isolate); |
19936 Handle<JSFunction> resume( | 19924 DCHECK_EQ(MODULE_SCOPE, function->shared()->scope_info()->scope_type()); |
19937 isolate->native_context()->generator_next_internal(), isolate); | 19925 Handle<Object> receiver = isolate->factory()->undefined_value(); |
19938 return Execution::Call(isolate, resume, generator, 0, nullptr); | 19926 Handle<Object> argv[] = {module}; |
| 19927 return Execution::Call(isolate, function, receiver, arraysize(argv), argv); |
19939 } | 19928 } |
19940 | 19929 |
19941 } // namespace internal | 19930 } // namespace internal |
19942 } // namespace v8 | 19931 } // namespace v8 |
OLD | NEW |