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