Permalink
Browse files

buffer: fix comments in bidirectionalIndexOf

PR-URL: #10162
Fixes: #9801
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information...
dcposch authored and silverwind committed Dec 7, 2016
1 parent d0112fc commit 39f65e66562835dfb09b610cd5322794d10bbe12
Showing with 4 additions and 3 deletions.
  1. +4 −3 lib/buffer.js
View
@@ -598,9 +598,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.

0 comments on commit 39f65e6

Please sign in to comment.