GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_external_reference.h Lines: 4 4 100.0 %
Date: 2022-01-17 04:13:54 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_NODE_EXTERNAL_REFERENCE_H_
2
#define SRC_NODE_EXTERNAL_REFERENCE_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include <cinttypes>
7
#include <vector>
8
#include "v8-fast-api-calls.h"
9
#include "v8.h"
10
11
namespace node {
12
13
using CFunctionCallback = void (*)(v8::Local<v8::Value> receiver);
14
15
// This class manages the external references from the V8 heap
16
// to the C++ addresses in Node.js.
17
class ExternalReferenceRegistry {
18
 public:
19
  ExternalReferenceRegistry();
20
21
#define ALLOWED_EXTERNAL_REFERENCE_TYPES(V)                                    \
22
  V(CFunctionCallback)                                                         \
23
  V(const v8::CFunctionInfo*)                                                  \
24
  V(v8::FunctionCallback)                                                      \
25
  V(v8::AccessorGetterCallback)                                                \
26
  V(v8::AccessorSetterCallback)                                                \
27
  V(v8::AccessorNameGetterCallback)                                            \
28
  V(v8::AccessorNameSetterCallback)                                            \
29
  V(v8::GenericNamedPropertyDefinerCallback)                                   \
30
  V(v8::GenericNamedPropertyDeleterCallback)                                   \
31
  V(v8::GenericNamedPropertyEnumeratorCallback)                                \
32
  V(v8::GenericNamedPropertyQueryCallback)                                     \
33
  V(v8::GenericNamedPropertySetterCallback)
34
35
#define V(ExternalReferenceType)                                               \
36
  void Register(ExternalReferenceType addr) { RegisterT(addr); }
37
3434187
  ALLOWED_EXTERNAL_REFERENCE_TYPES(V)
38
#undef V
39
40
  // This can be called only once.
41
  const std::vector<intptr_t>& external_references();
42
43
  bool is_empty() { return external_references_.empty(); }
44
45
 private:
46
  template <typename T>
47
3434187
  void RegisterT(T* address) {
48
3434187
    external_references_.push_back(reinterpret_cast<intptr_t>(address));
49
3434187
  }
50
  bool is_finalized_ = false;
51
  std::vector<intptr_t> external_references_;
52
};
53
54
#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)                                \
55
  V(async_wrap)                                                                \
56
  V(binding)                                                                   \
57
  V(blob)                                                                      \
58
  V(buffer)                                                                    \
59
  V(contextify)                                                                \
60
  V(credentials)                                                               \
61
  V(env_var)                                                                   \
62
  V(errors)                                                                    \
63
  V(fs)                                                                        \
64
  V(fs_dir)                                                                    \
65
  V(fs_event_wrap)                                                             \
66
  V(handle_wrap)                                                               \
67
  V(heap_utils)                                                                \
68
  V(messaging)                                                                 \
69
  V(native_module)                                                             \
70
  V(os)                                                                        \
71
  V(performance)                                                               \
72
  V(process_methods)                                                           \
73
  V(process_object)                                                            \
74
  V(report)                                                                    \
75
  V(task_queue)                                                                \
76
  V(tcp_wrap)                                                                  \
77
  V(tty_wrap)                                                                  \
78
  V(url)                                                                       \
79
  V(util)                                                                      \
80
  V(pipe_wrap)                                                                 \
81
  V(serdes)                                                                    \
82
  V(string_decoder)                                                            \
83
  V(stream_wrap)                                                               \
84
  V(signal_wrap)                                                               \
85
  V(trace_events)                                                              \
86
  V(timers)                                                                    \
87
  V(types)                                                                     \
88
  V(uv)                                                                        \
89
  V(v8)                                                                        \
90
  V(zlib)                                                                      \
91
  V(worker)
92
93
#if NODE_HAVE_I18N_SUPPORT
94
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu)
95
#else
96
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
97
#endif  // NODE_HAVE_I18N_SUPPORT
98
99
#if HAVE_INSPECTOR
100
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                           \
101
  V(inspector)                                                                 \
102
  V(profiler)
103
#else
104
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)
105
#endif  // HAVE_INSPECTOR
106
107
#if HAVE_DTRACE || HAVE_ETW
108
#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V) V(dtrace)
109
#else
110
#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V)
111
#endif
112
113
#if HAVE_OPENSSL
114
#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V) V(crypto) V(tls_wrap)
115
#else
116
#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
117
#endif  // HAVE_OPENSSL
118
119
#define EXTERNAL_REFERENCE_BINDING_LIST(V)                                     \
120
  EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)                                      \
121
  EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                                 \
122
  EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)                                      \
123
  EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V)                                    \
124
  EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
125
126
}  // namespace node
127
128
// Declare all the external reference registration functions here,
129
// and define them later with #NODE_MODULE_EXTERNAL_REFERENCE(modname, func);
130
#define V(modname)                                                             \
131
  void _register_external_reference_##modname(                                 \
132
      node::ExternalReferenceRegistry* registry);
133
EXTERNAL_REFERENCE_BINDING_LIST(V)
134
#undef V
135
136
#define NODE_MODULE_EXTERNAL_REFERENCE(modname, func)                          \
137
  void _register_external_reference_##modname(                                 \
138
      node::ExternalReferenceRegistry* registry) {                             \
139
    func(registry);                                                            \
140
  }
141
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
142
#endif  // SRC_NODE_EXTERNAL_REFERENCE_H_