Skip to content

Commit f49cef5

Browse files
committed
src: add typedef for CleanupHookCallback callback
This commit adds a typedef for the callback parameter used in CleanupHookCallback's constructor, AddCleanupHook, and RemoveCleanupHook. PR-URL: #36442 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 7e5bf48 commit f49cef5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/env-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,15 +1024,15 @@ inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> that,
10241024
t->SetClassName(name_string);
10251025
}
10261026

1027-
void Environment::AddCleanupHook(void (*fn)(void*), void* arg) {
1027+
void Environment::AddCleanupHook(CleanupCallback fn, void* arg) {
10281028
auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback {
10291029
fn, arg, cleanup_hook_counter_++
10301030
});
10311031
// Make sure there was no existing element with these values.
10321032
CHECK_EQ(insertion_info.second, true);
10331033
}
10341034

1035-
void Environment::RemoveCleanupHook(void (*fn)(void*), void* arg) {
1035+
void Environment::RemoveCleanupHook(CleanupCallback fn, void* arg) {
10361036
CleanupHookCallback search { fn, arg, 0 };
10371037
cleanup_hooks_.erase(search);
10381038
}

src/env.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,9 @@ class ShouldNotAbortOnUncaughtScope {
891891

892892
class CleanupHookCallback {
893893
public:
894-
CleanupHookCallback(void (*fn)(void*),
894+
typedef void (*Callback)(void*);
895+
896+
CleanupHookCallback(Callback fn,
895897
void* arg,
896898
uint64_t insertion_order_counter)
897899
: fn_(fn), arg_(arg), insertion_order_counter_(insertion_order_counter) {}
@@ -911,7 +913,7 @@ class CleanupHookCallback {
911913

912914
private:
913915
friend class Environment;
914-
void (*fn_)(void*);
916+
Callback fn_;
915917
void* arg_;
916918

917919
// We keep track of the insertion order for these objects, so that we can
@@ -1316,8 +1318,9 @@ class Environment : public MemoryRetainer {
13161318
void ScheduleTimer(int64_t duration);
13171319
void ToggleTimerRef(bool ref);
13181320

1319-
inline void AddCleanupHook(void (*fn)(void*), void* arg);
1320-
inline void RemoveCleanupHook(void (*fn)(void*), void* arg);
1321+
using CleanupCallback = CleanupHookCallback::Callback;
1322+
inline void AddCleanupHook(CleanupCallback cb, void* arg);
1323+
inline void RemoveCleanupHook(CleanupCallback cb, void* arg);
13211324
void RunCleanup();
13221325

13231326
static size_t NearHeapLimitCallback(void* data,

0 commit comments

Comments
 (0)