Browse Source

buffer: fix comments in bidirectionalIndexOf

PR-URL: https://github.com/nodejs/node/pull/10162
Fixes: https://github.com/nodejs/node/issues/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>
v6.x
dcposch@dcpos.ch 8 years ago
committed by Myles Borins
parent
commit
2b52859535
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 7
      lib/buffer.js

7
lib/buffer.js

@ -580,9 +580,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.

Loading…
Cancel
Save