summaryrefslogtreecommitdiff
path: root/lib/buffer.js
diff options
context:
space:
mode:
authorWeijia Wang <381152119@qq.com>2017-08-22 19:57:26 +0800
committerJames M Snell <jasnell@gmail.com>2017-08-24 14:49:47 -0700
commit9e0f771224759484bd95358f02de650916287488 (patch)
treeaba239ccc9c9f6988843d04483bffd7ddb63a527 /lib/buffer.js
parent52fe7626068c7110696104139a063942bdb3fd83 (diff)
downloadandroid-node-v8-9e0f771224759484bd95358f02de650916287488.tar.gz
android-node-v8-9e0f771224759484bd95358f02de650916287488.tar.bz2
android-node-v8-9e0f771224759484bd95358f02de650916287488.zip
buffer: improve error messages
Some errors in buffer module losed some arguments or received wrong arguments when they were created. This PR added these losing arguments and fixed the wrong arguments. PR-URL: https://github.com/nodejs/node/pull/14975 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/buffer.js')
-rw-r--r--lib/buffer.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index 5a0ca382fb..4cdbaa73d6 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -224,7 +224,8 @@ Buffer.from = function from(value, encodingOrOffset, length) {
throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE',
'first argument',
- ['string', 'buffer', 'arrayBuffer', 'array', 'array-like object']
+ ['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'],
+ value
);
};
@@ -507,7 +508,8 @@ function byteLength(string, encoding) {
}
throw new errors.TypeError(
- 'ERR_INVALID_ARG_TYPE', 'string', ['string', 'buffer', 'arrayBuffer']
+ 'ERR_INVALID_ARG_TYPE', 'string',
+ ['string', 'buffer', 'arrayBuffer'], string
);
}
@@ -668,7 +670,8 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
Buffer.prototype.equals = function equals(b) {
if (!isUint8Array(b)) {
throw new errors.TypeError(
- 'ERR_INVALID_ARG_TYPE', 'otherBuffer', ['buffer', 'uint8Array']
+ 'ERR_INVALID_ARG_TYPE', 'otherBuffer',
+ ['buffer', 'uint8Array'], b
);
}
if (this === b)
@@ -696,7 +699,8 @@ Buffer.prototype.compare = function compare(target,
thisEnd) {
if (!isUint8Array(target)) {
throw new errors.TypeError(
- 'ERR_INVALID_ARG_TYPE', 'target', ['buffer', 'uint8Array']
+ 'ERR_INVALID_ARG_TYPE', 'target',
+ ['buffer', 'uint8Array'], target
);
}
if (arguments.length === 1)
@@ -778,7 +782,8 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
}
throw new errors.TypeError(
- 'ERR_INVALID_ARG_TYPE', 'val', ['string', 'buffer', 'uint8Array']
+ 'ERR_INVALID_ARG_TYPE', 'value',
+ ['string', 'buffer', 'uint8Array'], val
);
}
@@ -847,7 +852,8 @@ Buffer.prototype.fill = function fill(val, start, end, encoding) {
}
if (encoding !== undefined && typeof encoding !== 'string') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'encoding', 'string');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'encoding',
+ 'string', encoding);
}
var normalizedEncoding = normalizeEncoding(encoding);
if (normalizedEncoding === undefined) {