diff --git a/lib/fs.js b/lib/fs.js index 2c96b08144b..2dcfb25348f 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1183,7 +1183,9 @@ fs.futimesSync = function(fd, atime, mtime) { validateUint32(fd, 'fd'); atime = toUnixTimestamp(atime, 'atime'); mtime = toUnixTimestamp(mtime, 'mtime'); - binding.futimes(fd, atime, mtime); + const ctx = {}; + binding.futimes(fd, atime, mtime, undefined, ctx); + handleErrorFromBinding(ctx); }; function writeAll(fd, isUserFd, buffer, offset, length, position, callback) { diff --git a/src/node_file.cc b/src/node_file.cc index bf036bc309e..dc9027cd5d9 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1622,20 +1622,27 @@ static void UTimes(const FunctionCallbackInfo& args) { static void FUTimes(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - CHECK(args[0]->IsInt32()); - CHECK(args[1]->IsNumber()); - CHECK(args[2]->IsNumber()); + const int argc = args.Length(); + CHECK_GE(argc, 3); - const int fd = args[0]->Int32Value(); - const double atime = static_cast(args[1]->NumberValue()); - const double mtime = static_cast(args[2]->NumberValue()); + CHECK(args[0]->IsInt32()); + const int fd = args[0].As()->Value(); + + CHECK(args[1]->IsNumber()); + const double atime = args[1].As()->Value(); + + CHECK(args[2]->IsNumber()); + const double mtime = args[2].As()->Value(); FSReqBase* req_wrap = GetReqWrap(env, args[3]); - if (req_wrap != nullptr) { + if (req_wrap != nullptr) { // futimes(fd, atime, mtime, req) AsyncCall(env, req_wrap, args, "futime", UTF8, AfterNoArgs, uv_fs_futime, fd, atime, mtime); - } else { - SYNC_CALL(futime, 0, fd, atime, mtime); + } else { // futimes(fd, atime, mtime, undefined, ctx) + CHECK_EQ(argc, 5); + fs_req_wrap req_wrap; + SyncCall(env, args[4], &req_wrap, "futime", + uv_fs_futime, fd, atime, mtime); } } diff --git a/test/parallel/test-fs-error-messages.js b/test/parallel/test-fs-error-messages.js index 27533f122fc..61e51585a02 100644 --- a/test/parallel/test-fs-error-messages.js +++ b/test/parallel/test-fs-error-messages.js @@ -811,3 +811,24 @@ if (!common.isWindows) { ); }); } + + +// futimes +if (!common.isAIX) { + const validateError = (err) => { + assert.strictEqual(err.message, 'EBADF: bad file descriptor, futime'); + assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.code, 'EBADF'); + assert.strictEqual(err.syscall, 'futime'); + return true; + }; + + common.runWithInvalidFD((fd) => { + fs.futimes(fd, new Date(), new Date(), common.mustCall(validateError)); + + assert.throws( + () => fs.futimesSync(fd, new Date(), new Date()), + validateError + ); + }); +}