Skip to content

Commit

Permalink
util: don't set the prototype of callbackified functions
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
BridgeAR authored and BethGriggs committed Apr 4, 2019
1 parent c5602d7 commit 7a1f344
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ function callbackify(original) {
(rej) => process.nextTick(callbackifyOnRejected, rej, cb));
}

Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
const descriptors = Object.getOwnPropertyDescriptors(original);
// It is possible to manipulate a functions `length` or `name` property. This
// guards against the manipulation.
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-util-callbackify.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ const values = [

const cbAsyncFn = callbackify(asyncFn);
assert.strictEqual(cbAsyncFn.length, 2);
assert.notStrictEqual(
Object.getPrototypeOf(cbAsyncFn),
Object.getPrototypeOf(asyncFn)
);
assert.strictEqual(Object.getPrototypeOf(cbAsyncFn), Function.prototype);
cbAsyncFn(value, common.mustCall((err, ret) => {
assert.ifError(err);
assert.strictEqual(ret, value);
Expand Down

0 comments on commit 7a1f344

Please sign in to comment.