|
| 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 | + 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 | + void RegisterT(T* address) { |
| 43 | + external_references_.push_back(reinterpret_cast<intptr_t>(address)); |
| 44 | + } |
| 45 | + bool is_finalized_ = false; |
| 46 | + std::vector<intptr_t> external_references_; |
| 47 | +}; |
| 48 | + |
| 49 | +#define EXTERNAL_REFERENCE_BINDING_LIST(V) |
| 50 | + |
| 51 | +} // namespace node |
| 52 | + |
| 53 | +// Declare all the external reference registration functions here, |
| 54 | +// and define them later with #NODE_MODULE_EXTERNAL_REFERENCE(modname, func); |
| 55 | +#define V(modname) \ |
| 56 | + void _register_external_reference_##modname( \ |
| 57 | + node::ExternalReferenceRegistry* registry); |
| 58 | +EXTERNAL_REFERENCE_BINDING_LIST(V) |
| 59 | +#undef V |
| 60 | + |
| 61 | +#define NODE_MODULE_EXTERNAL_REFERENCE(modname, func) \ |
| 62 | + void _register_external_reference_##modname( \ |
| 63 | + node::ExternalReferenceRegistry* registry) { \ |
| 64 | + func(registry); \ |
| 65 | + } |
| 66 | +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
| 67 | +#endif // SRC_NODE_EXTERNAL_REFERENCE_H_ |
0 commit comments