Skip to content

Commit d42dbde

Browse files
addaleaxtargos
authored andcommitted
src: add iteration over all base objects to Environment
PR-URL: #21741 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 0298299 commit d42dbde

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/env-inl.h

+16
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,22 @@ bool Environment::CleanupHookCallback::Equal::operator()(
809809
return a.fn_ == b.fn_ && a.arg_ == b.arg_;
810810
}
811811

812+
BaseObject* Environment::CleanupHookCallback::GetBaseObject() const {
813+
if (fn_ == BaseObject::DeleteMe)
814+
return static_cast<BaseObject*>(arg_);
815+
else
816+
return nullptr;
817+
}
818+
819+
template <typename T>
820+
void Environment::ForEachBaseObject(T&& iterator) {
821+
for (const auto& hook : cleanup_hooks_) {
822+
BaseObject* obj = hook.GetBaseObject();
823+
if (obj != nullptr)
824+
iterator(obj);
825+
}
826+
}
827+
812828
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
813829
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
814830
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)

src/env.h

+5
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ class Environment {
976976
inline bool operator()(const CleanupHookCallback& a,
977977
const CleanupHookCallback& b) const;
978978
};
979+
980+
inline BaseObject* GetBaseObject() const;
979981
};
980982

981983
// Use an unordered_set, so that we have efficient insertion and removal.
@@ -988,6 +990,9 @@ class Environment {
988990
v8::Local<v8::Promise> promise,
989991
v8::Local<v8::Value> parent);
990992

993+
template <typename T>
994+
void ForEachBaseObject(T&& iterator);
995+
991996
#define V(PropertyName, TypeName) Persistent<TypeName> PropertyName ## _;
992997
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
993998
#undef V

0 commit comments

Comments
 (0)