@@ -1828,28 +1828,27 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
1828
1828
Isolate* isolate = env->isolate ();
1829
1829
1830
1830
const int argc = args.Length ();
1831
- CHECK_GE (argc, 3 );
1831
+ CHECK_GE (argc, 2 );
1832
1832
1833
1833
BufferValue path (isolate, args[0 ]);
1834
1834
CHECK_NOT_NULL (*path);
1835
1835
1836
1836
const enum encoding encoding = ParseEncoding (isolate, args[1 ], UTF8);
1837
1837
1838
- FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
1839
- if ( req_wrap_async != nullptr ) { // realpath(path, encoding, req)
1838
+ if (argc > 2 ) { // realpath(path, encoding, req)
1839
+ FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
1840
1840
FS_ASYNC_TRACE_BEGIN1 (
1841
1841
UV_FS_REALPATH, req_wrap_async, " path" , TRACE_STR_COPY (*path))
1842
1842
AsyncCall (env, req_wrap_async, args, " realpath" , encoding, AfterStringPtr,
1843
1843
uv_fs_realpath, *path);
1844
1844
} else { // realpath(path, encoding, undefined, ctx)
1845
- CHECK_EQ (argc, 4 );
1846
- FSReqWrapSync req_wrap_sync;
1845
+ FSReqWrapSync req_wrap_sync (" realpath" , *path);
1847
1846
FS_SYNC_TRACE_BEGIN (realpath );
1848
- int err = SyncCall (env, args[ 3 ], &req_wrap_sync, " realpath " ,
1849
- uv_fs_realpath, *path);
1847
+ int err =
1848
+ SyncCallAndThrowOnError (env, &req_wrap_sync, uv_fs_realpath, *path);
1850
1849
FS_SYNC_TRACE_END (realpath );
1851
1850
if (err < 0 ) {
1852
- return ; // syscall failed, no need to continue, error info is in ctx
1851
+ return ;
1853
1852
}
1854
1853
1855
1854
const char * link_path = static_cast <const char *>(req_wrap_sync.req .ptr );
@@ -1860,8 +1859,7 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
1860
1859
encoding,
1861
1860
&error);
1862
1861
if (rc.IsEmpty ()) {
1863
- Local<Object> ctx = args[3 ].As <Object>();
1864
- ctx->Set (env->context (), env->error_string (), error).Check ();
1862
+ env->isolate ()->ThrowException (error);
1865
1863
return ;
1866
1864
}
1867
1865
0 commit comments