Skip to content

Commit

Permalink
src: remove BeforeExit callback list
Browse files Browse the repository at this point in the history
It obscures the fact that there is only a single BeforeExit action.
Just call that statically from `EmitBeforeExit()`.

PR-URL: #33386
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
bnoordhuis authored and codebytere committed Jul 8, 2020
1 parent b599037 commit 77b6298
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/api/hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
20 changes: 0 additions & 20 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,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());
Expand Down Expand Up @@ -640,19 +633,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);
Expand Down
3 changes: 0 additions & 3 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,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();

Expand Down Expand Up @@ -1394,7 +1392,6 @@ class Environment : public MemoryRetainer {
void (*cb_)(void* arg);
void* arg_;
};
std::list<ExitCallback> before_exit_functions_;

std::list<ExitCallback> at_exit_functions_;

Expand Down

0 comments on commit 77b6298

Please sign in to comment.