diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index c864feb9270b52..81adf7a866b927 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -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 }; } diff --git a/src/stream_base.cc b/src/stream_base.cc index 9ad9fd5bcb4a46..1d1d324841537f 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -14,6 +14,7 @@ namespace node { using v8::Array; +using v8::Boolean; using v8::Context; using v8::FunctionCallbackInfo; using v8::HandleScope; @@ -56,6 +57,20 @@ int StreamBase::Shutdown(const FunctionCallbackInfo& args) { return Shutdown(req_wrap_obj); } +inline void SetWriteResultPropertiesOnWrapObject( + Environment* env, + Local 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& args) { Environment* env = Environment::GetCurrent(args); @@ -150,7 +165,7 @@ int StreamBase::Writev(const FunctionCallbackInfo& 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); } @@ -178,9 +193,7 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo& 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; } @@ -286,10 +299,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo& 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); }