GeezerVison is showing github.com — src: add iteration over all base objects to Environment · nodejs/node@d42dbde
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/env-inl.h +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -809,6 +809,22 @@ bool Environment::CleanupHookCallback::Equal::operator()( |
809 | 809 | return a.fn_ == b.fn_ && a.arg_ == b.arg_; |
810 | 810 | } |
811 | 811 |
|
| 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 | + |
812 | 828 | #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) |
813 | 829 | #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) |
814 | 830 | #define VS(PropertyName, StringValue) V(v8::String, PropertyName) |
|
Collapse file
Copy file name to clipboardExpand all lines: src/env.h +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -976,6 +976,8 @@ class Environment { |
976 | 976 | inline bool operator()(const CleanupHookCallback& a, |
977 | 977 | const CleanupHookCallback& b) const; |
978 | 978 | }; |
| 979 | + |
| 980 | + inline BaseObject* GetBaseObject() const; |
979 | 981 | }; |
980 | 982 |
|
981 | 983 | // Use an unordered_set, so that we have efficient insertion and removal. |
@@ -988,6 +990,9 @@ class Environment { |
988 | 990 | v8::Local<v8::Promise> promise, |
989 | 991 | v8::Local<v8::Value> parent); |
990 | 992 |
|
| 993 | + template <typename T> |
| 994 | + void ForEachBaseObject(T&& iterator); |
| 995 | + |
991 | 996 | #define V(PropertyName, TypeName) Persistent<TypeName> PropertyName ## _; |
992 | 997 | ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) |
993 | 998 | #undef V |
|