@@ -1891,8 +1891,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
18911891
18921892 bool with_types = args[2 ]->IsTrue ();
18931893
1894- FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
1895- if ( req_wrap_async != nullptr ) { // readdir(path, encoding, withTypes, req)
1894+ if (argc > 3 ) { // readdir(path, encoding, withTypes, req)
1895+ FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
18961896 req_wrap_async->set_with_file_types (with_types);
18971897 FS_ASYNC_TRACE_BEGIN1 (
18981898 UV_FS_SCANDIR, req_wrap_async, " path" , TRACE_STR_COPY (*path))
@@ -1905,18 +1905,16 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
19051905 uv_fs_scandir,
19061906 *path,
19071907 0 /* flags*/ );
1908- } else { // readdir(path, encoding, withTypes, undefined, ctx)
1909- CHECK_EQ (argc, 5 );
1910- FSReqWrapSync req_wrap_sync;
1908+ } else { // readdir(path, encoding, withTypes)
1909+ FSReqWrapSync req_wrap_sync (" scandir" , *path);
19111910 FS_SYNC_TRACE_BEGIN (readdir);
1912- int err = SyncCall (env, args[ 4 ], &req_wrap_sync, " scandir " ,
1913- uv_fs_scandir, *path, 0 /* flags*/ );
1911+ int err = SyncCallAndThrowOnError (
1912+ env, &req_wrap_sync, uv_fs_scandir, *path, 0 /* flags*/ );
19141913 FS_SYNC_TRACE_END (readdir);
1915- if (err < 0 ) {
1916- return ; // syscall failed, no need to continue, error info is in ctx
1914+ if (is_uv_error ( err) ) {
1915+ return ;
19171916 }
19181917
1919- CHECK_GE (req_wrap_sync.req .result , 0 );
19201918 int r;
19211919 std::vector<Local<Value>> name_v;
19221920 std::vector<Local<Value>> type_v;
@@ -1927,12 +1925,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
19271925 r = uv_fs_scandir_next (&(req_wrap_sync.req ), &ent);
19281926 if (r == UV_EOF)
19291927 break ;
1930- if (r != 0 ) {
1931- Local<Object> ctx = args[4 ].As <Object>();
1932- ctx->Set (env->context (), env->errno_string (),
1933- Integer::New (isolate, r)).Check ();
1934- ctx->Set (env->context (), env->syscall_string (),
1935- OneByteString (isolate, " readdir" )).Check ();
1928+ if (is_uv_error (r)) {
1929+ env->ThrowUVException (r, " scandir" , nullptr , *path);
19361930 return ;
19371931 }
19381932
@@ -1943,8 +1937,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
19431937 &error);
19441938
19451939 if (filename.IsEmpty ()) {
1946- Local<Object> ctx = args[4 ].As <Object>();
1947- ctx->Set (env->context (), env->error_string (), error).Check ();
1940+ isolate->ThrowException (error);
19481941 return ;
19491942 }
19501943
0 commit comments