summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-11-26 17:05:26 -0800
committerJames M Snell <jasnell@gmail.com>2017-12-13 13:26:50 -0800
commit448ec0b5aaa8b07381a865a4b27bb62529639e48 (patch)
tree53a5da2ec7dfdcdd111c93f680cf2fac70518100 /lib
parent82eb459e3f5bab86c6aa75eae41cb51da1c6e2f6 (diff)
downloadandroid-node-v8-448ec0b5aaa8b07381a865a4b27bb62529639e48.tar.gz
android-node-v8-448ec0b5aaa8b07381a865a4b27bb62529639e48.tar.bz2
android-node-v8-448ec0b5aaa8b07381a865a4b27bb62529639e48.zip
fs: move type checking in fs.futimes 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>
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/fs.js b/lib/fs.js
index f13488ba0e..b40d726404 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1301,7 +1301,7 @@ fs.chownSync = function(path, uid, gid) {
};
// converts Date or number to a fractional UNIX timestamp
-function toUnixTimestamp(time) {
+function toUnixTimestamp(time, name = 'time') {
// eslint-disable-next-line eqeqeq
if (typeof time === 'string' && +time == time) {
return +time;
@@ -1316,10 +1316,10 @@ function toUnixTimestamp(time) {
// convert to 123.456 UNIX timestamp
return time.getTime() / 1000;
}
- throw new errors.Error('ERR_INVALID_ARG_TYPE',
- 'time',
- ['Date', 'Time in seconds'],
- time);
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
+ name,
+ ['Date', 'Time in seconds'],
+ time);
}
// exported for unit tests, not for public consumption
@@ -1347,16 +1347,24 @@ fs.utimesSync = function(path, atime, mtime) {
};
fs.futimes = function(fd, atime, mtime, callback) {
- atime = toUnixTimestamp(atime);
- mtime = toUnixTimestamp(mtime);
- var req = new FSReqWrap();
+ if (!Number.isInteger(fd))
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', 'number');
+ if (fd < 0 || fd > 0xFFFFFFFF)
+ throw new errors.RangeError('ERR_OUT_OF_RANGE', 'fd');
+ atime = toUnixTimestamp(atime, 'atime');
+ mtime = toUnixTimestamp(mtime, 'mtime');
+ const req = new FSReqWrap();
req.oncomplete = makeCallback(callback);
binding.futimes(fd, atime, mtime, req);
};
fs.futimesSync = function(fd, atime, mtime) {
- atime = toUnixTimestamp(atime);
- mtime = toUnixTimestamp(mtime);
+ if (!Number.isInteger(fd))
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', 'number');
+ if (fd < 0 || fd > 0xFFFFFFFF)
+ throw new errors.RangeError('ERR_OUT_OF_RANGE', 'fd');
+ atime = toUnixTimestamp(atime, 'atime');
+ mtime = toUnixTimestamp(mtime, 'mtime');
binding.futimes(fd, atime, mtime);
};