mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
src: add iteration over all base objects to Environment
PR-URL: https://github.com/nodejs/node/pull/21741 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
2 files changed
+21
No files matched your search
@@ -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<BaseObject*>(arg_);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
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)
|
||||
|
||||
@@ -981,6 +981,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.
|
||||
@@ -993,6 +995,9 @@ class Environment {
|
||||
v8::Local<v8::Promise> promise,
|
||||
v8::Local<v8::Value> parent);
|
||||
|
||||
template <typename T>
|
||||
void ForEachBaseObject(T&& iterator);
|
||||
|
||||
#define V(PropertyName, TypeName) Persistent<TypeName> PropertyName ## _;
|
||||
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
|
||||
#undef V
|
||||
|
||||
Reference in new issue
Block a user