runtime-module.cc 1.5 KB
Newer Older
1 2 3 4 5 6 7
// 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.

#include "src/runtime/runtime-utils.h"

#include "src/arguments.h"
8 9
#include "src/counters.h"
#include "src/objects-inl.h"
10 11
#include "src/objects/js-promise.h"
#include "src/objects/module.h"
12 13 14 15

namespace v8 {
namespace internal {

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

22
  Handle<Script> script(Script::cast(function->shared()->script()), isolate);
23

24 25 26
  while (script->has_eval_from_shared()) {
    script =
        handle(Script::cast(script->eval_from_shared()->script()), isolate);
27 28
  }

29 30
  RETURN_RESULT_OR_FAILURE(
      isolate,
31
      isolate->RunHostImportModuleDynamicallyCallback(script, specifier));
32 33
}

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

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

49 50
}  // namespace internal
}  // namespace v8