Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: refactor setting JS properties on WriteWrap #18963

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/stream_base-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ inline StreamWriteResult StreamBase::Write(
ClearError();
}

req_wrap_obj->Set(env->async(), v8::Boolean::New(env->isolate(), async));

return StreamWriteResult { async, err, req_wrap };
}

Expand Down
26 changes: 18 additions & 8 deletions src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace node {

using v8::Array;
using v8::Boolean;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
Expand Down Expand Up @@ -56,6 +57,20 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) {
return Shutdown(req_wrap_obj);
}

inline void SetWriteResultPropertiesOnWrapObject(
Environment* env,
Local<Object> req_wrap_obj,
const StreamWriteResult& res,
size_t bytes) {
req_wrap_obj->Set(
env->context(),
env->bytes_string(),
Number::New(env->isolate(), bytes)).FromJust();
req_wrap_obj->Set(
env->context(),
env->async(),
Boolean::New(env->isolate(), res.async)).FromJust();
}

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

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

if (res.async)
req_wrap_obj->Set(env->context(), env->buffer_string(), args[1]).FromJust();
req_wrap_obj->Set(env->context(), env->bytes_string(),
Integer::NewFromUnsigned(env->isolate(), buf.len))
.FromJust();
SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res, buf.len);

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

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

req_wrap_obj->Set(env->context(), env->bytes_string(),
Integer::NewFromUnsigned(env->isolate(), data_size))
.FromJust();

SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res, data_size);
if (res.wrap != nullptr) {
res.wrap->SetAllocatedStorage(data.release(), data_size);
}
Expand Down