diff --git a/lib/util.js b/lib/util.js index 02e205c8e16c..3ee7f133bfe9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -419,10 +419,12 @@ function callbackify(original) { const descriptors = ObjectGetOwnPropertyDescriptors(original); // It is possible to manipulate a functions `length` or `name` property. This // guards against the manipulation. - if (typeof descriptors.length.value === 'number') { + if (descriptors.length !== undefined && + typeof descriptors.length.value === 'number') { descriptors.length.value++; } - if (typeof descriptors.name.value === 'string') { + if (descriptors.name !== undefined && + typeof descriptors.name.value === 'string') { descriptors.name.value += 'Callbackified'; } const propertiesValues = ObjectValues(descriptors); diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index 3d366a6ccf6c..b3bf61a20e3e 100644 --- a/test/parallel/test-util-callbackify.js +++ b/test/parallel/test-util-callbackify.js @@ -299,3 +299,26 @@ const values = [ assert.match(stack[1], /at process\.processTicksAndRejections/); })); } + +{ + // Test that deleting the `length` or `name` property of the original + // function does not throw (https://github.com/nodejs/node/issues/67745). + async function asyncFn() { + return 42; + } + delete asyncFn.length; + delete asyncFn.name; + const cbAsyncFn = callbackify(asyncFn); + cbAsyncFn(common.mustSucceed((ret) => { + assert.strictEqual(ret, 42); + })); + + function promiseFn() { + return Promise.resolve(42); + } + delete promiseFn.length; + const cbPromiseFn = callbackify(promiseFn); + cbPromiseFn(common.mustSucceed((ret) => { + assert.strictEqual(ret, 42); + })); +}