diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-11-06 00:50:24 +0300 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-11-17 10:59:11 +0300 |
commit | b744070d74c710ea884512cb2998e7f2bb837a2c (patch) | |
tree | 6c1b2f2774e523b503b1d8696cf1db0dbd4ae7c0 /src/api | |
parent | de68720908bc783cadd811e84de7837fb4fa6759 (diff) |
src: allow adding linked bindings to Environment
This allows manually adding linked bindings to an `Environment`
instance, without having to register modules at program load in
a global namespace.
PR-URL: https://github.com/nodejs/node/pull/30274
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/environment.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/api/environment.cc b/src/api/environment.cc index 846e4a873da..4cb2da4b860 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -498,4 +498,32 @@ uv_loop_t* GetCurrentEventLoop(Isolate* isolate) { return env->event_loop(); } +void AddLinkedBinding(Environment* env, const node_module& mod) { + CHECK_NOT_NULL(env); + Mutex::ScopedLock lock(env->extra_linked_bindings_mutex()); + + node_module* prev_head = env->extra_linked_bindings_head(); + env->extra_linked_bindings()->push_back(mod); + if (prev_head != nullptr) + prev_head->nm_link = &env->extra_linked_bindings()->back(); +} + +void AddLinkedBinding(Environment* env, + const char* name, + addon_context_register_func fn, + void* priv) { + node_module mod = { + NODE_MODULE_VERSION, + NM_F_LINKED, + nullptr, // nm_dso_handle + nullptr, // nm_filename + nullptr, // nm_register_func + fn, + name, + priv, + nullptr // nm_link + }; + AddLinkedBinding(env, mod); +} + } // namespace node |