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>2019-09-29 02:29:07 +0300
committerMyles Borins <mylesborins@google.com>2019-11-21 08:29:26 +0300
commita2dbadc1cee69ad38b6d75c8328d1a89347c3fec (patch)
treebfdd93a9a6459617ed88113fe24e5523b64cd830 /src/handle_wrap.cc
parent1a92c884185bc3e01c6d64aae55ea5a947d82840 (diff)
src: introduce custom smart pointers for `BaseObject`s
Referring to `BaseObject` instances using standard C++ smart pointers can interfere with BaseObject’s own cleanup mechanisms (explicit delete, delete-on-GC and delete-on-cleanup). Introducing custom smart pointers allows referring to `BaseObject`s safely while keeping those mechanisms intact. Refs: https://github.com/nodejs/quic/pull/141 Refs: https://github.com/nodejs/quic/pull/149 Reviewed-By: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/30374 Refs: https://github.com/nodejs/quic/pull/165 Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/handle_wrap.cc')
-rw-r--r--src/handle_wrap.cc14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc
index fc84ca19bb2..f3a35557541 100644
--- a/src/handle_wrap.cc
+++ b/src/handle_wrap.cc
@@ -84,14 +84,8 @@ void HandleWrap::Close(Local<Value> close_callback) {
}
-void HandleWrap::MakeWeak() {
- persistent().SetWeak(
- this,
- [](const v8::WeakCallbackInfo<HandleWrap>& data) {
- HandleWrap* handle_wrap = data.GetParameter();
- handle_wrap->persistent().Reset();
- handle_wrap->Close();
- }, v8::WeakCallbackType::kParameter);
+void HandleWrap::OnGCCollect() {
+ Close();
}
@@ -122,7 +116,9 @@ HandleWrap::HandleWrap(Environment* env,
void HandleWrap::OnClose(uv_handle_t* handle) {
- std::unique_ptr<HandleWrap> wrap { static_cast<HandleWrap*>(handle->data) };
+ BaseObjectPtr<HandleWrap> wrap { static_cast<HandleWrap*>(handle->data) };
+ wrap->Detach();
+
Environment* env = wrap->env();
HandleScope scope(env->isolate());
Context::Scope context_scope(env->context());