diff --git a/lib/internal/util.js b/lib/internal/util.js index d231b41a2f1dc9..468a426ac5040c 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -66,7 +66,10 @@ exports._deprecate = function(fn, msg) { // The wrapper will keep the same prototype as fn to maintain prototype chain Object.setPrototypeOf(deprecated, fn); if (fn.prototype) { - Object.setPrototypeOf(deprecated.prototype, fn.prototype); + // Setting this (rather than using Object.setPrototype, as above) ensures + // that calling the unwrapped constructor gives an instanceof the wrapped + // constructor. + deprecated.prototype = fn.prototype; } return deprecated; diff --git a/test/fixtures/deprecated-userland-class.js b/test/fixtures/deprecated-userland-class.js index 867bbbf2aeea4f..075426fd6bf16c 100644 --- a/test/fixtures/deprecated-userland-class.js +++ b/test/fixtures/deprecated-userland-class.js @@ -7,6 +7,9 @@ class deprecatedClass { const deprecated = util.deprecate(deprecatedClass, 'deprecatedClass is deprecated.'); const instance = new deprecated(); +const deprecatedInstance = new deprecatedClass(); assert(instance instanceof deprecated); assert(instance instanceof deprecatedClass); +assert(deprecatedInstance instanceof deprecated); +assert(deprecatedInstance instanceof deprecatedClass);