@@ -1926,8 +1926,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
19261926
19271927 bool with_types = args[2 ]->IsTrue ();
19281928
1929- FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
1930- if ( req_wrap_async != nullptr ) { // readdir(path, encoding, withTypes, req)
1929+ if (argc > 3 ) { // readdir(path, encoding, withTypes, req)
1930+ FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
19311931 req_wrap_async->set_with_file_types (with_types);
19321932 FS_ASYNC_TRACE_BEGIN1 (
19331933 UV_FS_SCANDIR, req_wrap_async, " path" , TRACE_STR_COPY (*path))
@@ -1940,18 +1940,16 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
19401940 uv_fs_scandir,
19411941 *path,
19421942 0 /* flags*/ );
1943- } else { // readdir(path, encoding, withTypes, undefined, ctx)
1944- CHECK_EQ (argc, 5 );
1945- FSReqWrapSync req_wrap_sync;
1943+ } else { // readdir(path, encoding, withTypes)
1944+ FSReqWrapSync req_wrap_sync (" scandir" , *path);
19461945 FS_SYNC_TRACE_BEGIN (readdir);
1947- int err = SyncCall (env, args[ 4 ], &req_wrap_sync, " scandir " ,
1948- uv_fs_scandir, *path, 0 /* flags*/ );
1946+ int err = SyncCallAndThrowOnError (
1947+ env, &req_wrap_sync, uv_fs_scandir, *path, 0 /* flags*/ );
19491948 FS_SYNC_TRACE_END (readdir);
1950- if (err < 0 ) {
1951- return ; // syscall failed, no need to continue, error info is in ctx
1949+ if (is_uv_error ( err) ) {
1950+ return ;
19521951 }
19531952
1954- CHECK_GE (req_wrap_sync.req .result , 0 );
19551953 int r;
19561954 std::vector<Local<Value>> name_v;
19571955 std::vector<Local<Value>> type_v;
@@ -1962,12 +1960,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
19621960 r = uv_fs_scandir_next (&(req_wrap_sync.req ), &ent);
19631961 if (r == UV_EOF)
19641962 break ;
1965- if (r != 0 ) {
1966- Local<Object> ctx = args[4 ].As <Object>();
1967- ctx->Set (env->context (), env->errno_string (),
1968- Integer::New (isolate, r)).Check ();
1969- ctx->Set (env->context (), env->syscall_string (),
1970- OneByteString (isolate, " readdir" )).Check ();
1963+ if (is_uv_error (r)) {
1964+ env->ThrowUVException (r, " scandir" , nullptr , *path);
19711965 return ;
19721966 }
19731967
@@ -1978,8 +1972,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
19781972 &error);
19791973
19801974 if (filename.IsEmpty ()) {
1981- Local<Object> ctx = args[4 ].As <Object>();
1982- ctx->Set (env->context (), env->error_string (), error).Check ();
1975+ isolate->ThrowException (error);
19831976 return ;
19841977 }
19851978
0 commit comments