Skip to content

Commit

Permalink
buffer: fix comments in bidirectionalIndexOf
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dcposch authored and italoacasas committed Jan 30, 2017
1 parent dd60859 commit 6549bc2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,10 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
} else if (byteOffset < -0x80000000) {
byteOffset = -0x80000000;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
// If the offset is undefined, null, NaN, "foo", etc, search whole buffer.
// Coerce to Number. Values like null and [] become 0.
byteOffset = +byteOffset;
// If the offset is undefined, "foo", {}, coerces to NaN, search whole buffer.
if (Number.isNaN(byteOffset)) {
byteOffset = dir ? 0 : (buffer.length - 1);
}
dir = !!dir; // Cast to bool.
Expand Down

0 comments on commit 6549bc2

Please sign in to comment.