@@ -2031,7 +2031,7 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
20312031 Environment* env = Environment::GetCurrent (args);
20322032
20332033 const int argc = args.Length ();
2034- CHECK_GE (argc, 4 );
2034+ CHECK_GE (argc, 5 );
20352035
20362036 CHECK (args[0 ]->IsInt32 ());
20372037 const int fd = args[0 ].As <Int32>()->Value ();
@@ -2058,18 +2058,22 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
20582058 char * buf = buffer_data + off;
20592059 uv_buf_t uvbuf = uv_buf_init (buf, len);
20602060
2061- FSReqBase* req_wrap_async = GetReqWrap (args, 5 );
2062- if ( req_wrap_async != nullptr ) { // write(fd, buffer, off, len, pos, req)
2061+ if (argc > 5 ) { // write(fd, buffer, off, len, pos, req)
2062+ FSReqBase* req_wrap_async = GetReqWrap (args, 5 );
20632063 FS_ASYNC_TRACE_BEGIN0 (UV_FS_WRITE, req_wrap_async)
20642064 AsyncCall (env, req_wrap_async, args, " write" , UTF8, AfterInteger,
20652065 uv_fs_write, fd, &uvbuf, 1 , pos);
2066- } else { // write(fd, buffer, off, len, pos, undefined, ctx)
2067- CHECK_EQ (argc, 7 );
2068- FSReqWrapSync req_wrap_sync;
2066+ } else { // write(fd, buffer, off, len, pos)
2067+ FSReqWrapSync req_wrap_sync (" write" );
20692068 FS_SYNC_TRACE_BEGIN (write);
2070- int bytesWritten = SyncCall (env, args[ 6 ], &req_wrap_sync, " write " ,
2071- uv_fs_write, fd, &uvbuf, 1 , pos);
2069+ int bytesWritten = SyncCallAndThrowOnError (
2070+ env, &req_wrap_sync, uv_fs_write, fd, &uvbuf, 1 , pos);
20722071 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2072+
2073+ if (is_uv_error (bytesWritten)) {
2074+ return ;
2075+ }
2076+
20732077 args.GetReturnValue ().Set (bytesWritten);
20742078 }
20752079}
@@ -2206,9 +2210,8 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
22062210 } else {
22072211 req_wrap_async->SetReturnValue (args);
22082212 }
2209- } else { // write(fd, string, pos, enc, undefined, ctx)
2210- CHECK_EQ (argc, 6 );
2211- FSReqWrapSync req_wrap_sync;
2213+ } else { // write(fd, string, pos, enc)
2214+ FSReqWrapSync req_wrap_sync (" write" );
22122215 FSReqBase::FSReqBuffer stack_buffer;
22132216 if (buf == nullptr ) {
22142217 if (!StringBytes::StorageSize (isolate, value, enc).To (&len))
@@ -2223,9 +2226,14 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
22232226 }
22242227 uv_buf_t uvbuf = uv_buf_init (buf, len);
22252228 FS_SYNC_TRACE_BEGIN (write);
2226- int bytesWritten = SyncCall (env, args[ 5 ], &req_wrap_sync, " write " ,
2227- uv_fs_write, fd, &uvbuf, 1 , pos);
2229+ int bytesWritten = SyncCallAndThrowOnError (
2230+ env, &req_wrap_sync, uv_fs_write, fd, &uvbuf, 1 , pos);
22282231 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2232+
2233+ if (is_uv_error (bytesWritten)) {
2234+ return ;
2235+ }
2236+
22292237 args.GetReturnValue ().Set (bytesWritten);
22302238 }
22312239}
0 commit comments