diff --git a/lib/internal/util.js b/lib/internal/util.js index 073879d9e9f..055f8779b18 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 867bbbf2aee..075426fd6bf 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);