buffer: buffer.transcode to use internal/errors
`buffer.transcode` is still using raw TypeError. This change is to convert it to use internal/errors. Ref: https://github.com/nodejs/node/issues/11273 PR-URL: https://github.com/nodejs/node/pull/16352 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
parent
f1d6b04ac9
commit
e79a61cf80
@ -1562,7 +1562,8 @@ if (process.binding('config').hasIntl) {
|
|||||||
// Buffer instance.
|
// Buffer instance.
|
||||||
transcode = function transcode(source, fromEncoding, toEncoding) {
|
transcode = function transcode(source, fromEncoding, toEncoding) {
|
||||||
if (!isUint8Array(source))
|
if (!isUint8Array(source))
|
||||||
throw new TypeError('"source" argument must be a Buffer or Uint8Array');
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'source',
|
||||||
|
['Buffer', 'Uint8Array'], source);
|
||||||
if (source.length === 0) return Buffer.alloc(0);
|
if (source.length === 0) return Buffer.alloc(0);
|
||||||
|
|
||||||
fromEncoding = normalizeEncoding(fromEncoding) || fromEncoding;
|
fromEncoding = normalizeEncoding(fromEncoding) || fromEncoding;
|
||||||
|
@ -41,9 +41,14 @@ for (const test in tests) {
|
|||||||
utf8_to_ucs2.toString('ucs2'));
|
utf8_to_ucs2.toString('ucs2'));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.throws(
|
common.expectsError(
|
||||||
() => buffer.transcode(null, 'utf8', 'ascii'),
|
() => buffer.transcode(null, 'utf8', 'ascii'),
|
||||||
/^TypeError: "source" argument must be a Buffer or Uint8Array$/
|
{
|
||||||
|
type: TypeError,
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
message: 'The "source" argument must be one of type Buffer ' +
|
||||||
|
'or Uint8Array. Received type null'
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user