summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWeijia Wang <381152119@qq.com>2017-10-28 17:39:55 +0800
committerJames M Snell <jasnell@gmail.com>2017-11-12 11:04:06 -0800
commite22b8d0c46728ebdaf64176191ffa2bdd0f56be9 (patch)
tree7b5c9624490d67fc0c8bff2413e7a27e9f93bbbc /lib
parente0113ab5e0e2b329668fa7d744fac3bfe8b95935 (diff)
downloadandroid-node-v8-e22b8d0c46728ebdaf64176191ffa2bdd0f56be9.tar.gz
android-node-v8-e22b8d0c46728ebdaf64176191ffa2bdd0f56be9.tar.bz2
android-node-v8-e22b8d0c46728ebdaf64176191ffa2bdd0f56be9.zip
lib: improve the usage of TypeError[INVALID_ARG_TYPE]
The initials of expected in TypeError[ERR_INVALID_ARG_TYPE] are inconsistent. This change is to unify them. PR-URL: https://github.com/nodejs/node/pull/16401 Fixes: https://github.com/nodejs/node/issues/16383 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/_http_client.js2
-rw-r--r--lib/_http_outgoing.js4
-rw-r--r--lib/_tls_wrap.js2
-rw-r--r--lib/assert.js2
-rw-r--r--lib/buffer.js16
-rw-r--r--lib/dgram.js2
-rw-r--r--lib/dns.js2
-rw-r--r--lib/events.js8
-rw-r--r--lib/fs.js8
-rw-r--r--lib/inspector.js2
-rw-r--r--lib/internal/child_process.js4
-rw-r--r--lib/internal/encoding.js8
-rw-r--r--lib/internal/errors.js2
-rw-r--r--lib/internal/http2/core.js4
-rw-r--r--lib/internal/http2/util.js2
-rw-r--r--lib/internal/process.js6
-rw-r--r--lib/internal/url.js2
-rw-r--r--lib/internal/util.js4
-rw-r--r--lib/net.js4
-rw-r--r--lib/repl.js2
-rw-r--r--lib/url.js2
-rw-r--r--lib/util.js12
22 files changed, 50 insertions, 50 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js
index df99daa9d5..366a7b0712 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -105,7 +105,7 @@ function ClientRequest(options, cb) {
// when createConnection is provided.
} else if (typeof agent.addRequest !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'Agent option',
- ['Agent-like object', 'undefined', 'false']);
+ ['Agent-like Object', 'undefined', 'false']);
}
this.agent = agent;
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index b4cfe61d86..07cf84866f 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -650,7 +650,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
if (!fromEnd && typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
- ['string', 'buffer']);
+ ['string', 'Buffer']);
}
@@ -748,7 +748,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
if (chunk) {
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
- ['string', 'buffer']);
+ ['string', 'Buffer']);
}
if (!this._header) {
if (typeof chunk === 'string')
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
index b272d8090b..3e6f2b0642 100644
--- a/lib/_tls_wrap.js
+++ b/lib/_tls_wrap.js
@@ -846,7 +846,7 @@ function Server(options, listener) {
} else if (options == null || typeof options === 'object') {
options = options || {};
} else {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
}
diff --git a/lib/assert.js b/lib/assert.js
index 9c7260a1a8..76349c207d 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -166,7 +166,7 @@ function innerThrows(shouldThrow, block, expected, message) {
var details = '';
if (typeof block !== 'function') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function',
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'Function',
block);
}
diff --git a/lib/buffer.js b/lib/buffer.js
index f326aef751..2199d4be7f 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -199,7 +199,7 @@ 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
);
}
@@ -226,7 +226,7 @@ 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
);
};
@@ -429,7 +429,7 @@ Buffer.isBuffer = function isBuffer(b) {
Buffer.compare = function compare(a, b) {
if (!isUint8Array(a) || !isUint8Array(b)) {
throw new errors.TypeError(
- 'ERR_INVALID_ARG_TYPE', ['buf1', 'buf2'], ['buffer', 'uint8Array']
+ 'ERR_INVALID_ARG_TYPE', ['buf1', 'buf2'], ['Buffer', 'Uint8Array']
);
}
@@ -448,7 +448,7 @@ Buffer.isEncoding = function isEncoding(encoding) {
Buffer[kIsEncodingSymbol] = Buffer.isEncoding;
const kConcatErr = new errors.TypeError(
- 'ERR_INVALID_ARG_TYPE', 'list', ['array', 'buffer', 'uint8Array']
+ 'ERR_INVALID_ARG_TYPE', 'list', ['Array', 'Buffer', 'Uint8Array']
);
Buffer.concat = function concat(list, length) {
@@ -509,7 +509,7 @@ function byteLength(string, encoding) {
throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'string',
- ['string', 'buffer', 'arrayBuffer'], string
+ ['string', 'Buffer', 'ArrayBuffer'], string
);
}
@@ -671,7 +671,7 @@ Buffer.prototype.equals = function equals(b) {
if (!isUint8Array(b)) {
throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'otherBuffer',
- ['buffer', 'uint8Array'], b
+ ['Buffer', 'Uint8Array'], b
);
}
if (this === b)
@@ -700,7 +700,7 @@ Buffer.prototype.compare = function compare(target,
if (!isUint8Array(target)) {
throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'target',
- ['buffer', 'uint8Array'], target
+ ['Buffer', 'Uint8Array'], target
);
}
if (arguments.length === 1)
@@ -783,7 +783,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'value',
- ['string', 'buffer', 'uint8Array'], val
+ ['string', 'Buffer', 'Uint8Array'], val
);
}
diff --git a/lib/dgram.js b/lib/dgram.js
index cc2d11b81e..94e3a9b38e 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -63,7 +63,7 @@ function newHandle(type, lookup) {
if (lookup === undefined)
lookup = dns.lookup;
else if (typeof lookup !== 'function')
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'lookup', 'function');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'lookup', 'Function');
if (type === 'udp4') {
const handle = new UDP();
diff --git a/lib/dns.js b/lib/dns.js
index ca4a02d2ef..b8c98e7125 100644
--- a/lib/dns.js
+++ b/lib/dns.js
@@ -133,7 +133,7 @@ function lookup(hostname, options, callback) {
// Parse arguments
if (hostname && typeof hostname !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'hostname',
- ['string', 'falsey'], hostname);
+ ['string', 'falsy'], hostname);
} else if (typeof options === 'function') {
callback = options;
family = 0;
diff --git a/lib/events.js b/lib/events.js
index 6efc29108c..c99314f0df 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -243,7 +243,7 @@ function _addListener(target, type, listener, prepend) {
if (typeof listener !== 'function') {
const errors = lazyErrors();
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'function');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'Function');
}
events = target._events;
@@ -344,7 +344,7 @@ function _onceWrap(target, type, listener) {
EventEmitter.prototype.once = function once(type, listener) {
if (typeof listener !== 'function') {
const errors = lazyErrors();
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'function');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'Function');
}
this.on(type, _onceWrap(this, type, listener));
return this;
@@ -355,7 +355,7 @@ EventEmitter.prototype.prependOnceListener =
if (typeof listener !== 'function') {
const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener',
- 'function');
+ 'Function');
}
this.prependListener(type, _onceWrap(this, type, listener));
return this;
@@ -369,7 +369,7 @@ EventEmitter.prototype.removeListener =
if (typeof listener !== 'function') {
const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener',
- 'function');
+ 'Function');
}
events = this._events;
diff --git a/lib/fs.js b/lib/fs.js
index ce76ebc4d6..e6a1193bec 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -86,7 +86,7 @@ function getOptions(options, defaultOptions) {
} else if (typeof options !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options',
- ['string', 'object'],
+ ['string', 'Object'],
options);
}
@@ -1209,7 +1209,7 @@ function toUnixTimestamp(time) {
}
throw new errors.Error('ERR_INVALID_ARG_TYPE',
'time',
- ['Date', 'time in seconds'],
+ ['Date', 'Time in seconds'],
time);
}
@@ -1513,7 +1513,7 @@ fs.watchFile = function(filename, options, listener) {
if (typeof listener !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'listener',
- 'function',
+ 'Function',
listener);
}
@@ -1922,7 +1922,7 @@ fs.copyFile = function(src, dest, flags, callback) {
callback = flags;
flags = 0;
} else if (typeof callback !== 'function') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'callback', 'function');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'callback', 'Function');
}
src = getPathFromURL(src);
diff --git a/lib/inspector.js b/lib/inspector.js
index 775629c0f5..091e0e5fc9 100644
--- a/lib/inspector.js
+++ b/lib/inspector.js
@@ -56,7 +56,7 @@ class Session extends EventEmitter {
}
if (params && typeof params !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
- 'params', 'object', params);
+ 'params', 'Object', params);
}
if (callback && typeof callback !== 'function') {
throw new errors.TypeError('ERR_INVALID_CALLBACK');
diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js
index 70b13e0839..2692d8554a 100644
--- a/lib/internal/child_process.js
+++ b/lib/internal/child_process.js
@@ -273,7 +273,7 @@ ChildProcess.prototype.spawn = function(options) {
var i;
if (options === null || typeof options !== 'object') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object',
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object',
options);
}
@@ -594,7 +594,7 @@ function setupChannel(target, channel) {
options = undefined;
} else if (options !== undefined &&
(options === null || typeof options !== 'object')) {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object',
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object',
options);
}
diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js
index 09242be8dc..763ee42426 100644
--- a/lib/internal/encoding.js
+++ b/lib/internal/encoding.js
@@ -345,7 +345,7 @@ function makeTextDecoderICU() {
constructor(encoding = 'utf-8', options = {}) {
encoding = `${encoding}`;
if (typeof options !== 'object')
- throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'object');
+ throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'Object');
const enc = getEncodingFromLabel(encoding);
if (enc === undefined)
@@ -378,7 +378,7 @@ function makeTextDecoderICU() {
['ArrayBuffer', 'ArrayBufferView']);
}
if (typeof options !== 'object') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
}
var flags = 0;
@@ -417,7 +417,7 @@ function makeTextDecoderJS() {
constructor(encoding = 'utf-8', options = {}) {
encoding = `${encoding}`;
if (typeof options !== 'object')
- throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'object');
+ throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'Object');
const enc = getEncodingFromLabel(encoding);
if (enc === undefined || !hasConverter(enc))
@@ -452,7 +452,7 @@ function makeTextDecoderJS() {
['ArrayBuffer', 'ArrayBufferView']);
}
if (typeof options !== 'object') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
}
if (this[kFlags] & CONVERTER_FLAGS_FLUSH) {
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 3e43b9eed7..1eac23c42f 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -133,7 +133,7 @@ class SystemError extends makeNodeError(Error) {
class AssertionError extends Error {
constructor(options) {
if (typeof options !== 'object' || options === null) {
- throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
+ throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
}
var { actual, expected, message, operator, stackStartFunction } = options;
if (message) {
diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index 19790ad4e6..2e20c9ea88 100644
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -2484,7 +2484,7 @@ function connect(authority, options, listener) {
if (typeof authority === 'string')
authority = new URL(authority);
- assertIsObject(authority, 'authority', ['string', 'object', 'URL']);
+ assertIsObject(authority, 'authority', ['string', 'Object', 'URL']);
debug(`connecting to ${authority}`);
@@ -2539,7 +2539,7 @@ function createSecureServer(options, handler) {
if (options == null || typeof options !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options',
- 'object');
+ 'Object');
}
debug('creating http2secureserver');
return new Http2SecureServer(options, handler);
diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js
index b67b663f1a..e6da4293b5 100644
--- a/lib/internal/http2/util.js
+++ b/lib/internal/http2/util.js
@@ -465,7 +465,7 @@ class NghttpError extends Error {
}
}
-function assertIsObject(value, name, types = 'object') {
+function assertIsObject(value, name, types = 'Object') {
if (value !== undefined &&
(value === null ||
typeof value !== 'object' ||
diff --git a/lib/internal/process.js b/lib/internal/process.js
index 21a74abba7..ff5ea58dda 100644
--- a/lib/internal/process.js
+++ b/lib/internal/process.js
@@ -28,12 +28,12 @@ function setup_cpuUsage() {
if (prevValue) {
if (!previousValueIsValid(prevValue.user)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
- 'preValue.user', 'Number');
+ 'preValue.user', 'number');
}
if (!previousValueIsValid(prevValue.system)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
- 'preValue.system', 'Number');
+ 'preValue.system', 'number');
}
}
@@ -154,7 +154,7 @@ function setupKillAndExit() {
// eslint-disable-next-line eqeqeq
if (pid != (pid | 0)) {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pid', 'Number');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pid', 'number');
}
// preserve null signal
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 044d8b96a7..89087b750d 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -372,7 +372,7 @@ Object.defineProperties(URL.prototype, {
// eslint-disable-next-line func-name-matching
value: function format(options) {
if (options && typeof options !== 'object')
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
options = util._extend({
fragment: true,
unicode: false,
diff --git a/lib/internal/util.js b/lib/internal/util.js
index bcee867a8a..138c811a54 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -208,14 +208,14 @@ const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs');
function promisify(original) {
if (typeof original !== 'function')
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'function');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'Function');
if (original[kCustomPromisifiedSymbol]) {
const fn = original[kCustomPromisifiedSymbol];
if (typeof fn !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'util.promisify.custom',
- 'function',
+ 'Function',
fn);
}
Object.defineProperty(fn, kCustomPromisifiedSymbol, {
diff --git a/lib/net.js b/lib/net.js
index 78e12fac20..93b2279c7b 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -1080,7 +1080,7 @@ function lookupAndConnect(self, options) {
if (options.lookup && typeof options.lookup !== 'function')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.lookup',
- 'function',
+ 'Function',
options.lookup);
var dnsopts = {
@@ -1225,7 +1225,7 @@ function Server(options, connectionListener) {
} else {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options',
- 'object',
+ 'Object',
options);
}
diff --git a/lib/repl.js b/lib/repl.js
index 79acd217a4..5c3f0f1526 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -1111,7 +1111,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
} else if (typeof cmd.action !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'action',
- 'function',
+ 'Function',
cmd.action);
}
this.commands[keyword] = cmd;
diff --git a/lib/url.js b/lib/url.js
index 3734a0cad6..d27891d36b 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -556,7 +556,7 @@ function urlFormat(urlObject, options) {
urlObject = urlParse(urlObject);
} else if (typeof urlObject !== 'object' || urlObject === null) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObject',
- ['object', 'string'], urlObject);
+ ['Object', 'string'], urlObject);
} else if (!(urlObject instanceof Url)) {
var format = urlObject[formatSymbol];
return format ?
diff --git a/lib/util.js b/lib/util.js
index 00da489b88..6d041fdf42 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -335,7 +335,7 @@ Object.defineProperty(inspect, 'defaultOptions', {
},
set(options) {
if (options === null || typeof options !== 'object') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
}
Object.assign(inspectDefaultOptions, options);
return inspectDefaultOptions;
@@ -970,14 +970,14 @@ function log() {
function inherits(ctor, superCtor) {
if (ctor === undefined || ctor === null)
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ctor', 'function');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ctor', 'Function');
if (superCtor === undefined || superCtor === null)
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'function');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'Function');
if (superCtor.prototype === undefined) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype',
- 'function');
+ 'Function');
}
ctor.super_ = superCtor;
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
@@ -1080,7 +1080,7 @@ function callbackify(original) {
throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE',
'original',
- 'function');
+ 'Function');
}
// We DO NOT return the promise as it gives the user a false sense that
@@ -1092,7 +1092,7 @@ function callbackify(original) {
throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE',
'last argument',
- 'function');
+ 'Function');
}
const cb = (...args) => { Reflect.apply(maybeCb, this, args); };
// In true node style we process the callback on `nextTick` with all the