• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 namespace {
GetEvalOrigin(Isolate * isolate,Script origin_script)16 Handle<Script> GetEvalOrigin(Isolate* isolate, Script origin_script) {
17   DisallowGarbageCollection no_gc;
18   while (origin_script.has_eval_from_shared()) {
19     HeapObject maybe_script = origin_script.eval_from_shared().script();
20     CHECK(maybe_script.IsScript());
21     origin_script = Script::cast(maybe_script);
22   }
23   return handle(origin_script, isolate);
24 }
25 }  // namespace
26 
RUNTIME_FUNCTION(Runtime_DynamicImportCall)27 RUNTIME_FUNCTION(Runtime_DynamicImportCall) {
28   HandleScope scope(isolate);
29   DCHECK_LE(2, args.length());
30   DCHECK_GE(3, args.length());
31   Handle<JSFunction> function = args.at<JSFunction>(0);
32   Handle<Object> specifier = args.at(1);
33 
34   MaybeHandle<Object> import_assertions;
35   if (args.length() == 3) {
36     import_assertions = args.at<Object>(2);
37   }
38 
39   Handle<Script> referrer_script =
40       GetEvalOrigin(isolate, Script::cast(function->shared().script()));
41   RETURN_RESULT_OR_FAILURE(isolate,
42                            isolate->RunHostImportModuleDynamicallyCallback(
43                                referrer_script, specifier, import_assertions));
44 }
45 
RUNTIME_FUNCTION(Runtime_GetModuleNamespace)46 RUNTIME_FUNCTION(Runtime_GetModuleNamespace) {
47   HandleScope scope(isolate);
48   DCHECK_EQ(1, args.length());
49   int module_request = args.smi_value_at(0);
50   Handle<SourceTextModule> module(isolate->context().module(), isolate);
51   return *SourceTextModule::GetModuleNamespace(isolate, module, module_request);
52 }
53 
RUNTIME_FUNCTION(Runtime_GetImportMetaObject)54 RUNTIME_FUNCTION(Runtime_GetImportMetaObject) {
55   HandleScope scope(isolate);
56   DCHECK_EQ(0, args.length());
57   Handle<SourceTextModule> module(isolate->context().module(), isolate);
58   RETURN_RESULT_OR_FAILURE(isolate,
59                            SourceTextModule::GetImportMeta(isolate, module));
60 }
61 
62 }  // namespace internal
63 }  // namespace v8
64