@@ -2030,7 +2030,7 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
20302030 Environment* env = Environment::GetCurrent (args);
20312031
20322032 const int argc = args.Length ();
2033- CHECK_GE (argc, 4 );
2033+ CHECK_GE (argc, 5 );
20342034
20352035 CHECK (args[0 ]->IsInt32 ());
20362036 const int fd = args[0 ].As <Int32>()->Value ();
@@ -2057,18 +2057,20 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
20572057 char * buf = buffer_data + off;
20582058 uv_buf_t uvbuf = uv_buf_init (buf, len);
20592059
2060- FSReqBase* req_wrap_async = GetReqWrap (args, 5 );
2061- if ( req_wrap_async != nullptr ) { // write(fd, buffer, off, len, pos, req)
2060+ if (argc > 5 ) { // write(fd, buffer, off, len, pos, req)
2061+ FSReqBase* req_wrap_async = GetReqWrap (args, 5 );
20622062 FS_ASYNC_TRACE_BEGIN0 (UV_FS_WRITE, req_wrap_async)
20632063 AsyncCall (env, req_wrap_async, args, " write" , UTF8, AfterInteger,
20642064 uv_fs_write, fd, &uvbuf, 1 , pos);
2065- } else { // write(fd, buffer, off, len, pos, undefined, ctx)
2066- CHECK_EQ (argc, 7 );
2067- FSReqWrapSync req_wrap_sync;
2065+ } else { // write(fd, buffer, off, len, pos)
2066+ FSReqWrapSync req_wrap_sync (" write" );
20682067 FS_SYNC_TRACE_BEGIN (write);
2069- int bytesWritten = SyncCall (env, args[ 6 ], &req_wrap_sync, " write " ,
2070- uv_fs_write, fd, &uvbuf, 1 , pos);
2068+ int bytesWritten = SyncCallAndThrowOnError (
2069+ env, &req_wrap_sync, uv_fs_write, fd, &uvbuf, 1 , pos);
20712070 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2071+ if (is_uv_error (bytesWritten)) {
2072+ return ;
2073+ }
20722074 args.GetReturnValue ().Set (bytesWritten);
20732075 }
20742076}
@@ -2205,9 +2207,8 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
22052207 } else {
22062208 req_wrap_async->SetReturnValue (args);
22072209 }
2208- } else { // write(fd, string, pos, enc, undefined, ctx)
2209- CHECK_EQ (argc, 6 );
2210- FSReqWrapSync req_wrap_sync;
2210+ } else { // write(fd, string, pos, enc)
2211+ FSReqWrapSync req_wrap_sync (" write" );
22112212 FSReqBase::FSReqBuffer stack_buffer;
22122213 if (buf == nullptr ) {
22132214 if (!StringBytes::StorageSize (isolate, value, enc).To (&len))
@@ -2222,9 +2223,12 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
22222223 }
22232224 uv_buf_t uvbuf = uv_buf_init (buf, len);
22242225 FS_SYNC_TRACE_BEGIN (write);
2225- int bytesWritten = SyncCall (env, args[ 5 ], &req_wrap_sync, " write " ,
2226- uv_fs_write, fd, &uvbuf, 1 , pos);
2226+ int bytesWritten = SyncCallAndThrowOnError (
2227+ env, &req_wrap_sync, uv_fs_write, fd, &uvbuf, 1 , pos);
22272228 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2229+ if (is_uv_error (bytesWritten)) {
2230+ return ;
2231+ }
22282232 args.GetReturnValue ().Set (bytesWritten);
22292233 }
22302234}
0 commit comments