@@ -648,32 +648,39 @@ static void Link(const FunctionCallbackInfo<Value>& args) {
648648static void ReadLink (const FunctionCallbackInfo<Value>& args) {
649649 Environment* env = Environment::GetCurrent (args);
650650
651- const int argc = args.Length ();
652-
653- CHECK_GE (argc, 1 );
651+ int argc = args.Length ();
652+ CHECK_GE (argc, 3 );
654653
655654 BufferValue path (env->isolate (), args[0 ]);
656655 CHECK_NE (*path, nullptr );
657656
658657 const enum encoding encoding = ParseEncoding (env->isolate (), args[1 ], UTF8);
659658
660659 if (args[2 ]->IsObject ()) { // readlink(path, encoding, req)
661- CHECK_EQ (args. Length () , 3 );
660+ CHECK_EQ (argc , 3 );
662661 AsyncCall (env, args, " readlink" , encoding, AfterStringPtr,
663662 uv_fs_readlink, *path);
664- } else {
665- SYNC_CALL (readlink, *path, *path)
666- const char * link_path = static_cast <const char *>(SYNC_REQ.ptr );
663+ } else { // readlink(path, encoding, undefined, ctx)
664+ CHECK_EQ (argc, 4 );
665+ fs_req_wrap req_wrap;
666+ int err = SyncCall (env, args[3 ], &req_wrap, " readlink" ,
667+ uv_fs_readlink, *path);
668+ if (err) {
669+ return ; // syscall failed, no need to continue, error info is in ctx
670+ }
671+ const char * link_path = static_cast <const char *>(req_wrap.req .ptr );
667672
668673 Local<Value> error;
669674 MaybeLocal<Value> rc = StringBytes::Encode (env->isolate (),
670675 link_path,
671676 encoding,
672677 &error);
673678 if (rc.IsEmpty ()) {
674- env->isolate ()->ThrowException (error);
679+ Local<Object> ctx = args[3 ].As <Object>();
680+ ctx->Set (env->context (), env->error_string (), error).FromJust ();
675681 return ;
676682 }
683+
677684 args.GetReturnValue ().Set (rc.ToLocalChecked ());
678685 }
679686}
0 commit comments