summaryrefslogtreecommitdiff
path: root/src/node_file.cc
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-02-20 03:35:39 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-02-27 20:34:06 +0800
commit8fb5a6cd81a893dc4929a290206ac0b10c068487 (patch)
tree6770956b3c36ba06a21372fcc622913eeeedfef8 /src/node_file.cc
parent437c75649335a0b412670b82d3dfc37be7b01d0b (diff)
downloadandroid-node-v8-8fb5a6cd81a893dc4929a290206ac0b10c068487.tar.gz
android-node-v8-8fb5a6cd81a893dc4929a290206ac0b10c068487.tar.bz2
android-node-v8-8fb5a6cd81a893dc4929a290206ac0b10c068487.zip
fs: throw fs.chownSync errors in JS land
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.cc23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 4e99953b62..6e23846d47 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -102,6 +102,7 @@ using v8::ObjectTemplate;
using v8::Promise;
using v8::String;
using v8::Symbol;
+using v8::Uint32;
using v8::Undefined;
using v8::Value;
@@ -1508,23 +1509,27 @@ static void FChmod(const FunctionCallbackInfo<Value>& args) {
static void Chown(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
- int len = args.Length();
- CHECK_GE(len, 3);
- CHECK(args[1]->IsUint32());
- CHECK(args[2]->IsUint32());
+ const int argc = args.Length();
+ CHECK_GE(argc, 3);
BufferValue path(env->isolate(), args[0]);
CHECK_NE(*path, nullptr);
- uv_uid_t uid = static_cast<uv_uid_t>(args[1]->Uint32Value());
- uv_gid_t gid = static_cast<uv_gid_t>(args[2]->Uint32Value());
+ CHECK(args[1]->IsUint32());
+ const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());
+
+ CHECK(args[2]->IsUint32());
+ const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value());
FSReqBase* req_wrap = GetReqWrap(env, args[3]);
- if (req_wrap != nullptr) {
+ if (req_wrap != nullptr) { // chown(path, uid, gid, req)
AsyncCall(env, req_wrap, args, "chown", UTF8, AfterNoArgs,
uv_fs_chown, *path, uid, gid);
- } else {
- SYNC_CALL(chown, *path, *path, uid, gid);
+ } else { // chown(path, uid, gid, undefined, ctx)
+ CHECK_EQ(argc, 5);
+ fs_req_wrap req_wrap;
+ SyncCall(env, args[4], &req_wrap, "chown",
+ uv_fs_chown, *path, uid, gid);
}
}