runtime-module.cc 2.04 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 12 13

namespace v8 {
namespace internal {

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

  Handle<Script> script(Script::cast(function->shared()->script()));

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

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 38 39 40 41
  CONVERT_SMI_ARG_CHECKED(module_request, 0);
  Handle<Module> module(isolate->context()->module());
  return *Module::GetModuleNamespace(module, module_request);
}

42
RUNTIME_FUNCTION(Runtime_LoadModuleVariable) {
43
  HandleScope scope(isolate);
44
  DCHECK_EQ(1, args.length());
45
  CONVERT_SMI_ARG_CHECKED(index, 0);
46
  Handle<Module> module(isolate->context()->module());
47
  return *Module::LoadVariable(module, index);
48 49
}

50
RUNTIME_FUNCTION(Runtime_StoreModuleVariable) {
51
  HandleScope scope(isolate);
52
  DCHECK_EQ(2, args.length());
53
  CONVERT_SMI_ARG_CHECKED(index, 0);
54 55
  CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
  Handle<Module> module(isolate->context()->module());
56
  Module::StoreVariable(module, index, value);
57 58 59
  return isolate->heap()->undefined_value();
}

60 61 62 63 64 65 66
RUNTIME_FUNCTION(Runtime_GetImportMetaObject) {
  HandleScope scope(isolate);
  DCHECK_EQ(0, args.length());
  Handle<Module> module(isolate->context()->module());
  return *isolate->RunHostInitializeImportMetaObjectCallback(module);
}

67 68
}  // namespace internal
}  // namespace v8