Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e6f0680

Browse filesBrowse files
addaleaxtargos
authored andcommitted
src: simplify handle closing
Remove one extra closing state and use a smart pointer for deleting `HandleWrap`s. PR-URL: #20876 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
1 parent 65924c7 commit e6f0680
Copy full SHA for e6f0680

File tree

Expand file treeCollapse file tree

2 files changed

+8
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-10
lines changed
Open diff view settings
Collapse file

‎src/handle_wrap.cc‎

Copy file name to clipboardExpand all lines: src/handle_wrap.cc
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
6767
wrap->Close(args[0]);
6868
}
6969

70-
void HandleWrap::Close(v8::Local<v8::Value> close_callback) {
70+
void HandleWrap::Close(Local<Value> close_callback) {
7171
if (state_ != kInitialized)
7272
return;
7373

@@ -77,8 +77,7 @@ void HandleWrap::Close(v8::Local<v8::Value> close_callback) {
7777

7878
if (!close_callback.IsEmpty() && close_callback->IsFunction()) {
7979
object()->Set(env()->context(), env()->onclose_string(), close_callback)
80-
.FromJust();
81-
state_ = kClosingWithCallback;
80+
.FromMaybe(false);
8281
}
8382
}
8483

@@ -109,24 +108,23 @@ HandleWrap::HandleWrap(Environment* env,
109108

110109

111110
void HandleWrap::OnClose(uv_handle_t* handle) {
112-
HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
111+
std::unique_ptr<HandleWrap> wrap { static_cast<HandleWrap*>(handle->data) };
113112
Environment* env = wrap->env();
114113
HandleScope scope(env->isolate());
115114
Context::Scope context_scope(env->context());
116115

117116
// The wrap object should still be there.
118117
CHECK_EQ(wrap->persistent().IsEmpty(), false);
119-
CHECK(wrap->state_ >= kClosing && wrap->state_ <= kClosingWithCallback);
118+
CHECK_EQ(wrap->state_, kClosing);
120119

121-
const bool have_close_callback = (wrap->state_ == kClosingWithCallback);
122120
wrap->state_ = kClosed;
123121

124122
wrap->OnClose();
125123

126-
if (have_close_callback)
124+
if (wrap->object()->Has(env->context(), env->onclose_string())
125+
.FromMaybe(false)) {
127126
wrap->MakeCallback(env->onclose_string(), 0, nullptr);
128-
129-
delete wrap;
127+
}
130128
}
131129

132130

Collapse file

‎src/handle_wrap.h‎

Copy file name to clipboardExpand all lines: src/handle_wrap.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class HandleWrap : public AsyncWrap {
9595
// refer to `doc/guides/node-postmortem-support.md`
9696
friend int GenDebugSymbols();
9797
ListNode<HandleWrap> handle_wrap_queue_;
98-
enum { kInitialized, kClosing, kClosingWithCallback, kClosed } state_;
98+
enum { kInitialized, kClosing, kClosed } state_;
9999
uv_handle_t* const handle_;
100100
};
101101

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.