| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d291338 commit a0f7284
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,6 +122,15 @@ E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.'); | |||
| 122 | 122 | E('ERR_HTTP_INVALID_STATUS_CODE', | |
| 123 | 123 | (originalStatusCode) => `Invalid status code: ${originalStatusCode}`); | |
| 124 | 124 | E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range'); | |
| 125 | + E('ERR_INVALID_ARRAY_LENGTH', | ||
| 126 | + (name, length, actual) => { | ||
| 127 | + let msg = `The "${name}" array must have a length of ${length}`; | ||
| 128 | + if (arguments.length > 2) { | ||
| 129 | + const len = Array.isArray(actual) ? actual.length : actual; | ||
| 130 | + msg += `. Received length ${len}`; | ||
| 131 | + } | ||
| 132 | + return msg; | ||
| 133 | + }); | ||
| 125 | 134 | E('ERR_INVALID_ARG_TYPE', invalidArgType); | |
| 126 | 135 | E('ERR_INVALID_CALLBACK', 'callback must be a function'); | |
| 127 | 136 | E('ERR_INVALID_FD', (fd) => `"fd" must be a positive integer: ${fd}`); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,14 +78,19 @@ function setup_hrtime() { | |||
| 78 | 78 | _hrtime(hrValues); | |
| 79 | 79 | ||
| 80 | 80 | if (time !== undefined) { | |
| 81 | - if (Array.isArray(time) && time.length === 2) { | ||
| 82 | - const sec = (hrValues[0] * 0x100000000 + hrValues[1]) - time[0]; | ||
| 83 | - const nsec = hrValues[2] - time[1]; | ||
| 84 | - const needsBorrow = nsec < 0; | ||
| 85 | - return [needsBorrow ? sec - 1 : sec, needsBorrow ? nsec + 1e9 : nsec]; | ||
| 81 | + if (!Array.isArray(time)) { | ||
| 82 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'time', 'Array', | ||
| 83 | + time); | ||
| 86 | 84 | } | |
| 87 | - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 88 | - 'process.hrtime()', 'Array'); | ||
| 85 | + if (time.length !== 2) { | ||
| 86 | + throw new errors.TypeError('ERR_INVALID_ARRAY_LENGTH', 'time', 2, | ||
| 87 | + time); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + const sec = (hrValues[0] * 0x100000000 + hrValues[1]) - time[0]; | ||
| 91 | + const nsec = hrValues[2] - time[1]; | ||
| 92 | + const needsBorrow = nsec < 0; | ||
| 93 | + return [needsBorrow ? sec - 1 : sec, needsBorrow ? nsec + 1e9 : nsec]; | ||
| 89 | 94 | } | |
| 90 | 95 | ||
| 91 | 96 | return [ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,25 +32,35 @@ validateTuple(tuple); | |||
| 32 | 32 | // validate that passing an existing tuple returns another valid tuple | |
| 33 | 33 | validateTuple(process.hrtime(tuple)); | |
| 34 | 34 | ||
| 35 | - const invalidHrtimeArgument = common.expectsError({ | ||
| 36 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 37 | - type: TypeError, | ||
| 38 | - message: 'The "process.hrtime()" argument must be of type Array' | ||
| 39 | - }); | ||
| 40 | - | ||
| 41 | 35 | // test that only an Array may be passed to process.hrtime() | |
| 42 | 36 | assert.throws(() => { | |
| 43 | 37 | process.hrtime(1); | |
| 44 | - }, invalidHrtimeArgument); | ||
| 38 | + }, common.expectsError({ | ||
| 39 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 40 | + type: TypeError, | ||
| 41 | + message: 'The "time" argument must be of type Array. Received type number' | ||
| 42 | + })); | ||
| 45 | 43 | assert.throws(() => { | |
| 46 | 44 | process.hrtime([]); | |
| 47 | - }, invalidHrtimeArgument); | ||
| 45 | + }, common.expectsError({ | ||
| 46 | + code: 'ERR_INVALID_ARRAY_LENGTH', | ||
| 47 | + type: TypeError, | ||
| 48 | + message: 'The "time" array must have a length of 2. Received length 0' | ||
| 49 | + })); | ||
| 48 | 50 | assert.throws(() => { | |
| 49 | 51 | process.hrtime([1]); | |
| 50 | - }, invalidHrtimeArgument); | ||
| 52 | + }, common.expectsError({ | ||
| 53 | + code: 'ERR_INVALID_ARRAY_LENGTH', | ||
| 54 | + type: TypeError, | ||
| 55 | + message: 'The "time" array must have a length of 2. Received length 1' | ||
| 56 | + })); | ||
| 51 | 57 | assert.throws(() => { | |
| 52 | 58 | process.hrtime([1, 2, 3]); | |
| 53 | - }, invalidHrtimeArgument); | ||
| 59 | + }, common.expectsError({ | ||
| 60 | + code: 'ERR_INVALID_ARRAY_LENGTH', | ||
| 61 | + type: TypeError, | ||
| 62 | + message: 'The "time" array must have a length of 2. Received length 3' | ||
| 63 | + })); | ||
| 54 | 64 | ||
| 55 | 65 | function validateTuple(tuple) { | |
| 56 | 66 | assert(Array.isArray(tuple)); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments