@@ -2341,18 +2341,23 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
23412341 char * buf = buffer_data + off;
23422342 uv_buf_t uvbuf = uv_buf_init (buf, len);
23432343
2344- FSReqBase* req_wrap_async = GetReqWrap (args, 5 );
2345- if (req_wrap_async != nullptr ) { // read(fd, buffer, offset, len, pos, req)
2344+ if (argc > 5 ) { // read(fd, buffer, offset, len, pos, req)
2345+ FSReqBase* req_wrap_async = GetReqWrap (args, 5 );
2346+ CHECK_NOT_NULL (req_wrap_async);
23462347 FS_ASYNC_TRACE_BEGIN0 (UV_FS_READ, req_wrap_async)
23472348 AsyncCall (env, req_wrap_async, args, " read" , UTF8, AfterInteger,
23482349 uv_fs_read, fd, &uvbuf, 1 , pos);
2349- } else { // read(fd, buffer, offset, len, pos, undefined, ctx)
2350- CHECK_EQ (argc, 7 );
2351- FSReqWrapSync req_wrap_sync;
2350+ } else { // read(fd, buffer, offset, len, pos)
2351+ FSReqWrapSync req_wrap_sync (" read" );
23522352 FS_SYNC_TRACE_BEGIN (read);
2353- const int bytesRead = SyncCall (env, args[ 6 ], &req_wrap_sync, " read " ,
2354- uv_fs_read, fd, &uvbuf, 1 , pos);
2353+ const int bytesRead = SyncCallAndThrowOnError (
2354+ env, &req_wrap_sync, uv_fs_read, fd, &uvbuf, 1 , pos);
23552355 FS_SYNC_TRACE_END (read, " bytesRead" , bytesRead);
2356+
2357+ if (is_uv_error (bytesRead)) {
2358+ return ;
2359+ }
2360+
23562361 args.GetReturnValue ().Set (bytesRead);
23572362 }
23582363}
0 commit comments