| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 779310a commit 2459c11
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2904,7 +2904,7 @@ changes: | |||
| 2904 | 2904 | * `buffer` {Buffer|TypedArray|DataView} | |
| 2905 | 2905 | * `offset` {integer} | |
| 2906 | 2906 | * `length` {integer} | |
| 2907 | - * `position` {integer} | ||
| 2907 | + * `position` {integer|bigint} | ||
| 2908 | 2908 | * `callback` {Function} | |
| 2909 | 2909 | * `err` {Error} | |
| 2910 | 2910 | * `bytesRead` {integer} | |
@@ -2945,7 +2945,7 @@ changes: | |||
| 2945 | 2945 | * `buffer` {Buffer|TypedArray|DataView} **Default:** `Buffer.alloc(16384)` | |
| 2946 | 2946 | * `offset` {integer} **Default:** `0` | |
| 2947 | 2947 | * `length` {integer} **Default:** `buffer.length` | |
| 2948 | - * `position` {integer} **Default:** `null` | ||
| 2948 | + * `position` {integer|bigint} **Default:** `null` | ||
| 2949 | 2949 | * `callback` {Function} | |
| 2950 | 2950 | * `err` {Error} | |
| 2951 | 2951 | * `bytesRead` {integer} | |
@@ -3264,7 +3264,7 @@ changes: | |||
| 3264 | 3264 | * `buffer` {Buffer|TypedArray|DataView} | |
| 3265 | 3265 | * `offset` {integer} | |
| 3266 | 3266 | * `length` {integer} | |
| 3267 | - * `position` {integer} | ||
| 3267 | + * `position` {integer|bigint} | ||
| 3268 | 3268 | * Returns: {number} | |
| 3269 | 3269 | ||
| 3270 | 3270 | Returns the number of `bytesRead`. | |
@@ -3287,7 +3287,7 @@ changes: | |||
| 3287 | 3287 | * `options` {Object} | |
| 3288 | 3288 | * `offset` {integer} **Default:** `0` | |
| 3289 | 3289 | * `length` {integer} **Default:** `buffer.length` | |
| 3290 | - * `position` {integer} **Default:** `null` | ||
| 3290 | + * `position` {integer|bigint} **Default:** `null` | ||
| 3291 | 3291 | * Returns: {number} | |
| 3292 | 3292 | ||
| 3293 | 3293 | Returns the number of `bytesRead`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,6 @@ const { | |||
| 36 | 36 | Map, | |
| 37 | 37 | MathMax, | |
| 38 | 38 | Number, | |
| 39 | - NumberIsSafeInteger, | ||
| 40 | 39 | ObjectCreate, | |
| 41 | 40 | ObjectDefineProperties, | |
| 42 | 41 | ObjectDefineProperty, | |
@@ -69,7 +68,8 @@ const { | |||
| 69 | 68 | ERR_INVALID_ARG_VALUE, | |
| 70 | 69 | ERR_INVALID_ARG_TYPE, | |
| 71 | 70 | ERR_INVALID_CALLBACK, | |
| 72 | - ERR_FEATURE_UNAVAILABLE_ON_PLATFORM | ||
| 71 | + ERR_FEATURE_UNAVAILABLE_ON_PLATFORM, | ||
| 72 | + ERR_OUT_OF_RANGE, | ||
| 73 | 73 | }, | |
| 74 | 74 | hideStackFrames, | |
| 75 | 75 | uvErrmapGet, | |
@@ -553,9 +553,23 @@ function read(fd, buffer, offset, length, position, callback) { | |||
| 553 | 553 | ||
| 554 | 554 | validateOffsetLengthRead(offset, length, buffer.byteLength); | |
| 555 | 555 | ||
| 556 | - if (!NumberIsSafeInteger(position)) | ||
| 556 | + if (position == null) | ||
| 557 | 557 | position = -1; | |
| 558 | 558 | ||
| 559 | + if (typeof position === 'number') { | ||
| 560 | + validateInteger(position, 'position'); | ||
| 561 | + } else if (typeof position === 'bigint') { | ||
| 562 | + if (!(position >= -(2n ** 63n) && position <= 2n ** 63n - 1n)) { | ||
| 563 | + throw new ERR_OUT_OF_RANGE('position', | ||
| 564 | + `>= ${-(2n ** 63n)} && <= ${2n ** 63n - 1n}`, | ||
| 565 | + position); | ||
| 566 | + } | ||
| 567 | + } else { | ||
| 568 | + throw new ERR_INVALID_ARG_TYPE('position', | ||
| 569 | + ['integer', 'bigint'], | ||
| 570 | + position); | ||
| 571 | + } | ||
| 572 | + | ||
| 559 | 573 | function wrapper(err, bytesRead) { | |
| 560 | 574 | // Retain a reference to buffer so that it can't be GC'ed too soon. | |
| 561 | 575 | callback(err, bytesRead || 0, buffer); | |
@@ -605,9 +619,23 @@ function readSync(fd, buffer, offset, length, position) { | |||
| 605 | 619 | ||
| 606 | 620 | validateOffsetLengthRead(offset, length, buffer.byteLength); | |
| 607 | 621 | ||
| 608 | - if (!NumberIsSafeInteger(position)) | ||
| 622 | + if (position == null) | ||
| 609 | 623 | position = -1; | |
| 610 | 624 | ||
| 625 | + if (typeof position === 'number') { | ||
| 626 | + validateInteger(position, 'position'); | ||
| 627 | + } else if (typeof position === 'bigint') { | ||
| 628 | + if (!(position >= -(2n ** 63n) && position <= 2n ** 63n - 1n)) { | ||
| 629 | + throw new ERR_OUT_OF_RANGE('position', | ||
| 630 | + `>= ${-(2n ** 63n)} && <= ${2n ** 63n - 1n}`, | ||
| 631 | + position); | ||
| 632 | + } | ||
| 633 | + } else { | ||
| 634 | + throw new ERR_INVALID_ARG_TYPE('position', | ||
| 635 | + ['integer', 'bigint'], | ||
| 636 | + position); | ||
| 637 | + } | ||
| 638 | + | ||
| 611 | 639 | const ctx = {}; | |
| 612 | 640 | const result = binding.read(fd, buffer, offset, length, position, | |
| 613 | 641 | undefined, ctx); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,6 +51,7 @@ namespace node { | |||
| 51 | 51 | namespace fs { | |
| 52 | 52 | ||
| 53 | 53 | using v8::Array; | |
| 54 | + using v8::BigInt; | ||
| 54 | 55 | using v8::Boolean; | |
| 55 | 56 | using v8::Context; | |
| 56 | 57 | using v8::EscapableHandleScope; | |
@@ -2037,8 +2038,10 @@ static void Read(const FunctionCallbackInfo<Value>& args) { | |||
| 2037 | 2038 | const size_t len = static_cast<size_t>(args[3].As<Int32>()->Value()); | |
| 2038 | 2039 | CHECK(Buffer::IsWithinBounds(off, len, buffer_length)); | |
| 2039 | 2040 | ||
| 2040 | - CHECK(IsSafeJsInt(args[4])); | ||
| 2041 | - const int64_t pos = args[4].As<Integer>()->Value(); | ||
| 2041 | + CHECK(IsSafeJsInt(args[4]) || args[4]->IsBigInt()); | ||
| 2042 | + const int64_t pos = args[4]->IsNumber() ? | ||
| 2043 | + args[4].As<Integer>()->Value() : | ||
| 2044 | + args[4].As<BigInt>()->Int64Value(); | ||
| 2042 | 2045 | ||
| 2043 | 2046 | char* buf = buffer_data + off; | |
| 2044 | 2047 | uv_buf_t uvbuf = uv_buf_init(buf, len); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,47 @@ assert.throws(() => { | |||
| 74 | 74 | 'It must be >= 0. Received -1' | |
| 75 | 75 | }); | |
| 76 | 76 | ||
| 77 | + [true, () => {}, {}, ''].forEach((value) => { | ||
| 78 | + assert.throws(() => { | ||
| 79 | + fs.read(fd, | ||
| 80 | + Buffer.allocUnsafe(expected.length), | ||
| 81 | + 0, | ||
| 82 | + expected.length, | ||
| 83 | + value, | ||
| 84 | + common.mustNotCall()); | ||
| 85 | + }, { | ||
| 86 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 87 | + name: 'TypeError' | ||
| 88 | + }); | ||
| 89 | + }); | ||
| 90 | + | ||
| 91 | + [0.5, 2 ** 53, 2n ** 63n].forEach((value) => { | ||
| 92 | + assert.throws(() => { | ||
| 93 | + fs.read(fd, | ||
| 94 | + Buffer.allocUnsafe(expected.length), | ||
| 95 | + 0, | ||
| 96 | + expected.length, | ||
| 97 | + value, | ||
| 98 | + common.mustNotCall()); | ||
| 99 | + }, { | ||
| 100 | + code: 'ERR_OUT_OF_RANGE', | ||
| 101 | + name: 'RangeError' | ||
| 102 | + }); | ||
| 103 | + }); | ||
| 104 | + | ||
| 105 | + fs.read(fd, | ||
| 106 | + Buffer.allocUnsafe(expected.length), | ||
| 107 | + 0, | ||
| 108 | + expected.length, | ||
| 109 | + 0n, | ||
| 110 | + common.mustCall()); | ||
| 111 | + | ||
| 112 | + fs.read(fd, | ||
| 113 | + Buffer.allocUnsafe(expected.length), | ||
| 114 | + 0, | ||
| 115 | + expected.length, | ||
| 116 | + 2n ** 53n - 1n, | ||
| 117 | + common.mustCall()); | ||
| 77 | 118 | ||
| 78 | 119 | assert.throws( | |
| 79 | 120 | () => fs.readSync(fd, expected.length, 0, 'utf-8'), | |
@@ -147,3 +188,48 @@ assert.throws(() => { | |||
| 147 | 188 | message: 'The value of "length" is out of range. ' + | |
| 148 | 189 | 'It must be <= 4. Received 5' | |
| 149 | 190 | }); | |
| 191 | + | ||
| 192 | + [true, () => {}, {}, ''].forEach((value) => { | ||
| 193 | + assert.throws(() => { | ||
| 194 | + fs.readSync(fd, | ||
| 195 | + Buffer.allocUnsafe(expected.length), | ||
| 196 | + 0, | ||
| 197 | + expected.length, | ||
| 198 | + value); | ||
| 199 | + }, { | ||
| 200 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 201 | + name: 'TypeError' | ||
| 202 | + }); | ||
| 203 | + }); | ||
| 204 | + | ||
| 205 | + [0.5, 2 ** 53, 2n ** 63n].forEach((value) => { | ||
| 206 | + assert.throws(() => { | ||
| 207 | + fs.readSync(fd, | ||
| 208 | + Buffer.allocUnsafe(expected.length), | ||
| 209 | + 0, | ||
| 210 | + expected.length, | ||
| 211 | + value); | ||
| 212 | + }, { | ||
| 213 | + code: 'ERR_OUT_OF_RANGE', | ||
| 214 | + name: 'RangeError' | ||
| 215 | + }); | ||
| 216 | + }); | ||
| 217 | + | ||
| 218 | + fs.readSync(fd, | ||
| 219 | + Buffer.allocUnsafe(expected.length), | ||
| 220 | + 0, | ||
| 221 | + expected.length, | ||
| 222 | + 0n); | ||
| 223 | + | ||
| 224 | + try { | ||
| 225 | + fs.readSync(fd, | ||
| 226 | + Buffer.allocUnsafe(expected.length), | ||
| 227 | + 0, | ||
| 228 | + expected.length, | ||
| 229 | + 2n ** 53n - 1n); | ||
| 230 | + } catch (err) { | ||
| 231 | + // On systems where max file size is below 2^53-1, we'd expect a EFBIG error. | ||
| 232 | + // This is not using `assert.throws` because the above call should not raise | ||
| 233 | + // any error on systems that allows file of that size. | ||
| 234 | + if (err.code !== 'EFBIG') throw err; | ||
| 235 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments