runtime-module.cc 1.55 KB
Newer Older
1 2 3 4
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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 13 14

namespace v8 {
namespace internal {

15 16
RUNTIME_FUNCTION(Runtime_DynamicImportCall) {
  HandleScope scope(isolate);
17 18 19 20
  DCHECK_EQ(2, args.length());
  CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
  CONVERT_ARG_HANDLE_CHECKED(Object, specifier, 1);

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 28
  RETURN_RESULT_OR_FAILURE(
      isolate,
29
      isolate->RunHostImportModuleDynamicallyCallback(script, specifier));
30 31
}

32 33
RUNTIME_FUNCTION(Runtime_GetModuleNamespace) {
  HandleScope scope(isolate);
34
  DCHECK_EQ(1, args.length());
35
  CONVERT_SMI_ARG_CHECKED(module_request, 0);
36 37
  Handle<SourceTextModule> module(isolate->context().module(), isolate);
  return *SourceTextModule::GetModuleNamespace(isolate, module, module_request);
38 39
}

40 41 42
RUNTIME_FUNCTION(Runtime_GetImportMetaObject) {
  HandleScope scope(isolate);
  DCHECK_EQ(0, args.length());
43
  Handle<SourceTextModule> module(isolate->context().module(), isolate);
44 45 46
  return *isolate->RunHostInitializeImportMetaObjectCallback(module);
}

47 48
}  // namespace internal
}  // namespace v8