@@ -1926,8 +1926,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1926
1926
1927
1927
bool with_types = args[2 ]->IsTrue ();
1928
1928
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 );
1931
1931
req_wrap_async->set_with_file_types (with_types);
1932
1932
FS_ASYNC_TRACE_BEGIN1 (
1933
1933
UV_FS_SCANDIR, req_wrap_async, " path" , TRACE_STR_COPY (*path))
@@ -1940,18 +1940,16 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1940
1940
uv_fs_scandir,
1941
1941
*path,
1942
1942
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);
1946
1945
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*/ );
1949
1948
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 ;
1952
1951
}
1953
1952
1954
- CHECK_GE (req_wrap_sync.req .result , 0 );
1955
1953
int r;
1956
1954
std::vector<Local<Value>> name_v;
1957
1955
std::vector<Local<Value>> type_v;
@@ -1962,12 +1960,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1962
1960
r = uv_fs_scandir_next (&(req_wrap_sync.req ), &ent);
1963
1961
if (r == UV_EOF)
1964
1962
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);
1971
1965
return ;
1972
1966
}
1973
1967
@@ -1978,8 +1972,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1978
1972
&error);
1979
1973
1980
1974
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);
1983
1976
return ;
1984
1977
}
1985
1978
0 commit comments