mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
src: add an ExternalReferenceRegistry class
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>
This commit is contained in:
7 files changed
+114
-5
No files matched your search
@@ -0,0 +1,22 @@
|
||||
#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
|
||||
Reference in new issue
Block a user