buffer: add includes() for parity with TypedArray

Add Buffer#includes() by wrapping an indexOf and performing a strict
equals check to -1.

The includes method takes the search value, byteOffset, and encoding as
arguments.

The test is a modified version of the indexOf test.

Fixes: https://github.com/nodejs/node/issues/3552
PR-URL: https://github.com/nodejs/node/pull/3567
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Alexander Martin 2015-10-28 11:33:57 -05:00 committed by Trevor Norris
parent 23e7703c85
commit 67e181986a
3 changed files with 274 additions and 0 deletions

View file

@ -488,6 +488,11 @@ Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
};
Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
return this.indexOf(val, byteOffset, encoding) !== -1;
};
Buffer.prototype.fill = function fill(val, start, end) {
start = start >> 0;
end = (end === undefined) ? this.length : end >> 0;