Skip to content

Commit 2b52859

Browse files
dcposchMylesBorins
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 21a94ab commit 2b52859

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
@@ -580,9 +580,10 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
580580
} else if (byteOffset < -0x80000000) {
581581
byteOffset = -0x80000000;
582582
}
583-
byteOffset = +byteOffset; // Coerce to Number.
584-
if (isNaN(byteOffset)) {
585-
// If the offset is undefined, null, NaN, "foo", etc, search whole buffer.
583+
// Coerce to Number. Values like null and [] become 0.
584+
byteOffset = +byteOffset;
585+
// If the offset is undefined, "foo", {}, coerces to NaN, search whole buffer.
586+
if (Number.isNaN(byteOffset)) {
586587
byteOffset = dir ? 0 : (buffer.length - 1);
587588
}
588589
dir = !!dir; // Cast to bool.

0 commit comments

Comments
 (0)