Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Comment on lines -422 to +423

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, 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);
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-util-callbackify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
}
Loading