@@ -648,32 +648,39 @@ static void Link(const FunctionCallbackInfo<Value>& args) {
648
648
static void ReadLink (const FunctionCallbackInfo<Value>& args) {
649
649
Environment* env = Environment::GetCurrent (args);
650
650
651
- const int argc = args.Length ();
652
-
653
- CHECK_GE (argc, 1 );
651
+ int argc = args.Length ();
652
+ CHECK_GE (argc, 3 );
654
653
655
654
BufferValue path (env->isolate (), args[0 ]);
656
655
CHECK_NE (*path, nullptr );
657
656
658
657
const enum encoding encoding = ParseEncoding (env->isolate (), args[1 ], UTF8);
659
658
660
659
if (args[2 ]->IsObject ()) { // readlink(path, encoding, req)
661
- CHECK_EQ (args. Length () , 3 );
660
+ CHECK_EQ (argc , 3 );
662
661
AsyncCall (env, args, " readlink" , encoding, AfterStringPtr,
663
662
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 );
667
672
668
673
Local<Value> error;
669
674
MaybeLocal<Value> rc = StringBytes::Encode (env->isolate (),
670
675
link_path,
671
676
encoding,
672
677
&error);
673
678
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 ();
675
681
return ;
676
682
}
683
+
677
684
args.GetReturnValue ().Set (rc.ToLocalChecked ());
678
685
}
679
686
}
0 commit comments