summaryrefslogtreecommitdiff
path: root/lib/buffer.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/buffer.js')
-rw-r--r--lib/buffer.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index 01e605f50a..f43f67bb94 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -363,8 +363,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
byteOffset = 0;
} else {
byteOffset = +byteOffset;
- // check for NaN
- if (byteOffset !== byteOffset)
+ if (Number.isNaN(byteOffset))
byteOffset = 0;
}
@@ -376,7 +375,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
if (length === undefined) {
length = maxLength;
} else {
- // convert length to non-negative integer
+ // Convert length to non-negative integer.
length = +length;
if (length > 0) {
if (length > maxLength)
@@ -760,8 +759,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
// Coerce to Number. Values like null and [] become 0.
byteOffset = +byteOffset;
// If the offset is undefined, "foo", {}, coerces to NaN, search whole buffer.
- // `x !== x`-style conditionals are a faster form of `isNaN(x)`
- if (byteOffset !== byteOffset) {
+ if (Number.isNaN(byteOffset)) {
byteOffset = dir ? 0 : buffer.length;
}
dir = !!dir; // Cast to bool.
@@ -996,15 +994,17 @@ function adjustOffset(offset, length) {
// Use Math.trunc() to convert offset to an integer value that can be larger
// than an Int32. Hence, don't use offset | 0 or similar techniques.
offset = Math.trunc(offset);
- // `x !== x`-style conditionals are a faster form of `isNaN(x)`
- if (offset === 0 || offset !== offset) {
+ if (offset === 0) {
return 0;
- } else if (offset < 0) {
+ }
+ if (offset < 0) {
offset += length;
return offset > 0 ? offset : 0;
- } else {
- return offset < length ? offset : length;
}
+ if (offset < length) {
+ return offset;
+ }
+ return Number.isNaN(offset) ? 0 : length;
}