@@ -2033,7 +2033,7 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
20332033 Environment* env = Environment::GetCurrent (args);
20342034
20352035 const int argc = args.Length ();
2036- CHECK_GE (argc, 4 );
2036+ CHECK_GE (argc, 5 );
20372037
20382038 CHECK (args[0 ]->IsInt32 ());
20392039 const int fd = args[0 ].As <Int32>()->Value ();
@@ -2060,18 +2060,20 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
20602060 char * buf = buffer_data + off;
20612061 uv_buf_t uvbuf = uv_buf_init (buf, len);
20622062
2063- FSReqBase* req_wrap_async = GetReqWrap (args, 5 );
2064- if ( req_wrap_async != nullptr ) { // write(fd, buffer, off, len, pos, req)
2063+ if (argc > 5 ) { // write(fd, buffer, off, len, pos, req)
2064+ FSReqBase* req_wrap_async = GetReqWrap (args, 5 );
20652065 FS_ASYNC_TRACE_BEGIN0 (UV_FS_WRITE, req_wrap_async)
20662066 AsyncCall (env, req_wrap_async, args, " write" , UTF8, AfterInteger,
20672067 uv_fs_write, fd, &uvbuf, 1 , pos);
2068- } else { // write(fd, buffer, off, len, pos, undefined, ctx)
2069- CHECK_EQ (argc, 7 );
2070- FSReqWrapSync req_wrap_sync;
2068+ } else { // write(fd, buffer, off, len, pos)
2069+ FSReqWrapSync req_wrap_sync (" write" );
20712070 FS_SYNC_TRACE_BEGIN (write);
2072- int bytesWritten = SyncCall (env, args[ 6 ], &req_wrap_sync, " write " ,
2073- uv_fs_write, fd, &uvbuf, 1 , pos);
2071+ int bytesWritten = SyncCallAndThrowOnError (
2072+ env, &req_wrap_sync, uv_fs_write, fd, &uvbuf, 1 , pos);
20742073 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2074+ if (is_uv_error (bytesWritten)) {
2075+ return ;
2076+ }
20752077 args.GetReturnValue ().Set (bytesWritten);
20762078 }
20772079}
@@ -2208,9 +2210,8 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
22082210 } else {
22092211 req_wrap_async->SetReturnValue (args);
22102212 }
2211- } else { // write(fd, string, pos, enc, undefined, ctx)
2212- CHECK_EQ (argc, 6 );
2213- FSReqWrapSync req_wrap_sync;
2213+ } else { // write(fd, string, pos, enc)
2214+ FSReqWrapSync req_wrap_sync (" write" );
22142215 FSReqBase::FSReqBuffer stack_buffer;
22152216 if (buf == nullptr ) {
22162217 if (!StringBytes::StorageSize (isolate, value, enc).To (&len))
@@ -2225,9 +2226,12 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
22252226 }
22262227 uv_buf_t uvbuf = uv_buf_init (buf, len);
22272228 FS_SYNC_TRACE_BEGIN (write);
2228- int bytesWritten = SyncCall (env, args[ 5 ], &req_wrap_sync, " write " ,
2229- uv_fs_write, fd, &uvbuf, 1 , pos);
2229+ int bytesWritten = SyncCallAndThrowOnError (
2230+ env, &req_wrap_sync, uv_fs_write, fd, &uvbuf, 1 , pos);
22302231 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2232+ if (is_uv_error (bytesWritten)) {
2233+ return ;
2234+ }
22312235 args.GetReturnValue ().Set (bytesWritten);
22322236 }
22332237}
0 commit comments