diff --git a/lib/internal/util.js b/lib/internal/util.js index 073879d9e9..055f8779b1 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -69,7 +69,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 867bbbf2ae..075426fd6b 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);