Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use validateBuffer
  • Loading branch information
Flarna committed Apr 11, 2020
commit 0a7ff5051abd81834d45e7ebf29cd2b40bf35099
5 changes: 2 additions & 3 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const {
hideStackFrames
} = require('internal/errors');
const {
validateBuffer,
validateInt32,
validateString
} = require('internal/validators');
Expand Down Expand Up @@ -899,9 +900,7 @@ Buffer.prototype.compare = function compare(target,
// - encoding - an optional encoding, relevant if val is a string
// - dir - true for indexOf, false for lastIndexOf
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
if (!isArrayBufferView(buffer)) {
throw new ERR_INVALID_ARG_TYPE('buffer', 'Buffer', buffer);
}
validateBuffer(buffer);

if (typeof byteOffset === 'string') {
encoding = byteOffset;
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-buffer-indexof.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ assert.strictEqual(reallyLong.lastIndexOf(pattern), 0);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "buffer" argument must be an instance of Buffer. ' +
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. ' +
'Received an instance of lastIndexOf'
});
}