fs: throw futimesSync errors in JS
PR-URL: https://github.com/nodejs/node/pull/19041 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
994320b07b
commit
49dd80935c
@ -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) {
|
||||
|
@ -1622,20 +1622,27 @@ static void UTimes(const FunctionCallbackInfo<Value>& args) {
|
||||
static void FUTimes(const FunctionCallbackInfo<Value>& 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<double>(args[1]->NumberValue());
|
||||
const double mtime = static_cast<double>(args[2]->NumberValue());
|
||||
CHECK(args[0]->IsInt32());
|
||||
const int fd = args[0].As<Int32>()->Value();
|
||||
|
||||
CHECK(args[1]->IsNumber());
|
||||
const double atime = args[1].As<Number>()->Value();
|
||||
|
||||
CHECK(args[2]->IsNumber());
|
||||
const double mtime = args[2].As<Number>()->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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user