1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/execution/arguments-inl.h"
6 #include "src/logging/counters.h"
7 #include "src/objects/js-promise.h"
8 #include "src/objects/objects-inl.h"
9 #include "src/objects/source-text-module.h"
10 #include "src/runtime/runtime-utils.h"
11
12 namespace v8 {
13 namespace internal {
14
RUNTIME_FUNCTION(Runtime_DynamicImportCall)15 RUNTIME_FUNCTION(Runtime_DynamicImportCall) {
16 HandleScope scope(isolate);
17 DCHECK_EQ(2, args.length());
18 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
19 CONVERT_ARG_HANDLE_CHECKED(Object, specifier, 1);
20
21 Handle<Script> script(Script::cast(function->shared().script()), isolate);
22
23 while (script->has_eval_from_shared()) {
24 script = handle(Script::cast(script->eval_from_shared().script()), isolate);
25 }
26
27 RETURN_RESULT_OR_FAILURE(
28 isolate,
29 isolate->RunHostImportModuleDynamicallyCallback(script, specifier));
30 }
31
RUNTIME_FUNCTION(Runtime_GetModuleNamespace)32 RUNTIME_FUNCTION(Runtime_GetModuleNamespace) {
33 HandleScope scope(isolate);
34 DCHECK_EQ(1, args.length());
35 CONVERT_SMI_ARG_CHECKED(module_request, 0);
36 Handle<SourceTextModule> module(isolate->context().module(), isolate);
37 return *SourceTextModule::GetModuleNamespace(isolate, module, module_request);
38 }
39
RUNTIME_FUNCTION(Runtime_GetImportMetaObject)40 RUNTIME_FUNCTION(Runtime_GetImportMetaObject) {
41 HandleScope scope(isolate);
42 DCHECK_EQ(0, args.length());
43 Handle<SourceTextModule> module(isolate->context().module(), isolate);
44 RETURN_RESULT_OR_FAILURE(isolate,
45 SourceTextModule::GetImportMeta(isolate, module));
46 }
47
48 } // namespace internal
49 } // namespace v8
50