@@ -739,6 +739,36 @@ class ShouldNotAbortOnUncaughtScope {
739739 Environment* env_;
740740};
741741
742+ class CleanupHookCallback {
743+ public:
744+ CleanupHookCallback (void (*fn)(void *),
745+ void * arg,
746+ uint64_t insertion_order_counter)
747+ : fn_(fn), arg_(arg), insertion_order_counter_(insertion_order_counter) {}
748+
749+ // Only hashes `arg_`, since that is usually enough to identify the hook.
750+ struct Hash {
751+ inline size_t operator ()(const CleanupHookCallback& cb) const ;
752+ };
753+
754+ // Compares by `fn_` and `arg_` being equal.
755+ struct Equal {
756+ inline bool operator ()(const CleanupHookCallback& a,
757+ const CleanupHookCallback& b) const ;
758+ };
759+
760+ inline BaseObject* GetBaseObject () const ;
761+
762+ private:
763+ friend class Environment ;
764+ void (*fn_)(void *);
765+ void * arg_;
766+
767+ // We keep track of the insertion order for these objects, so that we can
768+ // call the callbacks in reverse order when we are cleaning up.
769+ uint64_t insertion_order_counter_;
770+ };
771+
742772class Environment : public MemoryRetainer {
743773 public:
744774 Environment (const Environment&) = delete ;
@@ -1224,42 +1254,6 @@ class Environment : public MemoryRetainer {
12241254 void RunAndClearNativeImmediates ();
12251255 static void CheckImmediate (uv_check_t * handle);
12261256
1227- class CleanupHookCallback : public MemoryRetainer {
1228- public:
1229- CleanupHookCallback (void (*fn)(void *),
1230- void * arg,
1231- uint64_t insertion_order_counter)
1232- : fn_(fn),
1233- arg_ (arg),
1234- insertion_order_counter_(insertion_order_counter) {}
1235-
1236- // Only hashes `arg_`, since that is usually enough to identify the hook.
1237- struct Hash {
1238- inline size_t operator ()(const CleanupHookCallback& cb) const ;
1239- };
1240-
1241- // Compares by `fn_` and `arg_` being equal.
1242- struct Equal {
1243- inline bool operator ()(const CleanupHookCallback& a,
1244- const CleanupHookCallback& b) const ;
1245- };
1246-
1247- SET_MEMORY_INFO_NAME (CleanupHookCallback);
1248- SET_SELF_SIZE (CleanupHookCallback);
1249- void MemoryInfo (MemoryTracker* tracker) const override ;
1250-
1251- inline BaseObject* GetBaseObject () const ;
1252-
1253- private:
1254- friend class Environment ;
1255- void (*fn_)(void *);
1256- void * arg_;
1257-
1258- // We keep track of the insertion order for these objects, so that we can
1259- // call the callbacks in reverse order when we are cleaning up.
1260- uint64_t insertion_order_counter_;
1261- };
1262-
12631257 // Use an unordered_set, so that we have efficient insertion and removal.
12641258 std::unordered_set<CleanupHookCallback,
12651259 CleanupHookCallback::Hash,
0 commit comments