@@ -1891,8 +1891,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1891
1891
1892
1892
bool with_types = args[2 ]->IsTrue ();
1893
1893
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 );
1896
1896
req_wrap_async->set_with_file_types (with_types);
1897
1897
FS_ASYNC_TRACE_BEGIN1 (
1898
1898
UV_FS_SCANDIR, req_wrap_async, " path" , TRACE_STR_COPY (*path))
@@ -1905,18 +1905,16 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1905
1905
uv_fs_scandir,
1906
1906
*path,
1907
1907
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);
1911
1910
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*/ );
1914
1913
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 ;
1917
1916
}
1918
1917
1919
- CHECK_GE (req_wrap_sync.req .result , 0 );
1920
1918
int r;
1921
1919
std::vector<Local<Value>> name_v;
1922
1920
std::vector<Local<Value>> type_v;
@@ -1927,12 +1925,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1927
1925
r = uv_fs_scandir_next (&(req_wrap_sync.req ), &ent);
1928
1926
if (r == UV_EOF)
1929
1927
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);
1936
1930
return ;
1937
1931
}
1938
1932
@@ -1943,8 +1937,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1943
1937
&error);
1944
1938
1945
1939
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);
1948
1941
return ;
1949
1942
}
1950
1943
0 commit comments