Skip to content

Commit 39f65e6

Browse files
dcposchsilverwind
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 d0112fc commit 39f65e6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/buffer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,10 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
598598
} else if (byteOffset < -0x80000000) {
599599
byteOffset = -0x80000000;
600600
}
601-
byteOffset = +byteOffset; // Coerce to Number.
602-
if (isNaN(byteOffset)) {
603-
// If the offset is undefined, null, NaN, "foo", etc, search whole buffer.
601+
// Coerce to Number. Values like null and [] become 0.
602+
byteOffset = +byteOffset;
603+
// If the offset is undefined, "foo", {}, coerces to NaN, search whole buffer.
604+
if (Number.isNaN(byteOffset)) {
604605
byteOffset = dir ? 0 : (buffer.length - 1);
605606
}
606607
dir = !!dir; // Cast to bool.

0 commit comments

Comments
 (0)