GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_external_reference.h Lines: 4 4 100.0 %
Date: 2022-10-07 04:22:37 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
  V(v8::IndexedPropertySetterCallback)                                         \
35
  V(v8::IndexedPropertyDefinerCallback)                                        \
36
  V(v8::IndexedPropertyDeleterCallback)                                        \
37
  V(v8::IndexedPropertyQueryCallback)                                          \
38
  V(v8::IndexedPropertyDescriptorCallback)
39
40
#define V(ExternalReferenceType)                                               \
41
  void Register(ExternalReferenceType addr) { RegisterT(addr); }
42
4203764
  ALLOWED_EXTERNAL_REFERENCE_TYPES(V)
43
#undef V
44
45
  // This can be called only once.
46
  const std::vector<intptr_t>& external_references();
47
48
  bool is_empty() { return external_references_.empty(); }
49
50
 private:
51
  template <typename T>
52
4203764
  void RegisterT(T* address) {
53
4203764
    external_references_.push_back(reinterpret_cast<intptr_t>(address));
54
4203764
  }
55
  bool is_finalized_ = false;
56
  std::vector<intptr_t> external_references_;
57
};
58
59
#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)                                \
60
  V(async_wrap)                                                                \
61
  V(binding)                                                                   \
62
  V(blob)                                                                      \
63
  V(buffer)                                                                    \
64
  V(builtins)                                                                  \
65
  V(cares_wrap)                                                                \
66
  V(contextify)                                                                \
67
  V(credentials)                                                               \
68
  V(env_var)                                                                   \
69
  V(errors)                                                                    \
70
  V(fs)                                                                        \
71
  V(fs_dir)                                                                    \
72
  V(fs_event_wrap)                                                             \
73
  V(handle_wrap)                                                               \
74
  V(heap_utils)                                                                \
75
  V(messaging)                                                                 \
76
  V(mksnapshot)                                                                \
77
  V(options)                                                                   \
78
  V(os)                                                                        \
79
  V(performance)                                                               \
80
  V(process_methods)                                                           \
81
  V(process_object)                                                            \
82
  V(report)                                                                    \
83
  V(task_queue)                                                                \
84
  V(tcp_wrap)                                                                  \
85
  V(tty_wrap)                                                                  \
86
  V(url)                                                                       \
87
  V(util)                                                                      \
88
  V(pipe_wrap)                                                                 \
89
  V(serdes)                                                                    \
90
  V(string_decoder)                                                            \
91
  V(stream_wrap)                                                               \
92
  V(signal_wrap)                                                               \
93
  V(trace_events)                                                              \
94
  V(timers)                                                                    \
95
  V(types)                                                                     \
96
  V(uv)                                                                        \
97
  V(v8)                                                                        \
98
  V(zlib)                                                                      \
99
  V(wasm_web_api)                                                              \
100
  V(worker)
101
102
#if NODE_HAVE_I18N_SUPPORT
103
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu)
104
#else
105
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
106
#endif  // NODE_HAVE_I18N_SUPPORT
107
108
#if HAVE_INSPECTOR
109
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                           \
110
  V(inspector)                                                                 \
111
  V(profiler)
112
#else
113
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)
114
#endif  // HAVE_INSPECTOR
115
116
#if HAVE_OPENSSL
117
#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V) V(crypto) V(tls_wrap)
118
#else
119
#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
120
#endif  // HAVE_OPENSSL
121
122
#define EXTERNAL_REFERENCE_BINDING_LIST(V)                                     \
123
  EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)                                      \
124
  EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                                 \
125
  EXTERNAL_REFERENCE_BINDING_LIST_I18N(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_