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: 13 16 81.3 %
Date: 2020-06-24 22:13:30 Branches: 0 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
namespace contextify {
12
13
2815
struct ContextOptions {
14
  v8::Local<v8::String> name;
15
  v8::Local<v8::String> origin;
16
  v8::Local<v8::Boolean> allow_code_gen_strings;
17
  v8::Local<v8::Boolean> allow_code_gen_wasm;
18
};
19
20
class ContextifyContext {
21
 public:
22
  enum InternalFields { kSlot, kInternalFieldCount };
23
  ContextifyContext(Environment* env,
24
                    v8::Local<v8::Object> sandbox_obj,
25
                    const ContextOptions& options);
26
  ~ContextifyContext();
27
  static void CleanupHook(void* arg);
28
29
  v8::MaybeLocal<v8::Object> CreateDataWrapper(Environment* env);
30
  v8::MaybeLocal<v8::Context> CreateV8Context(Environment* env,
31
                                              v8::Local<v8::Object> sandbox_obj,
32
                                              const ContextOptions& options);
33
  static void Init(Environment* env, v8::Local<v8::Object> target);
34
35
  static ContextifyContext* ContextFromContextifiedSandbox(
36
      Environment* env,
37
      const v8::Local<v8::Object>& sandbox);
38
39
2959882
  inline Environment* env() const {
40
2959882
    return env_;
41
  }
42
43
2958597
  inline v8::Local<v8::Context> context() const {
44
2958597
    return PersistentToLocal::Default(env()->isolate(), context_);
45
  }
46
47
284716
  inline v8::Local<v8::Object> global_proxy() const {
48
569432
    return context()->Global();
49
  }
50
51
1334284
  inline v8::Local<v8::Object> sandbox() const {
52
    return v8::Local<v8::Object>::Cast(
53
4002852
        context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject));
54
  }
55
56
57
  template <typename T>
58
  static ContextifyContext* Get(const v8::PropertyCallbackInfo<T>& args);
59
60
 private:
61
  static void MakeContext(const v8::FunctionCallbackInfo<v8::Value>& args);
62
  static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args);
63
  static void CompileFunction(
64
      const v8::FunctionCallbackInfo<v8::Value>& args);
65
  static void WeakCallback(
66
      const v8::WeakCallbackInfo<ContextifyContext>& data);
67
  static void PropertyGetterCallback(
68
      v8::Local<v8::Name> property,
69
      const v8::PropertyCallbackInfo<v8::Value>& args);
70
  static void PropertySetterCallback(
71
      v8::Local<v8::Name> property,
72
      v8::Local<v8::Value> value,
73
      const v8::PropertyCallbackInfo<v8::Value>& args);
74
  static void PropertyDescriptorCallback(
75
      v8::Local<v8::Name> property,
76
      const v8::PropertyCallbackInfo<v8::Value>& args);
77
  static void PropertyDefinerCallback(
78
      v8::Local<v8::Name> property,
79
      const v8::PropertyDescriptor& desc,
80
      const v8::PropertyCallbackInfo<v8::Value>& args);
81
  static void PropertyDeleterCallback(
82
      v8::Local<v8::Name> property,
83
      const v8::PropertyCallbackInfo<v8::Boolean>& args);
84
  static void PropertyEnumeratorCallback(
85
      const v8::PropertyCallbackInfo<v8::Array>& args);
86
  static void IndexedPropertyGetterCallback(
87
      uint32_t index,
88
      const v8::PropertyCallbackInfo<v8::Value>& args);
89
  static void IndexedPropertySetterCallback(
90
      uint32_t index,
91
      v8::Local<v8::Value> value,
92
      const v8::PropertyCallbackInfo<v8::Value>& args);
93
  static void IndexedPropertyDescriptorCallback(
94
      uint32_t index,
95
      const v8::PropertyCallbackInfo<v8::Value>& args);
96
  static void IndexedPropertyDefinerCallback(
97
      uint32_t index,
98
      const v8::PropertyDescriptor& desc,
99
      const v8::PropertyCallbackInfo<v8::Value>& args);
100
  static void IndexedPropertyDeleterCallback(
101
      uint32_t index,
102
      const v8::PropertyCallbackInfo<v8::Boolean>& args);
103
  Environment* const env_;
104
  v8::Global<v8::Context> context_;
105
};
106
107
class ContextifyScript : public BaseObject {
108
 public:
109
  SET_NO_MEMORY_INFO()
110
  SET_MEMORY_INFO_NAME(ContextifyScript)
111
  SET_SELF_SIZE(ContextifyScript)
112
113
  ContextifyScript(Environment* env, v8::Local<v8::Object> object);
114
  ~ContextifyScript() override;
115
116
  static void Init(Environment* env, v8::Local<v8::Object> target);
117
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
118
  static bool InstanceOf(Environment* env, const v8::Local<v8::Value>& args);
119
  static void CreateCachedData(
120
      const v8::FunctionCallbackInfo<v8::Value>& args);
121
  static void RunInThisContext(const v8::FunctionCallbackInfo<v8::Value>& args);
122
  static void RunInContext(const v8::FunctionCallbackInfo<v8::Value>& args);
123
  static bool EvalMachine(Environment* env,
124
                          const int64_t timeout,
125
                          const bool display_errors,
126
                          const bool break_on_sigint,
127
                          const bool break_on_first_line,
128
                          const v8::FunctionCallbackInfo<v8::Value>& args);
129
130
1856
  inline uint32_t id() { return id_; }
131
132
 private:
133
  v8::Global<v8::UnboundScript> script_;
134
  uint32_t id_;
135
};
136
137
class CompiledFnEntry final : public BaseObject {
138
 public:
139
58
  SET_NO_MEMORY_INFO()
140
58
  SET_MEMORY_INFO_NAME(CompiledFnEntry)
141
58
  SET_SELF_SIZE(CompiledFnEntry)
142
143
  CompiledFnEntry(Environment* env,
144
                  v8::Local<v8::Object> object,
145
                  uint32_t id,
146
                  v8::Local<v8::ScriptOrModule> script);
147
  ~CompiledFnEntry();
148
149
 private:
150
  uint32_t id_;
151
  v8::Global<v8::ScriptOrModule> script_;
152
153
  static void WeakCallback(const v8::WeakCallbackInfo<CompiledFnEntry>& data);
154
};
155
156
}  // namespace contextify
157
}  // namespace node
158
159
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
160
161
#endif  // SRC_NODE_CONTEXTIFY_H_