GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: module_wrap.h Lines: 6 8 75.0 %
Date: 2021-09-16 04:12:46 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_MODULE_WRAP_H_
2
#define SRC_MODULE_WRAP_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include <unordered_map>
7
#include <string>
8
#include <vector>
9
#include "base_object.h"
10
11
namespace node {
12
13
class Environment;
14
15
namespace contextify {
16
class ContextifyContext;
17
}
18
19
namespace loader {
20
21
enum ScriptType : int {
22
  kScript,
23
  kModule,
24
  kFunction,
25
};
26
27
enum HostDefinedOptions : int {
28
  kType = 8,
29
  kID = 9,
30
  kLength = 10,
31
};
32
33
class ModuleWrap : public BaseObject {
34
 public:
35
  enum InternalFields {
36
    kModuleWrapBaseField = BaseObject::kInternalFieldCount,
37
    kURLSlot,
38
    kSyntheticEvaluationStepsSlot,
39
    kContextObjectSlot,  // Object whose creation context is the target Context
40
    kInternalFieldCount
41
  };
42
43
  static void Initialize(v8::Local<v8::Object> target,
44
                         v8::Local<v8::Value> unused,
45
                         v8::Local<v8::Context> context,
46
                         void* priv);
47
  static void HostInitializeImportMetaObjectCallback(
48
      v8::Local<v8::Context> context,
49
      v8::Local<v8::Module> module,
50
      v8::Local<v8::Object> meta);
51
52
223
  void MemoryInfo(MemoryTracker* tracker) const override {
53
223
    tracker->TrackField("resolve_cache", resolve_cache_);
54
223
  }
55
56
45092
  inline uint32_t id() { return id_; }
57
  v8::Local<v8::Context> context() const;
58
  static ModuleWrap* GetFromID(node::Environment*, uint32_t id);
59
60
223
  SET_MEMORY_INFO_NAME(ModuleWrap)
61
223
  SET_SELF_SIZE(ModuleWrap)
62
63
  bool IsNotIndicativeOfMemoryLeakAtExit() const override {
64
    // XXX: The garbage collection rules for ModuleWrap are *super* unclear.
65
    // Do these objects ever get GC'd? Are we just okay with leaking them?
66
    return true;
67
  }
68
69
 private:
70
  ModuleWrap(Environment* env,
71
             v8::Local<v8::Object> object,
72
             v8::Local<v8::Module> module,
73
             v8::Local<v8::String> url);
74
  ~ModuleWrap() override;
75
76
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
77
  static void Link(const v8::FunctionCallbackInfo<v8::Value>& args);
78
  static void Instantiate(const v8::FunctionCallbackInfo<v8::Value>& args);
79
  static void Evaluate(const v8::FunctionCallbackInfo<v8::Value>& args);
80
  static void GetNamespace(const v8::FunctionCallbackInfo<v8::Value>& args);
81
  static void GetStatus(const v8::FunctionCallbackInfo<v8::Value>& args);
82
  static void GetError(const v8::FunctionCallbackInfo<v8::Value>& args);
83
  static void GetStaticDependencySpecifiers(
84
      const v8::FunctionCallbackInfo<v8::Value>& args);
85
86
  static void SetImportModuleDynamicallyCallback(
87
      const v8::FunctionCallbackInfo<v8::Value>& args);
88
  static void SetInitializeImportMetaObjectCallback(
89
      const v8::FunctionCallbackInfo<v8::Value>& args);
90
  static v8::MaybeLocal<v8::Value> SyntheticModuleEvaluationStepsCallback(
91
      v8::Local<v8::Context> context, v8::Local<v8::Module> module);
92
  static void SetSyntheticExport(
93
      const v8::FunctionCallbackInfo<v8::Value>& args);
94
  static void CreateCachedData(const v8::FunctionCallbackInfo<v8::Value>& args);
95
96
  static v8::MaybeLocal<v8::Module> ResolveModuleCallback(
97
      v8::Local<v8::Context> context,
98
      v8::Local<v8::String> specifier,
99
      v8::Local<v8::FixedArray> import_assertions,
100
      v8::Local<v8::Module> referrer);
101
  static ModuleWrap* GetFromModule(node::Environment*, v8::Local<v8::Module>);
102
103
  v8::Global<v8::Module> module_;
104
  std::unordered_map<std::string, v8::Global<v8::Promise>> resolve_cache_;
105
  contextify::ContextifyContext* contextify_context_ = nullptr;
106
  bool synthetic_ = false;
107
  bool linked_ = false;
108
  uint32_t id_;
109
};
110
111
}  // namespace loader
112
}  // namespace node
113
114
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
115
116
#endif  // SRC_MODULE_WRAP_H_