GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_external_reference.h Lines: 4 4 100.0 %
Date: 2022-04-11 04:20:14 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
3515888
  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
3515888
  void RegisterT(T* address) {
48
3515888
    external_references_.push_back(reinterpret_cast<intptr_t>(address));
49
3515888
  }
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(mksnapshot)                                                                \
70
  V(native_module)                                                             \
71
  V(options)                                                                   \
72
  V(os)                                                                        \
73
  V(performance)                                                               \
74
  V(process_methods)                                                           \
75
  V(process_object)                                                            \
76
  V(report)                                                                    \
77
  V(task_queue)                                                                \
78
  V(tcp_wrap)                                                                  \
79
  V(tty_wrap)                                                                  \
80
  V(url)                                                                       \
81
  V(util)                                                                      \
82
  V(pipe_wrap)                                                                 \
83
  V(serdes)                                                                    \
84
  V(string_decoder)                                                            \
85
  V(stream_wrap)                                                               \
86
  V(signal_wrap)                                                               \
87
  V(trace_events)                                                              \
88
  V(timers)                                                                    \
89
  V(types)                                                                     \
90
  V(uv)                                                                        \
91
  V(v8)                                                                        \
92
  V(zlib)                                                                      \
93
  V(worker)
94
95
#if NODE_HAVE_I18N_SUPPORT
96
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu)
97
#else
98
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
99
#endif  // NODE_HAVE_I18N_SUPPORT
100
101
#if HAVE_INSPECTOR
102
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                           \
103
  V(inspector)                                                                 \
104
  V(profiler)
105
#else
106
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)
107
#endif  // HAVE_INSPECTOR
108
109
#if HAVE_DTRACE || HAVE_ETW
110
#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V) V(dtrace)
111
#else
112
#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V)
113
#endif
114
115
#if HAVE_OPENSSL
116
#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V) V(crypto) V(tls_wrap)
117
#else
118
#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
119
#endif  // HAVE_OPENSSL
120
121
#define EXTERNAL_REFERENCE_BINDING_LIST(V)                                     \
122
  EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)                                      \
123
  EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                                 \
124
  EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)                                      \
125
  EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V)                                    \
126
  EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
127
128
}  // namespace node
129
130
// Declare all the external reference registration functions here,
131
// and define them later with #NODE_MODULE_EXTERNAL_REFERENCE(modname, func);
132
#define V(modname)                                                             \
133
  void _register_external_reference_##modname(                                 \
134
      node::ExternalReferenceRegistry* registry);
135
EXTERNAL_REFERENCE_BINDING_LIST(V)
136
#undef V
137
138
#define NODE_MODULE_EXTERNAL_REFERENCE(modname, func)                          \
139
  void _register_external_reference_##modname(                                 \
140
      node::ExternalReferenceRegistry* registry) {                             \
141
    func(registry);                                                            \
142
  }
143
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
144
#endif  // SRC_NODE_EXTERNAL_REFERENCE_H_