fs: move type checking for fs.fdatasync to js
PR-URL: https://github.com/nodejs/node/pull/17334 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
639096855e
commit
956f97b875
@ -907,7 +907,7 @@ fs.rmdirSync = function(path) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fs.fdatasync = function(fd, callback) {
|
fs.fdatasync = function(fd, callback) {
|
||||||
if (typeof fd !== 'number')
|
if (!Number.isInteger(fd))
|
||||||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', 'number');
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', 'number');
|
||||||
if (fd < 0 || fd > 0xFFFFFFFF)
|
if (fd < 0 || fd > 0xFFFFFFFF)
|
||||||
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'fd');
|
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'fd');
|
||||||
@ -917,7 +917,7 @@ fs.fdatasync = function(fd, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fs.fdatasyncSync = function(fd) {
|
fs.fdatasyncSync = function(fd) {
|
||||||
if (typeof fd !== 'number')
|
if (!Number.isInteger(fd))
|
||||||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', 'number');
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', 'number');
|
||||||
if (fd < 0 || fd > 0xFFFFFFFF)
|
if (fd < 0 || fd > 0xFFFFFFFF)
|
||||||
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'fd');
|
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'fd');
|
||||||
|
@ -792,10 +792,7 @@ static void FTruncate(const FunctionCallbackInfo<Value>& args) {
|
|||||||
static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
|
static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
|
|
||||||
if (args.Length() < 1)
|
CHECK(args[0]->IsInt32());
|
||||||
return TYPE_ERROR("fd is required");
|
|
||||||
if (!args[0]->IsInt32())
|
|
||||||
return TYPE_ERROR("fd must be a file descriptor");
|
|
||||||
|
|
||||||
int fd = args[0]->Int32Value();
|
int fd = args[0]->Int32Value();
|
||||||
|
|
||||||
|
@ -48,3 +48,41 @@ fs.open(fileFixture, 'a', 0o777, common.mustCall(function(err, fd) {
|
|||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
['', false, null, undefined, {}, []].forEach((i) => {
|
||||||
|
common.expectsError(
|
||||||
|
() => fs.fdatasync(i),
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "fd" argument must be of type number'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
common.expectsError(
|
||||||
|
() => fs.fdatasyncSync(i),
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "fd" argument must be of type number'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
[-1, 0xFFFFFFFF + 1].forEach((i) => {
|
||||||
|
common.expectsError(
|
||||||
|
() => fs.fdatasync(i),
|
||||||
|
{
|
||||||
|
code: 'ERR_OUT_OF_RANGE',
|
||||||
|
type: RangeError,
|
||||||
|
message: 'The "fd" argument is out of range'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
common.expectsError(
|
||||||
|
() => fs.fdatasyncSync(i),
|
||||||
|
{
|
||||||
|
code: 'ERR_OUT_OF_RANGE',
|
||||||
|
type: RangeError,
|
||||||
|
message: 'The "fd" argument is out of range'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user