Skip to content

Commit 6549bc2

Browse files
dcposchitaloacasas
authored andcommitted
buffer: fix comments in bidirectionalIndexOf
PR-URL: #10162 Fixes: #9801 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent dd60859 commit 6549bc2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/buffer.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,10 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
588588
} else if (byteOffset < -0x80000000) {
589589
byteOffset = -0x80000000;
590590
}
591-
byteOffset = +byteOffset; // Coerce to Number.
592-
if (isNaN(byteOffset)) {
593-
// If the offset is undefined, null, NaN, "foo", etc, search whole buffer.
591+
// Coerce to Number. Values like null and [] become 0.
592+
byteOffset = +byteOffset;
593+
// If the offset is undefined, "foo", {}, coerces to NaN, search whole buffer.
594+
if (Number.isNaN(byteOffset)) {
594595
byteOffset = dir ? 0 : (buffer.length - 1);
595596
}
596597
dir = !!dir; // Cast to bool.

0 commit comments

Comments
 (0)