summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-06-10 15:57:46 +0200
committerAnna Henningsen <anna@addaleax.net>2018-07-15 20:35:29 +0200
commit4a58725c157b775f71ee13c441dac110ec60cf15 (patch)
tree92af4a001c21278b94e403544e9a8423a48239c4 /src
parente75163f73e6556d6b091167945ad1fa947f40be0 (diff)
downloadandroid-node-v8-4a58725c157b775f71ee13c441dac110ec60cf15.tar.gz
android-node-v8-4a58725c157b775f71ee13c441dac110ec60cf15.tar.bz2
android-node-v8-4a58725c157b775f71ee13c441dac110ec60cf15.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/env-inl.h16
-rw-r--r--src/env.h5
2 files changed, 21 insertions, 0 deletions
diff --git a/src/env-inl.h b/src/env-inl.h
index b47af18111..fccd45070c 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<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)
diff --git a/src/env.h b/src/env.h
index f6725e8e53..9bdf33bce0 100644
--- a/src/env.h
+++ b/src/env.h
@@ -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