Skip to content

Commit e16a2be

Browse files
committed
src: avoid duplicate Before/AtExitCallback structs
Currently, BeforeExitCallback and AtExitCallback are identical apart for the name of the struct. This commit introduces an ExitCallback struct with can be used in both cases to avoid the duplication. PR-URL: nodejs#19226 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 695590e commit e16a2be

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/env.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,25 +293,25 @@ void Environment::PrintSyncTrace() const {
293293
}
294294

295295
void Environment::RunBeforeExitCallbacks() {
296-
for (BeforeExitCallback before_exit : before_exit_functions_) {
296+
for (ExitCallback before_exit : before_exit_functions_) {
297297
before_exit.cb_(before_exit.arg_);
298298
}
299299
before_exit_functions_.clear();
300300
}
301301

302302
void Environment::BeforeExit(void (*cb)(void* arg), void* arg) {
303-
before_exit_functions_.push_back(BeforeExitCallback{cb, arg});
303+
before_exit_functions_.push_back(ExitCallback{cb, arg});
304304
}
305305

306306
void Environment::RunAtExitCallbacks() {
307-
for (AtExitCallback at_exit : at_exit_functions_) {
307+
for (ExitCallback at_exit : at_exit_functions_) {
308308
at_exit.cb_(at_exit.arg_);
309309
}
310310
at_exit_functions_.clear();
311311
}
312312

313313
void Environment::AtExit(void (*cb)(void* arg), void* arg) {
314-
at_exit_functions_.push_back(AtExitCallback{cb, arg});
314+
at_exit_functions_.push_back(ExitCallback{cb, arg});
315315
}
316316

317317
void Environment::AddPromiseHook(promise_hook_func fn, void* arg) {

src/env.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,17 +823,13 @@ class Environment {
823823
static const int kFsStatsFieldsLength = 2 * 14;
824824
AliasedBuffer<double, v8::Float64Array> fs_stats_field_array_;
825825

826-
struct BeforeExitCallback {
826+
struct ExitCallback {
827827
void (*cb_)(void* arg);
828828
void* arg_;
829829
};
830-
std::list<BeforeExitCallback> before_exit_functions_;
830+
std::list<ExitCallback> before_exit_functions_;
831831

832-
struct AtExitCallback {
833-
void (*cb_)(void* arg);
834-
void* arg_;
835-
};
836-
std::list<AtExitCallback> at_exit_functions_;
832+
std::list<ExitCallback> at_exit_functions_;
837833

838834
struct PromiseHookCallback {
839835
promise_hook_func cb_;

0 commit comments

Comments
 (0)