mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Add an ExternalReferenceRegistry class for registering static
external references.
To register the external JS to C++ references created in a binding
(e.g. when a FunctionTemplate is created):
- Add the binding name (same as the id used for `internalBinding()`
and `NODE_MODULE_CONTEXT_AWARE_INTERNAL`) to
`EXTERNAL_REFERENCE_BINDING_LIST` in `src/node_external_reference.h`.
- In the file where the binding is implemented, create a registration
function to register the static C++ references (e.g. the C++
functions in `v8::FunctionCallback` associated with the function
templates), like this:
```c++
void RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(cpp_func_1);
}
```
- At the end of the file where `NODE_MODULE_CONTEXT_AWARE_INTERNAL` is
also usually called, register the registration function with
```
NODE_MODULE_EXTERNAL_REFERENCE(binding_name,
RegisterExternalReferences);
```
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
23 lines
602 B
C++
23 lines
602 B
C++
#include "node_external_reference.h"
|
|
#include <cinttypes>
|
|
#include <vector>
|
|
#include "util.h"
|
|
|
|
namespace node {
|
|
|
|
const std::vector<intptr_t>& ExternalReferenceRegistry::external_references() {
|
|
CHECK(!is_finalized_);
|
|
external_references_.push_back(reinterpret_cast<intptr_t>(nullptr));
|
|
is_finalized_ = true;
|
|
return external_references_;
|
|
}
|
|
|
|
ExternalReferenceRegistry::ExternalReferenceRegistry() {
|
|
#define V(modname) _register_external_reference_##modname(this);
|
|
EXTERNAL_REFERENCE_BINDING_LIST(V)
|
|
#undef V
|
|
// TODO(joyeecheung): collect more external references here.
|
|
}
|
|
|
|
} // namespace node
|