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 |
|
3840969 |
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 |
|
3840969 |
void RegisterT(T* address) { |
48 |
|
3840969 |
external_references_.push_back(reinterpret_cast<intptr_t>(address)); |
49 |
|
3840969 |
} |
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(builtins) \ |
60 |
|
|
V(contextify) \ |
61 |
|
|
V(credentials) \ |
62 |
|
|
V(env_var) \ |
63 |
|
|
V(errors) \ |
64 |
|
|
V(fs) \ |
65 |
|
|
V(fs_dir) \ |
66 |
|
|
V(fs_event_wrap) \ |
67 |
|
|
V(handle_wrap) \ |
68 |
|
|
V(heap_utils) \ |
69 |
|
|
V(messaging) \ |
70 |
|
|
V(mksnapshot) \ |
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(wasm_web_api) \ |
94 |
|
|
V(worker) |
95 |
|
|
|
96 |
|
|
#if NODE_HAVE_I18N_SUPPORT |
97 |
|
|
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu) |
98 |
|
|
#else |
99 |
|
|
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) |
100 |
|
|
#endif // NODE_HAVE_I18N_SUPPORT |
101 |
|
|
|
102 |
|
|
#if HAVE_INSPECTOR |
103 |
|
|
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \ |
104 |
|
|
V(inspector) \ |
105 |
|
|
V(profiler) |
106 |
|
|
#else |
107 |
|
|
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) |
108 |
|
|
#endif // HAVE_INSPECTOR |
109 |
|
|
|
110 |
|
|
#if HAVE_OPENSSL |
111 |
|
|
#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V) V(crypto) V(tls_wrap) |
112 |
|
|
#else |
113 |
|
|
#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V) |
114 |
|
|
#endif // HAVE_OPENSSL |
115 |
|
|
|
116 |
|
|
#define EXTERNAL_REFERENCE_BINDING_LIST(V) \ |
117 |
|
|
EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \ |
118 |
|
|
EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \ |
119 |
|
|
EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) \ |
120 |
|
|
EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V) |
121 |
|
|
|
122 |
|
|
} // namespace node |
123 |
|
|
|
124 |
|
|
// Declare all the external reference registration functions here, |
125 |
|
|
// and define them later with #NODE_MODULE_EXTERNAL_REFERENCE(modname, func); |
126 |
|
|
#define V(modname) \ |
127 |
|
|
void _register_external_reference_##modname( \ |
128 |
|
|
node::ExternalReferenceRegistry* registry); |
129 |
|
|
EXTERNAL_REFERENCE_BINDING_LIST(V) |
130 |
|
|
#undef V |
131 |
|
|
|
132 |
|
|
#define NODE_MODULE_EXTERNAL_REFERENCE(modname, func) \ |
133 |
|
|
void _register_external_reference_##modname( \ |
134 |
|
|
node::ExternalReferenceRegistry* registry) { \ |
135 |
|
|
func(registry); \ |
136 |
|
|
} |
137 |
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
138 |
|
|
#endif // SRC_NODE_EXTERNAL_REFERENCE_H_ |