diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-02-23 15:21:48 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-03-02 12:58:20 +0000 |
commit | 7cadb57e0c0459d3c60712744d1519eafc49b556 (patch) | |
tree | 783e1b712d77ac16f9be171e254698783d3ca27b /src/stream_base.cc | |
parent | 16facd7ef48b9d43af02009524983b05901dc26b (diff) | |
download | android-node-v8-7cadb57e0c0459d3c60712744d1519eafc49b556.tar.gz android-node-v8-7cadb57e0c0459d3c60712744d1519eafc49b556.tar.bz2 android-node-v8-7cadb57e0c0459d3c60712744d1519eafc49b556.zip |
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src/stream_base.cc')
-rw-r--r-- | src/stream_base.cc | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/stream_base.cc b/src/stream_base.cc index 9ad9fd5bcb..1d1d324841 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<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); @@ -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); } @@ -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; } @@ -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); } |