GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_external_reference.h Lines: 4 4 100.0 %
Date: 2021-08-24 04:12:49 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
1792692
  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
1792692
  void RegisterT(T* address) {
43
1792692
    external_references_.push_back(reinterpret_cast<intptr_t>(address));
44
1792692
  }
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(task_queue)                                                                \
69
  V(url)                                                                       \
70
  V(util)                                                                      \
71
  V(serdes)                                                                    \
72
  V(string_decoder)                                                            \
73
  V(stream_wrap)                                                               \
74
  V(trace_events)                                                              \
75
  V(timers)                                                                    \
76
  V(types)                                                                     \
77
  V(uv)                                                                        \
78
  V(v8)                                                                        \
79
  V(worker)
80
81
#if NODE_HAVE_I18N_SUPPORT
82
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu)
83
#else
84
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
85
#endif  // NODE_HAVE_I18N_SUPPORT
86
87
#if HAVE_INSPECTOR
88
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                           \
89
  V(inspector)                                                                 \
90
  V(profiler)
91
#else
92
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)
93
#endif  // HAVE_INSPECTOR
94
95
#define EXTERNAL_REFERENCE_BINDING_LIST(V)                                     \
96
  EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)                                      \
97
  EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                                 \
98
  EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
99
100
}  // namespace node
101
102
// Declare all the external reference registration functions here,
103
// and define them later with #NODE_MODULE_EXTERNAL_REFERENCE(modname, func);
104
#define V(modname)                                                             \
105
  void _register_external_reference_##modname(                                 \
106
      node::ExternalReferenceRegistry* registry);
107
EXTERNAL_REFERENCE_BINDING_LIST(V)
108
#undef V
109
110
#define NODE_MODULE_EXTERNAL_REFERENCE(modname, func)                          \
111
  void _register_external_reference_##modname(                                 \
112
      node::ExternalReferenceRegistry* registry) {                             \
113
    func(registry);                                                            \
114
  }
115
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
116
#endif  // SRC_NODE_EXTERNAL_REFERENCE_H_