diff --git a/src/env-inl.h b/src/env-inl.h index b436b23b678015..4ef9665cbddfed 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -809,6 +809,22 @@ bool Environment::CleanupHookCallback::Equal::operator()( return a.fn_ == b.fn_ && a.arg_ == b.arg_; } +BaseObject* Environment::CleanupHookCallback::GetBaseObject() const { + if (fn_ == BaseObject::DeleteMe) + return static_cast(arg_); + else + return nullptr; +} + +template +void Environment::ForEachBaseObject(T&& iterator) { + for (const auto& hook : cleanup_hooks_) { + BaseObject* obj = hook.GetBaseObject(); + if (obj != nullptr) + iterator(obj); + } +} + #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) #define VS(PropertyName, StringValue) V(v8::String, PropertyName) diff --git a/src/env.h b/src/env.h index ea50d019c2327f..3f4ea83b5611fd 100644 --- a/src/env.h +++ b/src/env.h @@ -976,6 +976,8 @@ class Environment { inline bool operator()(const CleanupHookCallback& a, const CleanupHookCallback& b) const; }; + + inline BaseObject* GetBaseObject() const; }; // Use an unordered_set, so that we have efficient insertion and removal. @@ -988,6 +990,9 @@ class Environment { v8::Local promise, v8::Local parent); + template + void ForEachBaseObject(T&& iterator); + #define V(PropertyName, TypeName) Persistent PropertyName ## _; ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) #undef V