GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_contextify.h Lines: 17 24 70.8 %
Date: 2021-06-10 04:11:54 Branches: 2 2 100.0 %

Line Branch Exec Source
1
#ifndef SRC_NODE_CONTEXTIFY_H_
2
#define SRC_NODE_CONTEXTIFY_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "base_object-inl.h"
7
#include "node_context_data.h"
8
#include "node_errors.h"
9
10
namespace node {
11
class ExternalReferenceRegistry;
12
13
namespace contextify {
14
15
10
class MicrotaskQueueWrap : public BaseObject {
16
 public:
17
  MicrotaskQueueWrap(Environment* env, v8::Local<v8::Object> obj);
18
19
  const std::shared_ptr<v8::MicrotaskQueue>& microtask_queue() const;
20
21
  static void Init(Environment* env, v8::Local<v8::Object> target);
22
  static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
23
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
24
25
  // This could have methods for running the microtask queue, if we ever decide
26
  // to make that fully customizable from userland.
27
28
  SET_NO_MEMORY_INFO()
29
  SET_MEMORY_INFO_NAME(MicrotaskQueueWrap)
30
  SET_SELF_SIZE(MicrotaskQueueWrap)
31
32
 private:
33
  std::shared_ptr<v8::MicrotaskQueue> microtask_queue_;
34
};
35
36
3528
struct ContextOptions {
37
  v8::Local<v8::String> name;
38
  v8::Local<v8::String> origin;
39
  v8::Local<v8::Boolean> allow_code_gen_strings;
40
  v8::Local<v8::Boolean> allow_code_gen_wasm;
41
  BaseObjectPtr<MicrotaskQueueWrap> microtask_queue_wrap;
42
};
43
44
class ContextifyContext {
45
 public:
46
  enum InternalFields { kSlot, kInternalFieldCount };
47
  ContextifyContext(Environment* env,
48
                    v8::Local<v8::Object> sandbox_obj,
49
                    const ContextOptions& options);
50
  ~ContextifyContext();
51
  static void CleanupHook(void* arg);
52
53
  v8::MaybeLocal<v8::Object> CreateDataWrapper(Environment* env);
54
  v8::MaybeLocal<v8::Context> CreateV8Context(Environment* env,
55
                                              v8::Local<v8::Object> sandbox_obj,
56
                                              const ContextOptions& options);
57
  static void Init(Environment* env, v8::Local<v8::Object> target);
58
  static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
59
60
  static ContextifyContext* ContextFromContextifiedSandbox(
61
      Environment* env,
62
      const v8::Local<v8::Object>& sandbox);
63
64
2124844
  inline Environment* env() const {
65
2124844
    return env_;
66
  }
67
68
2122574
  inline v8::Local<v8::Context> context() const {
69
2122574
    return PersistentToLocal::Default(env()->isolate(), context_);
70
  }
71
72
37844
  inline v8::Local<v8::Object> global_proxy() const {
73
75688
    return context()->Global();
74
  }
75
76
1041504
  inline v8::Local<v8::Object> sandbox() const {
77
    return v8::Local<v8::Object>::Cast(
78
3124512
        context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject));
79
  }
80
81
1385
  inline std::shared_ptr<v8::MicrotaskQueue> microtask_queue() const {
82
1385
    if (!microtask_queue_wrap_) return {};
83
15
    return microtask_queue_wrap_->microtask_queue();
84
  }
85
86
87
  template <typename T>
88
  static ContextifyContext* Get(const v8::PropertyCallbackInfo<T>& args);
89
90
 private:
91
  static void MakeContext(const v8::FunctionCallbackInfo<v8::Value>& args);
92
  static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args);
93
  static void CompileFunction(
94
      const v8::FunctionCallbackInfo<v8::Value>& args);
95
  static void WeakCallback(
96
      const v8::WeakCallbackInfo<ContextifyContext>& data);
97
  static void PropertyGetterCallback(
98
      v8::Local<v8::Name> property,
99
      const v8::PropertyCallbackInfo<v8::Value>& args);
100
  static void PropertySetterCallback(
101
      v8::Local<v8::Name> property,
102
      v8::Local<v8::Value> value,
103
      const v8::PropertyCallbackInfo<v8::Value>& args);
104
  static void PropertyDescriptorCallback(
105
      v8::Local<v8::Name> property,
106
      const v8::PropertyCallbackInfo<v8::Value>& args);
107
  static void PropertyDefinerCallback(
108
      v8::Local<v8::Name> property,
109
      const v8::PropertyDescriptor& desc,
110
      const v8::PropertyCallbackInfo<v8::Value>& args);
111
  static void PropertyDeleterCallback(
112
      v8::Local<v8::Name> property,
113
      const v8::PropertyCallbackInfo<v8::Boolean>& args);
114
  static void PropertyEnumeratorCallback(
115
      const v8::PropertyCallbackInfo<v8::Array>& args);
116
  static void IndexedPropertyGetterCallback(
117
      uint32_t index,
118
      const v8::PropertyCallbackInfo<v8::Value>& args);
119
  static void IndexedPropertySetterCallback(
120
      uint32_t index,
121
      v8::Local<v8::Value> value,
122
      const v8::PropertyCallbackInfo<v8::Value>& args);
123
  static void IndexedPropertyDescriptorCallback(
124
      uint32_t index,
125
      const v8::PropertyCallbackInfo<v8::Value>& args);
126
  static void IndexedPropertyDefinerCallback(
127
      uint32_t index,
128
      const v8::PropertyDescriptor& desc,
129
      const v8::PropertyCallbackInfo<v8::Value>& args);
130
  static void IndexedPropertyDeleterCallback(
131
      uint32_t index,
132
      const v8::PropertyCallbackInfo<v8::Boolean>& args);
133
  Environment* const env_;
134
  v8::Global<v8::Context> context_;
135
  BaseObjectPtr<MicrotaskQueueWrap> microtask_queue_wrap_;
136
};
137
138
class ContextifyScript : public BaseObject {
139
 public:
140
  SET_NO_MEMORY_INFO()
141
  SET_MEMORY_INFO_NAME(ContextifyScript)
142
  SET_SELF_SIZE(ContextifyScript)
143
144
  ContextifyScript(Environment* env, v8::Local<v8::Object> object);
145
  ~ContextifyScript() override;
146
147
  static void Init(Environment* env, v8::Local<v8::Object> target);
148
  static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
149
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
150
  static bool InstanceOf(Environment* env, const v8::Local<v8::Value>& args);
151
  static void CreateCachedData(
152
      const v8::FunctionCallbackInfo<v8::Value>& args);
153
  static void RunInThisContext(const v8::FunctionCallbackInfo<v8::Value>& args);
154
  static void RunInContext(const v8::FunctionCallbackInfo<v8::Value>& args);
155
  static bool EvalMachine(Environment* env,
156
                          const int64_t timeout,
157
                          const bool display_errors,
158
                          const bool break_on_sigint,
159
                          const bool break_on_first_line,
160
                          std::shared_ptr<v8::MicrotaskQueue> microtask_queue,
161
                          const v8::FunctionCallbackInfo<v8::Value>& args);
162
163
2154
  inline uint32_t id() { return id_; }
164
165
 private:
166
  v8::Global<v8::UnboundScript> script_;
167
  uint32_t id_;
168
};
169
170
class CompiledFnEntry final : public BaseObject {
171
 public:
172
65
  SET_NO_MEMORY_INFO()
173
65
  SET_MEMORY_INFO_NAME(CompiledFnEntry)
174
65
  SET_SELF_SIZE(CompiledFnEntry)
175
176
  CompiledFnEntry(Environment* env,
177
                  v8::Local<v8::Object> object,
178
                  uint32_t id,
179
                  v8::Local<v8::ScriptOrModule> script);
180
  ~CompiledFnEntry();
181
182
  bool IsNotIndicativeOfMemoryLeakAtExit() const override { return true; }
183
184
 private:
185
  uint32_t id_;
186
  v8::Global<v8::ScriptOrModule> script_;
187
188
  static void WeakCallback(const v8::WeakCallbackInfo<CompiledFnEntry>& data);
189
};
190
191
}  // namespace contextify
192
}  // namespace node
193
194
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
195
196
#endif  // SRC_NODE_CONTEXTIFY_H_