summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-02-03 22:22:05 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-02-27 20:33:43 +0800
commit72d150ea6f72098a2a99e4a25658f3b5c767d03b (patch)
tree98f473202706a462fbbfebef4aa8b87d843bc0ee /src
parent77b42e34de519d211f7b68330781af67be76fd35 (diff)
downloadandroid-node-v8-72d150ea6f72098a2a99e4a25658f3b5c767d03b.tar.gz
android-node-v8-72d150ea6f72098a2a99e4a25658f3b5c767d03b.tar.bz2
android-node-v8-72d150ea6f72098a2a99e4a25658f3b5c767d03b.zip
fs: throw realpathSync.native errors in JS
PR-URL: https://github.com/nodejs/node/pull/18871 Refs: https://github.com/nodejs/node/issues/18106 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src')
-rw-r--r--src/node_file.cc24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index ec2e35c25b..e3c9801b8a 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -1047,20 +1047,30 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
}
static void RealPath(const FunctionCallbackInfo<Value>& args) {
- CHECK_GE(args.Length(), 2);
Environment* env = Environment::GetCurrent(args);
+
+ const int argc = args.Length();
+ CHECK_GE(argc, 3);
+
BufferValue path(env->isolate(), args[0]);
CHECK_NE(*path, nullptr);
const enum encoding encoding = ParseEncoding(env->isolate(), args[1], UTF8);
FSReqBase* req_wrap = GetReqWrap(env, args[2]);
- if (req_wrap != nullptr) {
+ if (req_wrap != nullptr) { // realpath(path, encoding, req)
AsyncCall(env, req_wrap, args, "realpath", encoding, AfterStringPtr,
uv_fs_realpath, *path);
- } else {
- SYNC_CALL(realpath, *path, *path);
- const char* link_path = static_cast<const char*>(SYNC_REQ.ptr);
+ } else { // realpath(path, encoding, undefined, ctx)
+ CHECK_EQ(argc, 4);
+ fs_req_wrap req_wrap;
+ int err = SyncCall(env, args[3], &req_wrap, "realpath",
+ uv_fs_realpath, *path);
+ if (err < 0) {
+ return; // syscall failed, no need to continue, error info is in ctx
+ }
+
+ const char* link_path = static_cast<const char*>(req_wrap.req.ptr);
Local<Value> error;
MaybeLocal<Value> rc = StringBytes::Encode(env->isolate(),
@@ -1068,9 +1078,11 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
encoding,
&error);
if (rc.IsEmpty()) {
- env->isolate()->ThrowException(error);
+ Local<Object> ctx = args[3].As<Object>();
+ ctx->Set(env->context(), env->error_string(), error).FromJust();
return;
}
+
args.GetReturnValue().Set(rc.ToLocalChecked());
}
}