Skip to content

Commit b5ea925

Browse files
committed
util: don't set the prototype of callbackified functions
Using `util.callbackify()` should not set the prototype for the returned function to the one from the input function. It could cause confusion while debugging otherwise. PR-URL: #26893 Fixes: #26890 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 46bf0d0 commit b5ea925

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/util.js

-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ function callbackify(original) {
194194
(rej) => process.nextTick(callbackifyOnRejected, rej, cb));
195195
}
196196

197-
Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
198197
const descriptors = Object.getOwnPropertyDescriptors(original);
199198
// It is possible to manipulate a functions `length` or `name` property. This
200199
// guards against the manipulation.

test/parallel/test-util-callbackify.js

+5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ const values = [
157157

158158
const cbAsyncFn = callbackify(asyncFn);
159159
assert.strictEqual(cbAsyncFn.length, 2);
160+
assert.notStrictEqual(
161+
Object.getPrototypeOf(cbAsyncFn),
162+
Object.getPrototypeOf(asyncFn)
163+
);
164+
assert.strictEqual(Object.getPrototypeOf(cbAsyncFn), Function.prototype);
160165
cbAsyncFn(value, common.mustCall((err, ret) => {
161166
assert.ifError(err);
162167
assert.strictEqual(ret, value);

0 commit comments

Comments
 (0)