@@ -18,13 +18,11 @@ namespace node {
18
18
19
19
using v8::Array;
20
20
using v8::ArrayBuffer;
21
- using v8::Boolean ;
22
21
using v8::Context;
23
22
using v8::FunctionCallbackInfo;
24
23
using v8::HandleScope;
25
24
using v8::Integer;
26
25
using v8::Local;
27
- using v8::Number;
28
26
using v8::Object;
29
27
using v8::String;
30
28
using v8::Value;
@@ -56,18 +54,9 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) {
56
54
return Shutdown (req_wrap_obj);
57
55
}
58
56
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 ;
71
60
}
72
61
73
62
int StreamBase::Writev (const FunctionCallbackInfo<Value>& args) {
@@ -160,7 +149,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
160
149
}
161
150
162
151
StreamWriteResult res = Write (*bufs, count, nullptr , req_wrap_obj);
163
- SetWriteResultPropertiesOnWrapObject (env, req_wrap_obj, res);
152
+ SetWriteResult ( res);
164
153
if (res.wrap != nullptr && storage_size > 0 ) {
165
154
res.wrap ->SetAllocatedStorage (storage.release (), storage_size);
166
155
}
@@ -185,10 +174,7 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
185
174
buf.len = Buffer::Length (args[1 ]);
186
175
187
176
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);
192
178
193
179
return res.err ;
194
180
}
@@ -247,12 +233,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
247
233
248
234
// Immediate failure or success
249
235
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 });
256
237
return err;
257
238
}
258
239
@@ -295,7 +276,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
295
276
StreamWriteResult res = Write (&buf, 1 , send_handle, req_wrap_obj);
296
277
res.bytes += synchronously_written;
297
278
298
- SetWriteResultPropertiesOnWrapObject (env, req_wrap_obj, res);
279
+ SetWriteResult ( res);
299
280
if (res.wrap != nullptr ) {
300
281
res.wrap ->SetAllocatedStorage (data.release (), data_size);
301
282
}
0 commit comments