Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-11-02 22:41:48 +0300
committerMyles Borins <mylesborins@google.com>2019-11-17 10:59:06 +0300
commitcd6d6215ccb15bfe8491267033b2b86abfde212c (patch)
treea80b177659788ddf74521963bf6cd2114281e8d8 /src/node.h
parentc254d7469df9ba7adff2e90a611b5553da25c8ab (diff)
src: deprecate two- and one-argument AtExit()
Using `AtExit()` without an `Environment*` pointer or providing an argument is almost always a sign of improperly relying on global state and/or using `AtExit()` as an addon when the addon-targeting `AddEnvironmentCleanupHook()` would be the better choice. Deprecate those variants. This also updates the addon docs to refer to `AddEnvironmentCleanupHook()` rather than `AtExit()`. PR-URL: https://github.com/nodejs/node/pull/30227 Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node.h')
-rw-r--r--src/node.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/node.h b/src/node.h
index ea5d8a20a41..8215552227a 100644
--- a/src/node.h
+++ b/src/node.h
@@ -670,8 +670,13 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
/* Called after the event loop exits but before the VM is disposed.
* Callbacks are run in reverse order of registration, i.e. newest first.
+ *
+ * You should always use the three-argument variant (or, for addons,
+ * AddEnvironmentCleanupHook) in order to avoid relying on global state.
*/
-NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = nullptr);
+NODE_DEPRECATED(
+ "Use the three-argument variant of AtExit() or AddEnvironmentCleanupHook()",
+ NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = nullptr));
/* Registers a callback with the passed-in Environment instance. The callback
* is called after the event loop exits, but before the VM is disposed.
@@ -679,7 +684,13 @@ NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = nullptr);
*/
NODE_EXTERN void AtExit(Environment* env,
void (*cb)(void* arg),
- void* arg = nullptr);
+ void* arg);
+NODE_DEPRECATED(
+ "Use the three-argument variant of AtExit() or AddEnvironmentCleanupHook()",
+ inline void AtExit(Environment* env,
+ void (*cb)(void* arg)) {
+ AtExit(env, cb, nullptr);
+ })
typedef double async_id;
struct async_context {