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 08b83ee

Browse filesBrowse files
committed
src: refactor setting JS properties on WriteWrap
`async` and `bytes` are only interesting when the write is coming from JS, and unnecessary otherwise. Also, make all of the stream `Write*()` bindings use the same code for setting these, and upgrade to the non-deprecated versions. PR-URL: #18963 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 8d595bb commit 08b83ee
Copy full SHA for 08b83ee

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

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

‎src/stream_base-inl.h‎

Copy file name to clipboardExpand all lines: src/stream_base-inl.h
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ inline StreamWriteResult StreamBase::Write(
220220
ClearError();
221221
}
222222

223-
req_wrap_obj->Set(env->async(), v8::Boolean::New(env->isolate(), async));
224-
225223
return StreamWriteResult { async, err, req_wrap };
226224
}
227225

Collapse file

‎src/stream_base.cc‎

Copy file name to clipboardExpand all lines: src/stream_base.cc
+18-8Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace node {
1515

1616
using v8::Array;
17+
using v8::Boolean;
1718
using v8::Context;
1819
using v8::FunctionCallbackInfo;
1920
using v8::HandleScope;
@@ -56,6 +57,20 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) {
5657
return Shutdown(req_wrap_obj);
5758
}
5859

60+
inline void SetWriteResultPropertiesOnWrapObject(
61+
Environment* env,
62+
Local<Object> req_wrap_obj,
63+
const StreamWriteResult& res,
64+
size_t bytes) {
65+
req_wrap_obj->Set(
66+
env->context(),
67+
env->bytes_string(),
68+
Number::New(env->isolate(), bytes)).FromJust();
69+
req_wrap_obj->Set(
70+
env->context(),
71+
env->async(),
72+
Boolean::New(env->isolate(), res.async)).FromJust();
73+
}
5974

6075
int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
6176
Environment* env = Environment::GetCurrent(args);
@@ -150,7 +165,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
150165
}
151166

152167
StreamWriteResult res = Write(*bufs, count, nullptr, req_wrap_obj);
153-
req_wrap_obj->Set(env->bytes_string(), Number::New(env->isolate(), bytes));
168+
SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res, bytes);
154169
if (res.wrap != nullptr && storage) {
155170
res.wrap->SetAllocatedStorage(storage.release(), storage_size);
156171
}
@@ -178,9 +193,7 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
178193

179194
if (res.async)
180195
req_wrap_obj->Set(env->context(), env->buffer_string(), args[1]).FromJust();
181-
req_wrap_obj->Set(env->context(), env->bytes_string(),
182-
Integer::NewFromUnsigned(env->isolate(), buf.len))
183-
.FromJust();
196+
SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res, buf.len);
184197

185198
return res.err;
186199
}
@@ -286,10 +299,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
286299

287300
StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj);
288301

289-
req_wrap_obj->Set(env->context(), env->bytes_string(),
290-
Integer::NewFromUnsigned(env->isolate(), data_size))
291-
.FromJust();
292-
302+
SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res, data_size);
293303
if (res.wrap != nullptr) {
294304
res.wrap->SetAllocatedStorage(data.release(), data_size);
295305
}

0 commit comments

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