Skip to content

Commit

Permalink
buffer: remove mustMatch from Buffer.bytelength()
Browse files Browse the repository at this point in the history
Buffer.bytelength() has an undocumented third parameterm `mustMatch`.
Remove it.

Closes: nodejs#38536
  • Loading branch information
Trott committed Mar 26, 2022
1 parent bc395d4 commit 9259c7e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,16 +738,15 @@ function byteLength(string, encoding) {
}

const len = string.length;
const mustMatch = (arguments.length > 2 && arguments[2] === true);
if (!mustMatch && len === 0)
if (len === 0)
return 0;

if (!encoding)
return (mustMatch ? -1 : byteLengthUtf8(string));
return byteLengthUtf8(string);

const ops = getEncodingOps(encoding);
if (ops === undefined)
return (mustMatch ? -1 : byteLengthUtf8(string));
return byteLengthUtf8(string);
return ops.byteLength(string);
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-bytelength.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const vm = require('vm');
);
});

assert.strictEqual(Buffer.byteLength('', undefined, true), -1);
assert.strictEqual(Buffer.byteLength(''), 0);

assert(ArrayBuffer.isView(new Buffer(10)));
assert(ArrayBuffer.isView(new SlowBuffer(10)));
Expand Down

0 comments on commit 9259c7e

Please sign in to comment.