Skip to content

Commit f3ab106

Browse files
BridgeARMylesBorins
authored andcommitted
buffer: remove obsolete NaN check
These two NaN entries are not necessary and we can safely remove them. PR-URL: #18744 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent ed55374 commit f3ab106

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/buffer.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
377377
} else {
378378
// convert length to non-negative integer
379379
length = +length;
380-
// Check for NaN
381-
if (length !== length) {
382-
length = 0;
383-
} else if (length > 0) {
380+
if (length > 0) {
384381
if (length > maxLength)
385382
throw new errors.RangeError('ERR_BUFFER_OUT_OF_BOUNDS', 'length');
386383
} else {
@@ -403,7 +400,7 @@ function fromObject(obj) {
403400
}
404401

405402
if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
406-
if (typeof obj.length !== 'number' || obj.length !== obj.length) {
403+
if (typeof obj.length !== 'number') {
407404
return new FastBuffer();
408405
}
409406
return fromArrayLike(obj);

test/parallel/test-buffer-arraybuffer.js

+3
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,6 @@ b.writeDoubleBE(11.11, 0, true);
148148
message: '"length" is outside of buffer bounds'
149149
});
150150
}
151+
152+
// Test an array like entry with the length set to NaN.
153+
assert.deepStrictEqual(Buffer.from({ length: NaN }), Buffer.alloc(0));

0 commit comments

Comments
 (0)