@@ -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,20 @@ 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
+ FSReqWrapSync req_wrap_sync (" write" );
2068
2067
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);
2071
2070
FS_SYNC_TRACE_END (write , " bytesWritten" , bytesWritten);
2071
+ if (is_uv_error (bytesWritten)) {
2072
+ return ;
2073
+ }
2072
2074
args.GetReturnValue ().Set (bytesWritten);
2073
2075
}
2074
2076
}
@@ -2205,9 +2207,8 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
2205
2207
} else {
2206
2208
req_wrap_async->SetReturnValue (args);
2207
2209
}
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" );
2211
2212
FSReqBase::FSReqBuffer stack_buffer;
2212
2213
if (buf == nullptr ) {
2213
2214
if (!StringBytes::StorageSize (isolate, value, enc).To (&len))
@@ -2222,9 +2223,12 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
2222
2223
}
2223
2224
uv_buf_t uvbuf = uv_buf_init (buf, len);
2224
2225
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);
2227
2228
FS_SYNC_TRACE_END (write , " bytesWritten" , bytesWritten);
2229
+ if (is_uv_error (bytesWritten)) {
2230
+ return ;
2231
+ }
2228
2232
args.GetReturnValue ().Set (bytesWritten);
2229
2233
}
2230
2234
}
0 commit comments