| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7bfcf7c commit 4b5eb7b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,20 +22,21 @@ | |||
| 22 | 22 | #ifndef SRC_NODE_OBJECT_WRAP_H_ | |
| 23 | 23 | #define SRC_NODE_OBJECT_WRAP_H_ | |
| 24 | 24 | ||
| 25 | - #include "v8.h" | ||
| 26 | 25 | #include <cassert> | |
| 27 | - | ||
| 26 | + #include "node.h" | ||
| 28 | 27 | ||
| 29 | 28 | namespace node { | |
| 30 | 29 | ||
| 31 | 30 | class ObjectWrap { | |
| 32 | 31 | public: | |
| 33 | 32 | ObjectWrap() { | |
| 34 | 33 | refs_ = 0; | |
| 34 | + AddCleanupHook(); | ||
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | 38 | virtual ~ObjectWrap() { | |
| 39 | + RemoveCleanupHook(); | ||
| 39 | 40 | if (persistent().IsEmpty()) | |
| 40 | 41 | return; | |
| 41 | 42 | persistent().ClearWeak(); | |
@@ -123,6 +124,16 @@ class ObjectWrap { | |||
| 123 | 124 | delete wrap; | |
| 124 | 125 | } | |
| 125 | 126 | ||
| 127 | + void AddCleanupHook() { | ||
| 128 | + AddEnvironmentCleanupHook(v8::Isolate::GetCurrent(), CleanupHook, this); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + void RemoveCleanupHook() { | ||
| 132 | + RemoveEnvironmentCleanupHook(v8::Isolate::GetCurrent(), CleanupHook, this); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + static void CleanupHook(void* arg) { delete static_cast<ObjectWrap*>(arg); } | ||
| 136 | + | ||
| 126 | 137 | // NOLINTNEXTLINE(runtime/v8_persistent) | |
| 127 | 138 | v8::Persistent<v8::Object> handle_; | |
| 128 | 139 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments