buffer: remove obsolete NaN check
These two NaN entries are not necessary and we can safely remove them. PR-URL: https://github.com/nodejs/node/pull/18744 Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
ef0e92eb82
commit
43b8ce4ce7
@ -378,10 +378,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
|
|||||||
} else {
|
} else {
|
||||||
// convert length to non-negative integer
|
// convert length to non-negative integer
|
||||||
length = +length;
|
length = +length;
|
||||||
// Check for NaN
|
if (length > 0) {
|
||||||
if (length !== length) {
|
|
||||||
length = 0;
|
|
||||||
} else if (length > 0) {
|
|
||||||
if (length > maxLength)
|
if (length > maxLength)
|
||||||
throw new errors.RangeError('ERR_BUFFER_OUT_OF_BOUNDS', 'length');
|
throw new errors.RangeError('ERR_BUFFER_OUT_OF_BOUNDS', 'length');
|
||||||
} else {
|
} else {
|
||||||
@ -404,7 +401,7 @@ function fromObject(obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
|
if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
|
||||||
if (typeof obj.length !== 'number' || obj.length !== obj.length) {
|
if (typeof obj.length !== 'number') {
|
||||||
return new FastBuffer();
|
return new FastBuffer();
|
||||||
}
|
}
|
||||||
return fromArrayLike(obj);
|
return fromArrayLike(obj);
|
||||||
|
@ -148,3 +148,6 @@ b.writeDoubleBE(11.11, 0, true);
|
|||||||
message: '"length" is outside of buffer bounds'
|
message: '"length" is outside of buffer bounds'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test an array like entry with the length set to NaN.
|
||||||
|
assert.deepStrictEqual(Buffer.from({ length: NaN }), Buffer.alloc(0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user