@@ -1458,20 +1458,24 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
14581458static void Chmod (const FunctionCallbackInfo<Value>& args) {
14591459 Environment* env = Environment::GetCurrent (args);
14601460
1461- CHECK_GE ( args.Length (), 2 );
1462- CHECK (args[ 1 ]-> IsInt32 () );
1461+ const int argc = args.Length ();
1462+ CHECK_GE (argc, 2 );
14631463
14641464 BufferValue path (env->isolate (), args[0 ]);
14651465 CHECK_NE (*path, nullptr );
14661466
1467- int mode = static_cast <int >(args[1 ]->Int32Value ());
1467+ CHECK (args[1 ]->IsInt32 ());
1468+ int mode = args[1 ].As <Int32>()->Value ();
14681469
14691470 FSReqBase* req_wrap = GetReqWrap (env, args[2 ]);
1470- if (req_wrap != nullptr ) {
1471+ if (req_wrap != nullptr ) { // chmod(path, mode, req)
14711472 AsyncCall (env, req_wrap, args, " chmod" , UTF8, AfterNoArgs,
14721473 uv_fs_chmod, *path, mode);
1473- } else {
1474- SYNC_CALL (chmod, *path, *path, mode);
1474+ } else { // chmod(path, mode, undefined, ctx)
1475+ CHECK_EQ (argc, 4 );
1476+ fs_req_wrap req_wrap;
1477+ SyncCall (env, args[3 ], &req_wrap, " chmod" ,
1478+ uv_fs_chmod, *path, mode);
14751479 }
14761480}
14771481
0 commit comments