| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 17d9495 commit f194626
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -395,14 +395,14 @@ function readFileSync(path, options) { | |||
| 395 | 395 | } | |
| 396 | 396 | ||
| 397 | 397 | function close(fd, callback) { | |
| 398 | - validateUint32(fd, 'fd'); | ||
| 398 | + validateInt32(fd, 'fd', 0); | ||
| 399 | 399 | const req = new FSReqCallback(); | |
| 400 | 400 | req.oncomplete = makeCallback(callback); | |
| 401 | 401 | binding.close(fd, req); | |
| 402 | 402 | } | |
| 403 | 403 | ||
| 404 | 404 | function closeSync(fd) { | |
| 405 | - validateUint32(fd, 'fd'); | ||
| 405 | + validateInt32(fd, 'fd', 0); | ||
| 406 | 406 | ||
| 407 | 407 | const ctx = {}; | |
| 408 | 408 | binding.close(fd, undefined, ctx); | |
@@ -449,7 +449,7 @@ function openSync(path, flags, mode) { | |||
| 449 | 449 | } | |
| 450 | 450 | ||
| 451 | 451 | function read(fd, buffer, offset, length, position, callback) { | |
| 452 | - validateUint32(fd, 'fd'); | ||
| 452 | + validateInt32(fd, 'fd', 0); | ||
| 453 | 453 | validateBuffer(buffer); | |
| 454 | 454 | callback = maybeCallback(callback); | |
| 455 | 455 | ||
@@ -487,7 +487,7 @@ Object.defineProperty(read, internalUtil.customPromisifyArgs, | |||
| 487 | 487 | { value: ['bytesRead', 'buffer'], enumerable: false }); | |
| 488 | 488 | ||
| 489 | 489 | function readSync(fd, buffer, offset, length, position) { | |
| 490 | - validateUint32(fd, 'fd'); | ||
| 490 | + validateInt32(fd, 'fd', 0); | ||
| 491 | 491 | validateBuffer(buffer); | |
| 492 | 492 | ||
| 493 | 493 | offset |= 0; | |
@@ -524,7 +524,7 @@ function write(fd, buffer, offset, length, position, callback) { | |||
| 524 | 524 | callback(err, written || 0, buffer); | |
| 525 | 525 | } | |
| 526 | 526 | ||
| 527 | - validateUint32(fd, 'fd'); | ||
| 527 | + validateInt32(fd, 'fd', 0); | ||
| 528 | 528 | ||
| 529 | 529 | const req = new FSReqCallback(); | |
| 530 | 530 | req.oncomplete = wrapper; | |
@@ -564,7 +564,7 @@ Object.defineProperty(write, internalUtil.customPromisifyArgs, | |||
| 564 | 564 | // OR | |
| 565 | 565 | // fs.writeSync(fd, string[, position[, encoding]]); | |
| 566 | 566 | function writeSync(fd, buffer, offset, length, position) { | |
| 567 | - validateUint32(fd, 'fd'); | ||
| 567 | + validateInt32(fd, 'fd', 0); | ||
| 568 | 568 | const ctx = {}; | |
| 569 | 569 | let result; | |
| 570 | 570 | if (isArrayBufferView(buffer)) { | |
@@ -661,7 +661,7 @@ function ftruncate(fd, len = 0, callback) { | |||
| 661 | 661 | callback = len; | |
| 662 | 662 | len = 0; | |
| 663 | 663 | } | |
| 664 | - validateUint32(fd, 'fd'); | ||
| 664 | + validateInt32(fd, 'fd', 0); | ||
| 665 | 665 | validateInteger(len, 'len'); | |
| 666 | 666 | len = Math.max(0, len); | |
| 667 | 667 | const req = new FSReqCallback(); | |
@@ -670,7 +670,7 @@ function ftruncate(fd, len = 0, callback) { | |||
| 670 | 670 | } | |
| 671 | 671 | ||
| 672 | 672 | function ftruncateSync(fd, len = 0) { | |
| 673 | - validateUint32(fd, 'fd'); | ||
| 673 | + validateInt32(fd, 'fd', 0); | ||
| 674 | 674 | validateInteger(len, 'len'); | |
| 675 | 675 | len = Math.max(0, len); | |
| 676 | 676 | const ctx = {}; | |
@@ -694,28 +694,28 @@ function rmdirSync(path) { | |||
| 694 | 694 | } | |
| 695 | 695 | ||
| 696 | 696 | function fdatasync(fd, callback) { | |
| 697 | - validateUint32(fd, 'fd'); | ||
| 697 | + validateInt32(fd, 'fd', 0); | ||
| 698 | 698 | const req = new FSReqCallback(); | |
| 699 | 699 | req.oncomplete = makeCallback(callback); | |
| 700 | 700 | binding.fdatasync(fd, req); | |
| 701 | 701 | } | |
| 702 | 702 | ||
| 703 | 703 | function fdatasyncSync(fd) { | |
| 704 | - validateUint32(fd, 'fd'); | ||
| 704 | + validateInt32(fd, 'fd', 0); | ||
| 705 | 705 | const ctx = {}; | |
| 706 | 706 | binding.fdatasync(fd, undefined, ctx); | |
| 707 | 707 | handleErrorFromBinding(ctx); | |
| 708 | 708 | } | |
| 709 | 709 | ||
| 710 | 710 | function fsync(fd, callback) { | |
| 711 | - validateUint32(fd, 'fd'); | ||
| 711 | + validateInt32(fd, 'fd', 0); | ||
| 712 | 712 | const req = new FSReqCallback(); | |
| 713 | 713 | req.oncomplete = makeCallback(callback); | |
| 714 | 714 | binding.fsync(fd, req); | |
| 715 | 715 | } | |
| 716 | 716 | ||
| 717 | 717 | function fsyncSync(fd) { | |
| 718 | - validateUint32(fd, 'fd'); | ||
| 718 | + validateInt32(fd, 'fd', 0); | ||
| 719 | 719 | const ctx = {}; | |
| 720 | 720 | binding.fsync(fd, undefined, ctx); | |
| 721 | 721 | handleErrorFromBinding(ctx); | |
@@ -801,7 +801,7 @@ function fstat(fd, options, callback) { | |||
| 801 | 801 | callback = options; | |
| 802 | 802 | options = {}; | |
| 803 | 803 | } | |
| 804 | - validateUint32(fd, 'fd'); | ||
| 804 | + validateInt32(fd, 'fd', 0); | ||
| 805 | 805 | const req = new FSReqCallback(options.bigint); | |
| 806 | 806 | req.oncomplete = makeStatsCallback(callback); | |
| 807 | 807 | binding.fstat(fd, options.bigint, req); | |
@@ -832,7 +832,7 @@ function stat(path, options, callback) { | |||
| 832 | 832 | } | |
| 833 | 833 | ||
| 834 | 834 | function fstatSync(fd, options = {}) { | |
| 835 | - validateUint32(fd, 'fd'); | ||
| 835 | + validateInt32(fd, 'fd', 0); | ||
| 836 | 836 | const ctx = { fd }; | |
| 837 | 837 | const stats = binding.fstat(fd, options.bigint, undefined, ctx); | |
| 838 | 838 | handleErrorFromBinding(ctx); | |
@@ -1065,7 +1065,7 @@ function lchownSync(path, uid, gid) { | |||
| 1065 | 1065 | } | |
| 1066 | 1066 | ||
| 1067 | 1067 | function fchown(fd, uid, gid, callback) { | |
| 1068 | - validateUint32(fd, 'fd'); | ||
| 1068 | + validateInt32(fd, 'fd', 0); | ||
| 1069 | 1069 | validateUint32(uid, 'uid'); | |
| 1070 | 1070 | validateUint32(gid, 'gid'); | |
| 1071 | 1071 | ||
@@ -1075,7 +1075,7 @@ function fchown(fd, uid, gid, callback) { | |||
| 1075 | 1075 | } | |
| 1076 | 1076 | ||
| 1077 | 1077 | function fchownSync(fd, uid, gid) { | |
| 1078 | - validateUint32(fd, 'fd'); | ||
| 1078 | + validateInt32(fd, 'fd', 0); | ||
| 1079 | 1079 | validateUint32(uid, 'uid'); | |
| 1080 | 1080 | validateUint32(gid, 'gid'); | |
| 1081 | 1081 | ||
@@ -1126,7 +1126,7 @@ function utimesSync(path, atime, mtime) { | |||
| 1126 | 1126 | } | |
| 1127 | 1127 | ||
| 1128 | 1128 | function futimes(fd, atime, mtime, callback) { | |
| 1129 | - validateUint32(fd, 'fd'); | ||
| 1129 | + validateInt32(fd, 'fd', 0); | ||
| 1130 | 1130 | atime = toUnixTimestamp(atime, 'atime'); | |
| 1131 | 1131 | mtime = toUnixTimestamp(mtime, 'mtime'); | |
| 1132 | 1132 | const req = new FSReqCallback(); | |
@@ -1135,7 +1135,7 @@ function futimes(fd, atime, mtime, callback) { | |||
| 1135 | 1135 | } | |
| 1136 | 1136 | ||
| 1137 | 1137 | function futimesSync(fd, atime, mtime) { | |
| 1138 | - validateUint32(fd, 'fd'); | ||
| 1138 | + validateInt32(fd, 'fd', 0); | ||
| 1139 | 1139 | atime = toUnixTimestamp(atime, 'atime'); | |
| 1140 | 1140 | mtime = toUnixTimestamp(mtime, 'mtime'); | |
| 1141 | 1141 | const ctx = {}; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,13 +4,17 @@ require('../common'); | |||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const fs = require('fs'); | |
| 6 | 6 | ||
| 7 | - function test(input, errObj) { | ||
| 7 | + function testFd(input, errObj) { | ||
| 8 | 8 | assert.throws(() => fs.fchown(input), errObj); | |
| 9 | 9 | assert.throws(() => fs.fchownSync(input), errObj); | |
| 10 | - errObj.message = errObj.message.replace('fd', 'uid'); | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + function testUid(input, errObj) { | ||
| 11 | 13 | assert.throws(() => fs.fchown(1, input), errObj); | |
| 12 | 14 | assert.throws(() => fs.fchownSync(1, input), errObj); | |
| 13 | - errObj.message = errObj.message.replace('uid', 'gid'); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + function testGid(input, errObj) { | ||
| 14 | 18 | assert.throws(() => fs.fchown(1, 1, input), errObj); | |
| 15 | 19 | assert.throws(() => fs.fchownSync(1, 1, input), errObj); | |
| 16 | 20 | } | |
@@ -22,7 +26,11 @@ function test(input, errObj) { | |||
| 22 | 26 | message: 'The "fd" argument must be of type number. Received type ' + | |
| 23 | 27 | typeof input | |
| 24 | 28 | }; | |
| 25 | - test(input, errObj); | ||
| 29 | + testFd(input, errObj); | ||
| 30 | + errObj.message = errObj.message.replace('fd', 'uid'); | ||
| 31 | + testUid(input, errObj); | ||
| 32 | + errObj.message = errObj.message.replace('uid', 'gid'); | ||
| 33 | + testGid(input, errObj); | ||
| 26 | 34 | }); | |
| 27 | 35 | ||
| 28 | 36 | [Infinity, NaN].forEach((input) => { | |
@@ -32,15 +40,24 @@ function test(input, errObj) { | |||
| 32 | 40 | message: 'The value of "fd" is out of range. It must be an integer. ' + | |
| 33 | 41 | `Received ${input}` | |
| 34 | 42 | }; | |
| 35 | - test(input, errObj); | ||
| 43 | + testFd(input, errObj); | ||
| 44 | + errObj.message = errObj.message.replace('fd', 'uid'); | ||
| 45 | + testUid(input, errObj); | ||
| 46 | + errObj.message = errObj.message.replace('uid', 'gid'); | ||
| 47 | + testGid(input, errObj); | ||
| 36 | 48 | }); | |
| 37 | 49 | ||
| 38 | 50 | [-1, 2 ** 32].forEach((input) => { | |
| 39 | 51 | const errObj = { | |
| 40 | 52 | code: 'ERR_OUT_OF_RANGE', | |
| 41 | 53 | name: 'RangeError', | |
| 42 | 54 | message: 'The value of "fd" is out of range. It must be ' + | |
| 43 | - `>= 0 && < 4294967296. Received ${input}` | ||
| 55 | + `>= 0 && <= 2147483647. Received ${input}` | ||
| 44 | 56 | }; | |
| 45 | - test(input, errObj); | ||
| 57 | + testFd(input, errObj); | ||
| 58 | + errObj.message = 'The value of "uid" is out of range. It must be >= 0 && ' + | ||
| 59 | + `< 4294967296. Received ${input}`; | ||
| 60 | + testUid(input, errObj); | ||
| 61 | + errObj.message = errObj.message.replace('uid', 'gid'); | ||
| 62 | + testGid(input, errObj); | ||
| 46 | 63 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -210,7 +210,7 @@ const expectRangeError = { | |||
| 210 | 210 | code: 'ERR_OUT_OF_RANGE', | |
| 211 | 211 | type: RangeError, | |
| 212 | 212 | message: 'The value of "fd" is out of range. ' + | |
| 213 | - 'It must be >= 0 && < 4294967296. Received -1' | ||
| 213 | + 'It must be >= 0 && <= 2147483647. Received -1' | ||
| 214 | 214 | }; | |
| 215 | 215 | // futimes-only error cases | |
| 216 | 216 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments