From ef9964f4c183f062ca25337984a542895590141d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 20 Apr 2019 21:35:27 +0800 Subject: 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 Reviewed-By: Daniel Bevenius --- node.gyp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'node.gyp') diff --git a/node.gyp b/node.gyp index 36cc88c629a..acaf2cef8fb 100644 --- a/node.gyp +++ b/node.gyp @@ -593,6 +593,7 @@ 'src/node_dir.cc', 'src/node_env_var.cc', 'src/node_errors.cc', + 'src/node_external_reference.cc', 'src/node_file.cc', 'src/node_http_parser.cc', 'src/node_http2.cc', @@ -687,6 +688,7 @@ 'src/node_contextify.h', 'src/node_dir.h', 'src/node_errors.h', + 'src/node_external_reference.h', 'src/node_file.h', 'src/node_file-inl.h', 'src/node_http_common.h', -- cgit v1.2.3