@@ -1863,28 +1863,27 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
18631863 Isolate* isolate = env->isolate ();
18641864
18651865 const int argc = args.Length ();
1866- CHECK_GE (argc, 3 );
1866+ CHECK_GE (argc, 2 );
18671867
18681868 BufferValue path (isolate, args[0 ]);
18691869 CHECK_NOT_NULL (*path);
18701870
18711871 const enum encoding encoding = ParseEncoding (isolate, args[1 ], UTF8);
18721872
1873- FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
1874- if ( req_wrap_async != nullptr ) { // realpath(path, encoding, req)
1873+ if (argc > 2 ) { // realpath(path, encoding, req)
1874+ FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
18751875 FS_ASYNC_TRACE_BEGIN1 (
18761876 UV_FS_REALPATH, req_wrap_async, " path" , TRACE_STR_COPY (*path))
18771877 AsyncCall (env, req_wrap_async, args, " realpath" , encoding, AfterStringPtr,
18781878 uv_fs_realpath, *path);
18791879 } else { // realpath(path, encoding, undefined, ctx)
1880- CHECK_EQ (argc, 4 );
1881- FSReqWrapSync req_wrap_sync;
1880+ FSReqWrapSync req_wrap_sync (" realpath" , *path);
18821881 FS_SYNC_TRACE_BEGIN (realpath);
1883- int err = SyncCall (env, args[ 3 ], &req_wrap_sync, " realpath " ,
1884- uv_fs_realpath, *path);
1882+ int err =
1883+ SyncCallAndThrowOnError (env, &req_wrap_sync, uv_fs_realpath, *path);
18851884 FS_SYNC_TRACE_END (realpath);
18861885 if (err < 0 ) {
1887- return ; // syscall failed, no need to continue, error info is in ctx
1886+ return ;
18881887 }
18891888
18901889 const char * link_path = static_cast <const char *>(req_wrap_sync.req .ptr );
@@ -1895,8 +1894,7 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
18951894 encoding,
18961895 &error);
18971896 if (rc.IsEmpty ()) {
1898- Local<Object> ctx = args[3 ].As <Object>();
1899- ctx->Set (env->context (), env->error_string (), error).Check ();
1897+ env->isolate ()->ThrowException (error);
19001898 return ;
19011899 }
19021900
0 commit comments