From d1e1dbf188821fc8cb071ad9122b9a656de23ad6 Mon Sep 17 00:00:00 2001
From: Ben Noordhuis <info@bnoordhuis.nl>
Date: Sat, 16 May 2020 11:39:53 +0200
Subject: [PATCH] src: remove BeforeExit callback list

It obscures the fact that there is only a single BeforeExit action.
Just call that statically from `EmitBeforeExit()`.

PR-URL: https://github.com/nodejs/node/pull/33386
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
---
 src/api/hooks.cc |  5 ++++-
 src/env.cc       | 20 --------------------
 src/env.h        |  3 ---
 3 files changed, 4 insertions(+), 24 deletions(-)

diff --git a/src/api/hooks.cc b/src/api/hooks.cc
index 2dd0cc994ea7f2..d0113670457401 100644
--- a/src/api/hooks.cc
+++ b/src/api/hooks.cc
@@ -30,7 +30,10 @@ void AtExit(Environment* env, void (*cb)(void* arg), void* arg) {
 }
 
 void EmitBeforeExit(Environment* env) {
-  env->RunBeforeExitCallbacks();
+  TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
+                              "BeforeExit", env);
+  if (!env->destroy_async_id_list()->empty())
+    AsyncWrap::DestroyAsyncIdsCallback(env);
 
   HandleScope handle_scope(env->isolate());
   Context::Scope context_scope(env->context());
diff --git a/src/env.cc b/src/env.cc
index 8214936d794101..4e7c975902b091 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -373,13 +373,6 @@ Environment::Environment(IsolateData* isolate_data,
   }
 
   destroy_async_id_list_.reserve(512);
-  BeforeExit(
-      [](void* arg) {
-        Environment* env = static_cast<Environment*>(arg);
-        if (!env->destroy_async_id_list()->empty())
-          AsyncWrap::DestroyAsyncIdsCallback(env);
-      },
-      this);
 
   performance_state_ =
       std::make_unique<performance::PerformanceState>(isolate());
@@ -677,19 +670,6 @@ void Environment::RunCleanup() {
   }
 }
 
-void Environment::RunBeforeExitCallbacks() {
-  TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
-                              "BeforeExit", this);
-  for (ExitCallback before_exit : before_exit_functions_) {
-    before_exit.cb_(before_exit.arg_);
-  }
-  before_exit_functions_.clear();
-}
-
-void Environment::BeforeExit(void (*cb)(void* arg), void* arg) {
-  before_exit_functions_.push_back(ExitCallback{cb, arg});
-}
-
 void Environment::RunAtExitCallbacks() {
   TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
                               "AtExit", this);
diff --git a/src/env.h b/src/env.h
index ff6f389ce55c56..5536f21268fb7b 100644
--- a/src/env.h
+++ b/src/env.h
@@ -1101,8 +1101,6 @@ class Environment : public MemoryRetainer {
                                          const char* name,
                                          v8::FunctionCallback callback);
 
-  void BeforeExit(void (*cb)(void* arg), void* arg);
-  void RunBeforeExitCallbacks();
   void AtExit(void (*cb)(void* arg), void* arg);
   void RunAtExitCallbacks();
 
@@ -1359,7 +1357,6 @@ class Environment : public MemoryRetainer {
     void (*cb_)(void* arg);
     void* arg_;
   };
-  std::list<ExitCallback> before_exit_functions_;
 
   std::list<ExitCallback> at_exit_functions_;