| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,8 +3,6 @@ | |||
| 3 | 3 | const { | |
| 4 | 4 | Array, | |
| 5 | 5 | MathMin, | |
| 6 | - NumberIsInteger, | ||
| 7 | - NumberIsSafeInteger, | ||
| 8 | 6 | ObjectDefineProperty, | |
| 9 | 7 | ObjectSetPrototypeOf, | |
| 10 | 8 | Symbol, | |
@@ -15,7 +13,7 @@ const { | |||
| 15 | 13 | ERR_OUT_OF_RANGE, | |
| 16 | 14 | ERR_STREAM_DESTROYED | |
| 17 | 15 | } = require('internal/errors').codes; | |
| 18 | - const { validateNumber } = require('internal/validators'); | ||
| 16 | + const { validateInteger } = require('internal/validators'); | ||
| 19 | 17 | const fs = require('fs'); | |
| 20 | 18 | const { Buffer } = require('buffer'); | |
| 21 | 19 | const { | |
@@ -46,19 +44,6 @@ function allocNewPool(poolSize) { | |||
| 46 | 44 | pool.used = 0; | |
| 47 | 45 | } | |
| 48 | 46 | ||
| 49 | - // Check the `this.start` and `this.end` of stream. | ||
| 50 | - function checkPosition(pos, name) { | ||
| 51 | - if (!NumberIsSafeInteger(pos)) { | ||
| 52 | - validateNumber(pos, name); | ||
| 53 | - if (!NumberIsInteger(pos)) | ||
| 54 | - throw new ERR_OUT_OF_RANGE(name, 'an integer', pos); | ||
| 55 | - throw new ERR_OUT_OF_RANGE(name, '>= 0 and <= 2 ** 53 - 1', pos); | ||
| 56 | - } | ||
| 57 | - if (pos < 0) { | ||
| 58 | - throw new ERR_OUT_OF_RANGE(name, '>= 0 and <= 2 ** 53 - 1', pos); | ||
| 59 | - } | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | 47 | function roundUpToMultipleOf8(n) { | |
| 63 | 48 | return (n + 7) & ~7; // Align to 8 byte boundary. | |
| 64 | 49 | } | |
@@ -111,15 +96,15 @@ function ReadStream(path, options) { | |||
| 111 | 96 | this[kIsPerformingIO] = false; | |
| 112 | 97 | ||
| 113 | 98 | if (this.start !== undefined) { | |
| 114 | - checkPosition(this.start, 'start'); | ||
| 99 | + validateInteger(this.start, 'start', 0); | ||
| 115 | 100 | ||
| 116 | 101 | this.pos = this.start; | |
| 117 | 102 | } | |
| 118 | 103 | ||
| 119 | 104 | if (this.end === undefined) { | |
| 120 | 105 | this.end = Infinity; | |
| 121 | 106 | } else if (this.end !== Infinity) { | |
| 122 | - checkPosition(this.end, 'end'); | ||
| 107 | + validateInteger(this.end, 'end', 0); | ||
| 123 | 108 | ||
| 124 | 109 | if (this.start !== undefined && this.start > this.end) { | |
| 125 | 110 | throw new ERR_OUT_OF_RANGE( | |
@@ -339,7 +324,7 @@ function WriteStream(path, options) { | |||
| 339 | 324 | this[kIsPerformingIO] = false; | |
| 340 | 325 | ||
| 341 | 326 | if (this.start !== undefined) { | |
| 342 | - checkPosition(this.start, 'start'); | ||
| 327 | + validateInteger(this.start, 'start', 0); | ||
| 343 | 328 | ||
| 344 | 329 | this.pos = this.start; | |
| 345 | 330 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -182,10 +182,12 @@ const run_test_4 = common.mustCall(function() { | |||
| 182 | 182 | const fn = () => { | |
| 183 | 183 | fs.createWriteStream(filepath, { start: -5, flags: 'r+' }); | |
| 184 | 184 | }; | |
| 185 | + // Verify the range of values using a common integer verifier. | ||
| 186 | + // Limit Number.MAX_SAFE_INTEGER | ||
| 185 | 187 | const err = { | |
| 186 | 188 | code: 'ERR_OUT_OF_RANGE', | |
| 187 | 189 | message: 'The value of "start" is out of range. ' + | |
| 188 | - 'It must be >= 0 and <= 2 ** 53 - 1. Received -5', | ||
| 190 | + `It must be >= 0 && <= ${Number.MAX_SAFE_INTEGER}. Received -5`, | ||
| 189 | 191 | name: 'RangeError' | |
| 190 | 192 | }; | |
| 191 | 193 | assert.throws(fn, err); | |
@@ -197,10 +199,13 @@ const run_test_5 = common.mustCall(function() { | |||
| 197 | 199 | const fn = () => { | |
| 198 | 200 | fs.createWriteStream(filepath, { start: 2 ** 53, flags: 'r+' }); | |
| 199 | 201 | }; | |
| 202 | + // Verify the range of values using a common integer verifier. | ||
| 203 | + // Limit Number.MAX_SAFE_INTEGER | ||
| 200 | 204 | const err = { | |
| 201 | 205 | code: 'ERR_OUT_OF_RANGE', | |
| 202 | 206 | message: 'The value of "start" is out of range. It must be ' + | |
| 203 | - '>= 0 and <= 2 ** 53 - 1. Received 9_007_199_254_740_992', | ||
| 207 | + `>= 0 && <= ${Number.MAX_SAFE_INTEGER}. ` + | ||
| 208 | + 'Received 9_007_199_254_740_992', | ||
| 204 | 209 | name: 'RangeError' | |
| 205 | 210 | }; | |
| 206 | 211 | assert.throws(fn, err); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments