diff --git a/lib/fs.js b/lib/fs.js index 60134b1c321..0d8d8ec4dcc 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1054,7 +1054,9 @@ fs.chmodSync = function(path, mode) { validatePath(path); mode = modeNum(mode); validateUint32(mode, 'mode'); - return binding.chmod(pathModule.toNamespacedPath(path), mode); + const ctx = { path }; + binding.chmod(pathModule.toNamespacedPath(path), mode, undefined, ctx); + handleErrorFromBinding(ctx); }; if (constants.O_SYMLINK !== undefined) { diff --git a/src/node_file.cc b/src/node_file.cc index 5e8f9ee168b..4e99953b626 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1458,20 +1458,24 @@ static void Read(const FunctionCallbackInfo& args) { static void Chmod(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - CHECK_GE(args.Length(), 2); - CHECK(args[1]->IsInt32()); + const int argc = args.Length(); + CHECK_GE(argc, 2); BufferValue path(env->isolate(), args[0]); CHECK_NE(*path, nullptr); - int mode = static_cast(args[1]->Int32Value()); + CHECK(args[1]->IsInt32()); + int mode = args[1].As()->Value(); FSReqBase* req_wrap = GetReqWrap(env, args[2]); - if (req_wrap != nullptr) { + if (req_wrap != nullptr) { // chmod(path, mode, req) AsyncCall(env, req_wrap, args, "chmod", UTF8, AfterNoArgs, uv_fs_chmod, *path, mode); - } else { - SYNC_CALL(chmod, *path, *path, mode); + } else { // chmod(path, mode, undefined, ctx) + CHECK_EQ(argc, 4); + fs_req_wrap req_wrap; + SyncCall(env, args[3], &req_wrap, "chmod", + uv_fs_chmod, *path, mode); } }