Skip to content

Commit 10d4f58

Browse files
BridgeARMayaLekova
authored andcommitted
buffer: remove obsolete NaN check
These two NaN entries are not necessary and we can safely remove them. PR-URL: nodejs#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 a349093 commit 10d4f58

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
@@ -378,10 +378,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
378378
} else {
379379
// convert length to non-negative integer
380380
length = +length;
381-
// Check for NaN
382-
if (length !== length) {
383-
length = 0;
384-
} else if (length > 0) {
381+
if (length > 0) {
385382
if (length > maxLength)
386383
throw new errors.RangeError('ERR_BUFFER_OUT_OF_BOUNDS', 'length');
387384
} else {
@@ -404,7 +401,7 @@ function fromObject(obj) {
404401
}
405402

406403
if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
407-
if (typeof obj.length !== 'number' || obj.length !== obj.length) {
404+
if (typeof obj.length !== 'number') {
408405
return new FastBuffer();
409406
}
410407
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)