diff --git a/lib/util.js b/lib/util.js index 1935955ad28c32..4db05e478c4e86 100644 --- a/lib/util.js +++ b/lib/util.js @@ -196,11 +196,14 @@ function callbackify(original) { Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)); const descriptors = Object.getOwnPropertyDescriptors(original); - // It is possible to manipulate a functions `length` property. This guards - // against the manipulation. + // It is possible to manipulate a functions `length` or `name` property. This + // guards against the manipulation. if (typeof descriptors.length.value === 'number') { descriptors.length.value++; } + if (typeof descriptors.name.value === 'string') { + descriptors.name.value += 'Callbackified'; + } Object.defineProperties(callbackified, descriptors); return callbackified; } diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index 4d7d46658a8edc..5c5aa12f1d39e2 100644 --- a/test/parallel/test-util-callbackify.js +++ b/test/parallel/test-util-callbackify.js @@ -75,6 +75,7 @@ const values = [ const cbAsyncFn = callbackify(asyncFn); assert.strictEqual(cbAsyncFn.length, 1); + assert.strictEqual(cbAsyncFn.name, 'asyncFnCallbackified'); cbAsyncFn(common.mustCall((err, ret) => { assert.strictEqual(ret, undefined); if (err instanceof Error) { @@ -94,8 +95,16 @@ const values = [ function promiseFn() { return Promise.reject(value); } + const obj = {}; + Object.defineProperty(promiseFn, 'name', { + value: obj, + writable: false, + enumerable: false, + configurable: true + }); const cbPromiseFn = callbackify(promiseFn); + assert.strictEqual(promiseFn.name, obj); cbPromiseFn(common.mustCall((err, ret) => { assert.strictEqual(ret, undefined); if (err instanceof Error) {