Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-10-03 23:44:55 +0300
committerAnna Henningsen <anna@addaleax.net>2020-10-06 14:26:33 +0300
commit78e58755f71d7d59901de1c7e2712cebe4de0ef1 (patch)
tree8b7a55e28352f785718297009975e76517d0b11f /src/stream_base-inl.h
parentfb2f3cc828e47215ab5dbcc1e5bb911b0cde9e38 (diff)
http2,tls: store WriteWrap using BaseObjectPtr
Create weak `WriteWrap` and `ShutdownWrap` objects, and when referencing them in C++ is necessary, use `BaseObjectPtr<>` instead of plain pointers to keep these objects from being garbage-collected. This solves issues that arise when the underlying `StreamBase` instance is weak, but the `WriteWrap` or `ShutdownWrap` instances are not; in that case, they would otherwise potentially stick around in memory after the stream that they originally belong to is long gone. It probably makes sense to use `BaseObjectptr<>` more extensively in `StreamBase` in the long run as well. PR-URL: https://github.com/nodejs/node/pull/35488 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r--src/stream_base-inl.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h
index bd7224e9c02..c003ffc1ef6 100644
--- a/src/stream_base-inl.h
+++ b/src/stream_base-inl.h
@@ -243,6 +243,28 @@ StreamBase* StreamBase::FromObject(v8::Local<v8::Object> obj) {
StreamBase::kStreamBaseField));
}
+WriteWrap* WriteWrap::FromObject(v8::Local<v8::Object> req_wrap_obj) {
+ return static_cast<WriteWrap*>(StreamReq::FromObject(req_wrap_obj));
+}
+
+template <typename T, bool kIsWeak>
+WriteWrap* WriteWrap::FromObject(
+ const BaseObjectPtrImpl<T, kIsWeak>& base_obj) {
+ if (!base_obj) return nullptr;
+ return FromObject(base_obj->object());
+}
+
+ShutdownWrap* ShutdownWrap::FromObject(v8::Local<v8::Object> req_wrap_obj) {
+ return static_cast<ShutdownWrap*>(StreamReq::FromObject(req_wrap_obj));
+}
+
+template <typename T, bool kIsWeak>
+ShutdownWrap* ShutdownWrap::FromObject(
+ const BaseObjectPtrImpl<T, kIsWeak>& base_obj) {
+ if (!base_obj) return nullptr;
+ return FromObject(base_obj->object());
+}
+
void WriteWrap::SetAllocatedStorage(AllocatedBuffer&& storage) {
CHECK_NULL(storage_.data());
storage_ = std::move(storage);