| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 52fe762 commit 9e0f771
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -224,7 +224,8 @@ Buffer.from = function from(value, encodingOrOffset, length) { | |||
| 224 | 224 | throw new errors.TypeError( | |
| 225 | 225 | 'ERR_INVALID_ARG_TYPE', | |
| 226 | 226 | 'first argument', | |
| 227 | - ['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'] | ||
| 227 | + ['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'], | ||
| 228 | + value | ||
| 228 | 229 | ); | |
| 229 | 230 | }; | |
| 230 | 231 | ||
@@ -507,7 +508,8 @@ function byteLength(string, encoding) { | |||
| 507 | 508 | } | |
| 508 | 509 | ||
| 509 | 510 | throw new errors.TypeError( | |
| 510 | - 'ERR_INVALID_ARG_TYPE', 'string', ['string', 'buffer', 'arrayBuffer'] | ||
| 511 | + 'ERR_INVALID_ARG_TYPE', 'string', | ||
| 512 | + ['string', 'buffer', 'arrayBuffer'], string | ||
| 511 | 513 | ); | |
| 512 | 514 | } | |
| 513 | 515 | ||
@@ -668,7 +670,8 @@ Buffer.prototype.toString = function toString(encoding, start, end) { | |||
| 668 | 670 | Buffer.prototype.equals = function equals(b) { | |
| 669 | 671 | if (!isUint8Array(b)) { | |
| 670 | 672 | throw new errors.TypeError( | |
| 671 | - 'ERR_INVALID_ARG_TYPE', 'otherBuffer', ['buffer', 'uint8Array'] | ||
| 673 | + 'ERR_INVALID_ARG_TYPE', 'otherBuffer', | ||
| 674 | + ['buffer', 'uint8Array'], b | ||
| 672 | 675 | ); | |
| 673 | 676 | } | |
| 674 | 677 | if (this === b) | |
@@ -696,7 +699,8 @@ Buffer.prototype.compare = function compare(target, | |||
| 696 | 699 | thisEnd) { | |
| 697 | 700 | if (!isUint8Array(target)) { | |
| 698 | 701 | throw new errors.TypeError( | |
| 699 | - 'ERR_INVALID_ARG_TYPE', 'target', ['buffer', 'uint8Array'] | ||
| 702 | + 'ERR_INVALID_ARG_TYPE', 'target', | ||
| 703 | + ['buffer', 'uint8Array'], target | ||
| 700 | 704 | ); | |
| 701 | 705 | } | |
| 702 | 706 | if (arguments.length === 1) | |
@@ -778,7 +782,8 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { | |||
| 778 | 782 | } | |
| 779 | 783 | ||
| 780 | 784 | throw new errors.TypeError( | |
| 781 | - 'ERR_INVALID_ARG_TYPE', 'val', ['string', 'buffer', 'uint8Array'] | ||
| 785 | + 'ERR_INVALID_ARG_TYPE', 'value', | ||
| 786 | + ['string', 'buffer', 'uint8Array'], val | ||
| 782 | 787 | ); | |
| 783 | 788 | } | |
| 784 | 789 | ||
@@ -847,7 +852,8 @@ Buffer.prototype.fill = function fill(val, start, end, encoding) { | |||
| 847 | 852 | } | |
| 848 | 853 | ||
| 849 | 854 | if (encoding !== undefined && typeof encoding !== 'string') { | |
| 850 | - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'encoding', 'string'); | ||
| 855 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'encoding', | ||
| 856 | + 'string', encoding); | ||
| 851 | 857 | } | |
| 852 | 858 | var normalizedEncoding = normalizeEncoding(encoding); | |
| 853 | 859 | if (normalizedEncoding === undefined) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,17 +5,22 @@ const assert = require('assert'); | |||
| 5 | 5 | const SlowBuffer = require('buffer').SlowBuffer; | |
| 6 | 6 | const vm = require('vm'); | |
| 7 | 7 | ||
| 8 | - // coerce values to string | ||
| 9 | - const errMsg = common.expectsError({ | ||
| 10 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 11 | - type: TypeError, | ||
| 12 | - message: 'The "string" argument must be one of type string, ' + | ||
| 13 | - 'buffer, or arrayBuffer' | ||
| 14 | - }, 4); | ||
| 15 | - assert.throws(() => { Buffer.byteLength(32, 'latin1'); }, errMsg); | ||
| 16 | - assert.throws(() => { Buffer.byteLength(NaN, 'utf8'); }, errMsg); | ||
| 17 | - assert.throws(() => { Buffer.byteLength({}, 'latin1'); }, errMsg); | ||
| 18 | - assert.throws(() => { Buffer.byteLength(); }, errMsg); | ||
| 8 | + [ | ||
| 9 | + [32, 'latin1'], | ||
| 10 | + [NaN, 'utf8'], | ||
| 11 | + [{}, 'latin1'], | ||
| 12 | + [] | ||
| 13 | + ].forEach((args) => { | ||
| 14 | + common.expectsError( | ||
| 15 | + () => Buffer.byteLength(...args), | ||
| 16 | + { | ||
| 17 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 18 | + type: TypeError, | ||
| 19 | + message: 'The "string" argument must be one of type string, ' + | ||
| 20 | + `buffer, or arrayBuffer. Received type ${typeof args[0]}` | ||
| 21 | + } | ||
| 22 | + ); | ||
| 23 | + }); | ||
| 19 | 24 | ||
| 20 | 25 | assert.strictEqual(Buffer.byteLength('', undefined, true), -1); | |
| 21 | 26 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,5 +69,6 @@ assert.throws(() => a.compare(b, -Infinity, Infinity), oor); | |||
| 69 | 69 | assert.throws(() => a.compare(), common.expectsError({ | |
| 70 | 70 | code: 'ERR_INVALID_ARG_TYPE', | |
| 71 | 71 | type: TypeError, | |
| 72 | - message: 'The "target" argument must be one of type buffer or uint8Array' | ||
| 72 | + message: 'The "target" argument must be one of ' + | ||
| 73 | + 'type buffer or uint8Array. Received type undefined' | ||
| 73 | 74 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,5 +41,6 @@ assert.throws(() => Buffer.compare('abc', Buffer.alloc(1)), errMsg); | |||
| 41 | 41 | assert.throws(() => Buffer.alloc(1).compare('abc'), common.expectsError({ | |
| 42 | 42 | code: 'ERR_INVALID_ARG_TYPE', | |
| 43 | 43 | type: TypeError, | |
| 44 | - message: 'The "target" argument must be one of type buffer or uint8Array' | ||
| 44 | + message: 'The "target" argument must be one of ' + | ||
| 45 | + 'type buffer or uint8Array. Received type string' | ||
| 45 | 46 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,10 +14,12 @@ assert.ok(!d.equals(e)); | |||
| 14 | 14 | assert.ok(d.equals(d)); | |
| 15 | 15 | assert.ok(d.equals(new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65]))); | |
| 16 | 16 | ||
| 17 | - assert.throws(() => Buffer.alloc(1).equals('abc'), | ||
| 18 | - common.expectsError({ | ||
| 19 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 20 | - type: TypeError, | ||
| 21 | - message: 'The "otherBuffer" argument must be one of type ' + | ||
| 22 | - 'buffer or uint8Array' | ||
| 23 | - })); | ||
| 17 | + common.expectsError( | ||
| 18 | + () => Buffer.alloc(1).equals('abc'), | ||
| 19 | + { | ||
| 20 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 21 | + type: TypeError, | ||
| 22 | + message: 'The "otherBuffer" argument must be one of type ' + | ||
| 23 | + 'buffer or uint8Array. Received type string' | ||
| 24 | + } | ||
| 25 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -192,45 +192,49 @@ deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, -1]), [0, 0, 0, 0]); | |||
| 192 | 192 | ||
| 193 | 193 | ||
| 194 | 194 | // Check exceptions | |
| 195 | - assert.throws( | ||
| 196 | - () => buf1.fill(0, -1), | ||
| 197 | - common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' })); | ||
| 198 | - assert.throws( | ||
| 199 | - () => buf1.fill(0, 0, buf1.length + 1), | ||
| 200 | - common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' })); | ||
| 201 | - assert.throws( | ||
| 202 | - () => buf1.fill('', -1), | ||
| 203 | - common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' })); | ||
| 204 | - assert.throws( | ||
| 205 | - () => buf1.fill('', 0, buf1.length + 1), | ||
| 206 | - common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' })); | ||
| 207 | - assert.throws( | ||
| 195 | + [ | ||
| 196 | + [0, -1], | ||
| 197 | + [0, 0, buf1.length + 1], | ||
| 198 | + ['', -1], | ||
| 199 | + ['', 0, buf1.length + 1] | ||
| 200 | + ].forEach((args) => { | ||
| 201 | + common.expectsError( | ||
| 202 | + () => buf1.fill(...args), | ||
| 203 | + { code: 'ERR_INDEX_OUT_OF_RANGE' } | ||
| 204 | + ); | ||
| 205 | + }); | ||
| 206 | + | ||
| 207 | + common.expectsError( | ||
| 208 | 208 | () => buf1.fill('a', 0, buf1.length, 'node rocks!'), | |
| 209 | - common.expectsError({ | ||
| 209 | + { | ||
| 210 | 210 | code: 'ERR_UNKNOWN_ENCODING', | |
| 211 | 211 | type: TypeError, | |
| 212 | 212 | message: 'Unknown encoding: node rocks!' | |
| 213 | - })); | ||
| 214 | - assert.throws( | ||
| 215 | - () => buf1.fill('a', 0, 0, NaN), | ||
| 216 | - common.expectsError({ | ||
| 217 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 218 | - message: 'The "encoding" argument must be of type string' | ||
| 219 | - })); | ||
| 220 | - assert.throws( | ||
| 221 | - () => buf1.fill('a', 0, 0, null), | ||
| 222 | - common.expectsError({ | ||
| 223 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 224 | - message: 'The "encoding" argument must be of type string' | ||
| 225 | - })); | ||
| 226 | - assert.throws( | ||
| 213 | + } | ||
| 214 | + ); | ||
| 215 | + | ||
| 216 | + [ | ||
| 217 | + ['a', 0, 0, NaN], | ||
| 218 | + ['a', 0, 0, null] | ||
| 219 | + ].forEach((args) => { | ||
| 220 | + common.expectsError( | ||
| 221 | + () => buf1.fill(...args), | ||
| 222 | + { | ||
| 223 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 224 | + message: 'The "encoding" argument must be of type ' + | ||
| 225 | + `string. Received type ${args[3] === null ? 'null' : typeof args[3]}` | ||
| 226 | + } | ||
| 227 | + ); | ||
| 228 | + }); | ||
| 229 | + | ||
| 230 | + common.expectsError( | ||
| 227 | 231 | () => buf1.fill('a', 0, 0, 'foo'), | |
| 228 | - common.expectsError({ | ||
| 232 | + { | ||
| 229 | 233 | code: 'ERR_UNKNOWN_ENCODING', | |
| 230 | 234 | type: TypeError, | |
| 231 | 235 | message: 'Unknown encoding: foo' | |
| 232 | - })); | ||
| 233 | - | ||
| 236 | + } | ||
| 237 | + ); | ||
| 234 | 238 | ||
| 235 | 239 | function genBuffer(size, args) { | |
| 236 | 240 | const b = Buffer.allocUnsafe(size); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,18 +36,19 @@ deepStrictEqual( | |||
| 36 | 36 | ); | |
| 37 | 37 | ||
| 38 | 38 | [ | |
| 39 | - {}, | ||
| 40 | - new Boolean(true), | ||
| 41 | - { valueOf() { return null; } }, | ||
| 42 | - { valueOf() { return undefined; } }, | ||
| 43 | - { valueOf: null }, | ||
| 44 | - Object.create(null) | ||
| 45 | - ].forEach((input) => { | ||
| 39 | + [{}, 'object'], | ||
| 40 | + [new Boolean(true), 'boolean'], | ||
| 41 | + [{ valueOf() { return null; } }, 'object'], | ||
| 42 | + [{ valueOf() { return undefined; } }, 'object'], | ||
| 43 | + [{ valueOf: null }, 'object'], | ||
| 44 | + [Object.create(null), 'object'] | ||
| 45 | + ].forEach(([input, actualType]) => { | ||
| 46 | 46 | const err = common.expectsError({ | |
| 47 | 47 | code: 'ERR_INVALID_ARG_TYPE', | |
| 48 | 48 | type: TypeError, | |
| 49 | 49 | message: 'The first argument must be one of type string, buffer, ' + | |
| 50 | - 'arrayBuffer, array, or array-like object' | ||
| 50 | + 'arrayBuffer, array, or array-like object. Received ' + | ||
| 51 | + `type ${actualType}` | ||
| 51 | 52 | }); | |
| 52 | 53 | throws(() => Buffer.from(input), err); | |
| 53 | 54 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,7 +148,7 @@ assert(twoByteString.includes( | |||
| 148 | 148 | assert(!twoByteString.includes('\u03a3', -2, 'ucs2')); | |
| 149 | 149 | ||
| 150 | 150 | const mixedByteStringUcs2 = | |
| 151 | - Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2'); | ||
| 151 | + Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2'); | ||
| 152 | 152 | assert(mixedByteStringUcs2.includes('bc', 0, 'ucs2')); | |
| 153 | 153 | assert(mixedByteStringUcs2.includes('\u03a3', 0, 'ucs2')); | |
| 154 | 154 | assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2')); | |
@@ -261,7 +261,7 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { | |||
| 261 | 261 | const length = lengths[lengthIndex]; | |
| 262 | 262 | ||
| 263 | 263 | const patternBufferUcs2 = | |
| 264 | - allCharsBufferUcs2.slice(index, index + length); | ||
| 264 | + allCharsBufferUcs2.slice(index, index + length); | ||
| 265 | 265 | assert.ok( | |
| 266 | 266 | allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2')); | |
| 267 | 267 | ||
@@ -271,21 +271,21 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { | |||
| 271 | 271 | } | |
| 272 | 272 | } | |
| 273 | 273 | ||
| 274 | - const expectedError = common.expectsError({ | ||
| 275 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 276 | - type: TypeError, | ||
| 277 | - message: 'The "val" argument must be one of type ' + | ||
| 278 | - 'string, buffer, or uint8Array' | ||
| 279 | - }, 3); | ||
| 280 | - assert.throws(() => { | ||
| 281 | - b.includes(() => {}); | ||
| 282 | - }, expectedError); | ||
| 283 | - assert.throws(() => { | ||
| 284 | - b.includes({}); | ||
| 285 | - }, expectedError); | ||
| 286 | - assert.throws(() => { | ||
| 287 | - b.includes([]); | ||
| 288 | - }, expectedError); | ||
| 274 | + [ | ||
| 275 | + () => { }, | ||
| 276 | + {}, | ||
| 277 | + [] | ||
| 278 | + ].forEach((val) => { | ||
| 279 | + common.expectsError( | ||
| 280 | + () => b.includes(val), | ||
| 281 | + { | ||
| 282 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 283 | + type: TypeError, | ||
| 284 | + message: 'The "value" argument must be one of type string, ' + | ||
| 285 | + `buffer, or uint8Array. Received type ${typeof val}` | ||
| 286 | + } | ||
| 287 | + ); | ||
| 288 | + }); | ||
| 289 | 289 | ||
| 290 | 290 | // test truncation of Number arguments to uint8 | |
| 291 | 291 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -344,24 +344,21 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1); | |||
| 344 | 344 | } | |
| 345 | 345 | } | |
| 346 | 346 | ||
| 347 | - const argumentExpected = common.expectsError({ | ||
| 348 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 349 | - type: TypeError, | ||
| 350 | - message: 'The "val" argument must be one of type ' + | ||
| 351 | - 'string, buffer, or uint8Array' | ||
| 352 | - }, 3); | ||
| 353 | - | ||
| 354 | - assert.throws(() => { | ||
| 355 | - b.indexOf(() => { }); | ||
| 356 | - }, argumentExpected); | ||
| 357 | - | ||
| 358 | - assert.throws(() => { | ||
| 359 | - b.indexOf({}); | ||
| 360 | - }, argumentExpected); | ||
| 361 | - | ||
| 362 | - assert.throws(() => { | ||
| 363 | - b.indexOf([]); | ||
| 364 | - }, argumentExpected); | ||
| 347 | + [ | ||
| 348 | + () => {}, | ||
| 349 | + {}, | ||
| 350 | + [] | ||
| 351 | + ].forEach((val) => { | ||
| 352 | + common.expectsError( | ||
| 353 | + () => b.indexOf(val), | ||
| 354 | + { | ||
| 355 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 356 | + type: TypeError, | ||
| 357 | + message: 'The "value" argument must be one of type string, ' + | ||
| 358 | + `buffer, or uint8Array. Received type ${typeof val}` | ||
| 359 | + } | ||
| 360 | + ); | ||
| 361 | + }); | ||
| 365 | 362 | ||
| 366 | 363 | // Test weird offset arguments. | |
| 367 | 364 | // The following offsets coerce to NaN or 0, searching the whole Buffer | |
| Back | FazBrowse Home | New Git URL |
0 commit comments