From b5ea925c8e30aa85f1821f3bd9833b52608bf91e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 24 Mar 2019 22:20:55 +0100 Subject: [PATCH] util: don't set the prototype of callbackified functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/26893 Fixes: https://github.com/nodejs/node/issues/26890 Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel Reviewed-By: Michaƫl Zasso --- lib/util.js | 1 - test/parallel/test-util-callbackify.js | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 4db05e478c4e86..f58f0e7a3e7605 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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. diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index 5c5aa12f1d39e2..879177907451a8 100644 --- a/test/parallel/test-util-callbackify.js +++ b/test/parallel/test-util-callbackify.js @@ -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);