aboutsummaryrefslogtreecommitdiff
path: root/lib/internal/util.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-06-20 23:20:10 +0200
committerRefael Ackermann <refack@gmail.com>2017-07-22 18:18:04 -0400
commit095357e26efc366b1cca389306e0780cc1fa81d9 (patch)
tree428cb86546dca71248b43a318d9afd15b508d9c4 /lib/internal/util.js
parent8979b4fc9face199099a53f32dfeb14a1203ad57 (diff)
downloadandroid-node-v8-095357e26efc366b1cca389306e0780cc1fa81d9.tar.gz
android-node-v8-095357e26efc366b1cca389306e0780cc1fa81d9.tar.bz2
android-node-v8-095357e26efc366b1cca389306e0780cc1fa81d9.zip
lib: tweak use of internal/errors
In addition refactor common.throws to common.expectsError PR-URL: https://github.com/nodejs/node/pull/13829 Refs: https://github.com/nodejs/node/issues/11273 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/internal/util.js')
-rw-r--r--lib/internal/util.js25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js
index 735f78d4ac..e7b9b958c7 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -201,15 +201,17 @@ function getConstructorOf(obj) {
const kCustomPromisifiedSymbol = Symbol('util.promisify.custom');
const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs');
-function promisify(orig) {
- if (typeof orig !== 'function')
+function promisify(original) {
+ if (typeof original !== 'function')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'function');
- if (orig[kCustomPromisifiedSymbol]) {
- const fn = orig[kCustomPromisifiedSymbol];
+ if (original[kCustomPromisifiedSymbol]) {
+ const fn = original[kCustomPromisifiedSymbol];
if (typeof fn !== 'function') {
- throw new TypeError('The [util.promisify.custom] property must be ' +
- 'a function');
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
+ 'util.promisify.custom',
+ 'function',
+ fn);
}
Object.defineProperty(fn, kCustomPromisifiedSymbol, {
value: fn, enumerable: false, writable: false, configurable: true
@@ -219,12 +221,12 @@ function promisify(orig) {
// Names to create an object from in case the callback receives multiple
// arguments, e.g. ['stdout', 'stderr'] for child_process.exec.
- const argumentNames = orig[kCustomPromisifyArgsSymbol];
+ const argumentNames = original[kCustomPromisifyArgsSymbol];
function fn(...args) {
const promise = createPromise();
try {
- orig.call(this, ...args, (err, ...values) => {
+ original.call(this, ...args, (err, ...values) => {
if (err) {
promiseReject(promise, err);
} else if (argumentNames !== undefined && values.length > 1) {
@@ -242,12 +244,15 @@ function promisify(orig) {
return promise;
}
- Object.setPrototypeOf(fn, Object.getPrototypeOf(orig));
+ Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
Object.defineProperty(fn, kCustomPromisifiedSymbol, {
value: fn, enumerable: false, writable: false, configurable: true
});
- return Object.defineProperties(fn, Object.getOwnPropertyDescriptors(orig));
+ return Object.defineProperties(
+ fn,
+ Object.getOwnPropertyDescriptors(original)
+ );
}
promisify.custom = kCustomPromisifiedSymbol;