@@ -18,13 +18,11 @@ namespace node {
1818
1919using v8::Array;
2020using v8::ArrayBuffer;
21- using v8::Boolean;
2221using v8::Context;
2322using v8::FunctionCallbackInfo;
2423using v8::HandleScope;
2524using v8::Integer;
2625using v8::Local;
27- using v8::Number;
2826using v8::Object;
2927using v8::String;
3028using v8::Value;
@@ -56,18 +54,9 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) {
5654 return Shutdown (req_wrap_obj);
5755}
5856
59- inline void SetWriteResultPropertiesOnWrapObject (
60- Environment* env,
61- Local<Object> req_wrap_obj,
62- const StreamWriteResult& res) {
63- req_wrap_obj->Set (
64- env->context (),
65- env->bytes_string (),
66- Number::New (env->isolate (), res.bytes )).FromJust ();
67- req_wrap_obj->Set (
68- env->context (),
69- env->async (),
70- Boolean::New (env->isolate (), res.async )).FromJust ();
57+ void StreamBase::SetWriteResult (const StreamWriteResult& res) {
58+ env_->stream_base_state ()[kBytesWritten ] = res.bytes ;
59+ env_->stream_base_state ()[kLastWriteWasAsync ] = res.async ;
7160}
7261
7362int StreamBase::Writev (const FunctionCallbackInfo<Value>& args) {
@@ -160,7 +149,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
160149 }
161150
162151 StreamWriteResult res = Write (*bufs, count, nullptr , req_wrap_obj);
163- SetWriteResultPropertiesOnWrapObject (env, req_wrap_obj, res);
152+ SetWriteResult ( res);
164153 if (res.wrap != nullptr && storage_size > 0 ) {
165154 res.wrap ->SetAllocatedStorage (storage.release (), storage_size);
166155 }
@@ -185,10 +174,7 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
185174 buf.len = Buffer::Length (args[1 ]);
186175
187176 StreamWriteResult res = Write (&buf, 1 , nullptr , req_wrap_obj);
188-
189- if (res.async )
190- req_wrap_obj->Set (env->context (), env->buffer_string (), args[1 ]).FromJust ();
191- SetWriteResultPropertiesOnWrapObject (env, req_wrap_obj, res);
177+ SetWriteResult (res);
192178
193179 return res.err ;
194180}
@@ -247,12 +233,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
247233
248234 // Immediate failure or success
249235 if (err != 0 || count == 0 ) {
250- req_wrap_obj->Set (env->context (), env->async (), False (env->isolate ()))
251- .FromJust ();
252- req_wrap_obj->Set (env->context (),
253- env->bytes_string (),
254- Integer::NewFromUnsigned (env->isolate (), data_size))
255- .FromJust ();
236+ SetWriteResult (StreamWriteResult { false , err, nullptr , data_size });
256237 return err;
257238 }
258239
@@ -295,7 +276,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
295276 StreamWriteResult res = Write (&buf, 1 , send_handle, req_wrap_obj);
296277 res.bytes += synchronously_written;
297278
298- SetWriteResultPropertiesOnWrapObject (env, req_wrap_obj, res);
279+ SetWriteResult ( res);
299280 if (res.wrap != nullptr ) {
300281 res.wrap ->SetAllocatedStorage (data.release (), data_size);
301282 }
0 commit comments