From 5b2067c6ca17340204c1de283baead174b071355 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 2 Nov 2019 20:41:48 +0100 Subject: 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 Reviewed-By: Franziska Hinkelmann Reviewed-By: Daniel Bevenius Reviewed-By: James M Snell --- test/addons/at-exit/binding.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'test/addons') diff --git a/test/addons/at-exit/binding.cc b/test/addons/at-exit/binding.cc index 3a27bcd7c3..b091c65ed9 100644 --- a/test/addons/at-exit/binding.cc +++ b/test/addons/at-exit/binding.cc @@ -3,7 +3,11 @@ #include #include +// TODO(addaleax): Maybe merge this file with the cctest for AtExit()? + using node::AtExit; +using node::Environment; +using node::GetCurrentEnvironment; using v8::HandleScope; using v8::Isolate; using v8::Local; @@ -46,9 +50,10 @@ NODE_C_DTOR(sanity_check) { } void init(Local exports) { - AtExit(at_exit_cb1, exports->GetIsolate()); - AtExit(at_exit_cb2, cookie); - AtExit(at_exit_cb2, cookie); + Environment* env = GetCurrentEnvironment(exports->CreationContext()); + AtExit(env, at_exit_cb1, exports->GetIsolate()); + AtExit(env, at_exit_cb2, cookie); + AtExit(env, at_exit_cb2, cookie); } NODE_MODULE(NODE_GYP_MODULE_NAME, init) -- cgit v1.2.3