diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-02-16 13:25:21 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-02-27 20:34:18 +0800 |
commit | 4eb45b884d9bd1f13979047750ad680275f4a348 (patch) | |
tree | 0bffb5e15f59ab58888f28e4e75dc663bf85bce2 /src/node_file.cc | |
parent | d2dc2a50113492840e77e4f5d3df6ff75fa986a4 (diff) | |
download | android-node-v8-4eb45b884d9bd1f13979047750ad680275f4a348.tar.gz android-node-v8-4eb45b884d9bd1f13979047750ad680275f4a348.tar.bz2 android-node-v8-4eb45b884d9bd1f13979047750ad680275f4a348.zip |
fs: throw copyFileSync 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/node_file.cc')
-rw-r--r-- | src/node_file.cc | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/node_file.cc b/src/node_file.cc index d73b5450da..00fe1f178b 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1232,21 +1232,28 @@ static void OpenFileHandle(const FunctionCallbackInfo<Value>& args) { static void CopyFile(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); - CHECK_GE(args.Length(), 3); - CHECK(args[2]->IsInt32()); + const int argc = args.Length(); + CHECK_GE(argc, 3); BufferValue src(env->isolate(), args[0]); CHECK_NE(*src, nullptr); + BufferValue dest(env->isolate(), args[1]); CHECK_NE(*dest, nullptr); - int flags = args[2]->Int32Value(); + + CHECK(args[2]->IsInt32()); + const int flags = args[2].As<Int32>()->Value(); FSReqBase* req_wrap = GetReqWrap(env, args[3]); - if (req_wrap != nullptr) { - AsyncCall(env, req_wrap, args, "copyfile", UTF8, AfterNoArgs, - uv_fs_copyfile, *src, *dest, flags); - } else { - SYNC_DEST_CALL(copyfile, *src, *dest, *src, *dest, flags) + if (req_wrap != nullptr) { // copyFile(src, dest, flags, req) + AsyncDestCall(env, req_wrap, args, "copyfile", + *dest, dest.length(), UTF8, AfterNoArgs, + uv_fs_copyfile, *src, *dest, flags); + } else { // copyFile(src, dest, flags, undefined, ctx) + CHECK_EQ(argc, 5); + fs_req_wrap req_wrap; + SyncCall(env, args[4], &req_wrap, "copyfile", + uv_fs_copyfile, *src, *dest, flags); } } |