@@ -1383,7 +1383,7 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
13831383 Isolate* isolate = env->isolate ();
13841384
13851385 const int argc = args.Length ();
1386- CHECK_GE (argc, 3 );
1386+ CHECK_GE (argc, 2 );
13871387
13881388 BufferValue path (isolate, args[0 ]);
13891389 CHECK_NOT_NULL (*path);
@@ -1392,21 +1392,20 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
13921392
13931393 const enum encoding encoding = ParseEncoding (isolate, args[1 ], UTF8);
13941394
1395- FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
1396- if ( req_wrap_async != nullptr ) { // readlink(path, encoding, req)
1395+ if (argc > 2 ) { // readlink(path, encoding, req)
1396+ FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
13971397 FS_ASYNC_TRACE_BEGIN1 (
13981398 UV_FS_READLINK, req_wrap_async, " path" , TRACE_STR_COPY (*path))
13991399 AsyncCall (env, req_wrap_async, args, " readlink" , encoding, AfterStringPtr,
14001400 uv_fs_readlink, *path);
1401- } else {
1402- CHECK_EQ (argc, 4 );
1403- FSReqWrapSync req_wrap_sync;
1401+ } else { // readlink(path, encoding)
1402+ FSReqWrapSync req_wrap_sync (" readlink" , *path);
14041403 FS_SYNC_TRACE_BEGIN (readlink);
1405- int err = SyncCall (env, args[ 3 ], &req_wrap_sync, " readlink " ,
1406- uv_fs_readlink, *path);
1404+ int err =
1405+ SyncCallAndThrowOnError (env, &req_wrap_sync, uv_fs_readlink, *path);
14071406 FS_SYNC_TRACE_END (readlink);
14081407 if (err < 0 ) {
1409- return ; // syscall failed, no need to continue, error info is in ctx
1408+ return ;
14101409 }
14111410 const char * link_path = static_cast <const char *>(req_wrap_sync.req .ptr );
14121411
@@ -1416,8 +1415,7 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
14161415 encoding,
14171416 &error);
14181417 if (rc.IsEmpty ()) {
1419- Local<Object> ctx = args[3 ].As <Object>();
1420- ctx->Set (env->context (), env->error_string (), error).Check ();
1418+ env->isolate ()->ThrowException (error);
14211419 return ;
14221420 }
14231421
0 commit comments