@@ -2030,7 +2030,7 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
2030
2030
Environment* env = Environment::GetCurrent (args);
2031
2031
2032
2032
const int argc = args.Length ();
2033
- CHECK_GE (argc, 4 );
2033
+ CHECK_GE (argc, 5 );
2034
2034
2035
2035
CHECK (args[0 ]->IsInt32 ());
2036
2036
const int fd = args[0 ].As <Int32>()->Value ();
@@ -2057,18 +2057,21 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
2057
2057
char * buf = buffer_data + off;
2058
2058
uv_buf_t uvbuf = uv_buf_init (buf, len);
2059
2059
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 );
2062
2062
FS_ASYNC_TRACE_BEGIN0 (UV_FS_WRITE, req_wrap_async)
2063
2063
AsyncCall (env, req_wrap_async, args, " write" , UTF8, AfterInteger,
2064
2064
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 " ) ;
2068
2068
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);
2071
2071
FS_SYNC_TRACE_END (write , " bytesWritten" , bytesWritten);
2072
+ if (is_uv_error (bytesWritten)) {
2073
+ return ;
2074
+ }
2072
2075
args.GetReturnValue ().Set (bytesWritten);
2073
2076
}
2074
2077
}
@@ -2205,9 +2208,8 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
2205
2208
} else {
2206
2209
req_wrap_async->SetReturnValue (args);
2207
2210
}
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" );
2211
2213
FSReqBase::FSReqBuffer stack_buffer;
2212
2214
if (buf == nullptr ) {
2213
2215
if (!StringBytes::StorageSize (isolate, value, enc).To (&len))
@@ -2222,9 +2224,12 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
2222
2224
}
2223
2225
uv_buf_t uvbuf = uv_buf_init (buf, len);
2224
2226
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);
2227
2229
FS_SYNC_TRACE_END (write , " bytesWritten" , bytesWritten);
2230
+ if (is_uv_error (bytesWritten)) {
2231
+ return ;
2232
+ }
2228
2233
args.GetReturnValue ().Set (bytesWritten);
2229
2234
}
2230
2235
}
0 commit comments