@@ -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,21 @@ 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 == 6 ) { // 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+ CHECK_EQ (argc, 5 );
2067+ FSReqWrapSync req_wrap_sync ( " write " ) ;
20682068 FS_SYNC_TRACE_BEGIN (write);
2069- int bytesWritten = SyncCall (env, args[ 6 ], &req_wrap_sync, " write " ,
2070- uv_fs_write, fd, &uvbuf, 1 , pos);
2069+ int bytesWritten = SyncCallAndThrowOnError (
2070+ env, &req_wrap_sync, uv_fs_write, fd, &uvbuf, 1 , pos);
20712071 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2072+ if (is_uv_error (bytesWritten)) {
2073+ return ;
2074+ }
20722075 args.GetReturnValue ().Set (bytesWritten);
20732076 }
20742077}
@@ -2205,9 +2208,8 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
22052208 } else {
22062209 req_wrap_async->SetReturnValue (args);
22072210 }
2208- } else { // write(fd, string, pos, enc, undefined, ctx)
2209- CHECK_EQ (argc, 6 );
2210- FSReqWrapSync req_wrap_sync;
2211+ } else { // write(fd, string, pos, enc)
2212+ FSReqWrapSync req_wrap_sync (" write" );
22112213 FSReqBase::FSReqBuffer stack_buffer;
22122214 if (buf == nullptr ) {
22132215 if (!StringBytes::StorageSize (isolate, value, enc).To (&len))
@@ -2222,9 +2224,12 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
22222224 }
22232225 uv_buf_t uvbuf = uv_buf_init (buf, len);
22242226 FS_SYNC_TRACE_BEGIN (write);
2225- int bytesWritten = SyncCall (env, args[ 5 ], &req_wrap_sync, " write " ,
2226- uv_fs_write, fd, &uvbuf, 1 , pos);
2227+ int bytesWritten = SyncCallAndThrowOnError (
2228+ env, &req_wrap_sync, uv_fs_write, fd, &uvbuf, 1 , pos);
22272229 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2230+ if (is_uv_error (bytesWritten)) {
2231+ return ;
2232+ }
22282233 args.GetReturnValue ().Set (bytesWritten);
22292234 }
22302235}
0 commit comments