fs: move type checking for fs.sync 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
956f97b875
commit
8cb080c486
@ -925,7 +925,7 @@ fs.fdatasyncSync = function(fd) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fs.fsync = function(fd, callback) {
|
fs.fsync = 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');
|
||||||
@ -935,7 +935,7 @@ fs.fsync = function(fd, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fs.fsyncSync = function(fd) {
|
fs.fsyncSync = 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');
|
||||||
|
@ -806,10 +806,7 @@ static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
|
|||||||
static void Fsync(const FunctionCallbackInfo<Value>& args) {
|
static void Fsync(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();
|
||||||
|
|
||||||
|
@ -66,11 +66,27 @@ fs.open(fileFixture, 'a', 0o777, common.mustCall(function(err, fd) {
|
|||||||
message: 'The "fd" argument must be of type number'
|
message: 'The "fd" argument must be of type number'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
common.expectsError(
|
||||||
|
() => fs.fsync(i),
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "fd" argument must be of type number'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
common.expectsError(
|
||||||
|
() => fs.fsyncSync(i),
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "fd" argument must be of type number'
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
[-1, 0xFFFFFFFF + 1].forEach((i) => {
|
[-1, 0xFFFFFFFF + 1].forEach((i) => {
|
||||||
common.expectsError(
|
common.expectsError(
|
||||||
() => fs.fdatasync(i),
|
() => fs.fsync(i),
|
||||||
{
|
{
|
||||||
code: 'ERR_OUT_OF_RANGE',
|
code: 'ERR_OUT_OF_RANGE',
|
||||||
type: RangeError,
|
type: RangeError,
|
||||||
@ -78,7 +94,7 @@ fs.open(fileFixture, 'a', 0o777, common.mustCall(function(err, fd) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
common.expectsError(
|
common.expectsError(
|
||||||
() => fs.fdatasyncSync(i),
|
() => fs.fsyncSync(i),
|
||||||
{
|
{
|
||||||
code: 'ERR_OUT_OF_RANGE',
|
code: 'ERR_OUT_OF_RANGE',
|
||||||
type: RangeError,
|
type: RangeError,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user