aboutsummaryrefslogtreecommitdiff
path: root/lib/internal/util.js
diff options
context:
space:
mode:
authorBryan English <bryan@bryanenglish.com>2016-08-14 15:27:40 -0700
committerJames M Snell <jasnell@gmail.com>2016-08-17 18:27:22 -0700
commit249bb8da2fc8efd1394d7977a571d9d7f28cf296 (patch)
tree5a6b560da55f3150401bcb1dfe9cd4c9ee29c8b1 /lib/internal/util.js
parent3177b99737a4cfd46277f9408f7cbd2033901c7f (diff)
downloadandroid-node-v8-249bb8da2fc8efd1394d7977a571d9d7f28cf296.tar.gz
android-node-v8-249bb8da2fc8efd1394d7977a571d9d7f28cf296.tar.bz2
android-node-v8-249bb8da2fc8efd1394d7977a571d9d7f28cf296.zip
util: fix deprecated class prototype
Ensure the wrapped class prototype is exactly the unwrapped class prototype, rather than an object whose prototype is the unwrapped class prototype. This ensures that instances of the unwrapped class are instances of the wrapped class. This is useful when both a wrapped class and a factory for the unwrapped class are both exposed. Ref: https://github.com/nodejs/node/pull/8103 PR-URL: https://github.com/nodejs/node/pull/8105 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/util.js')
-rw-r--r--lib/internal/util.js5
1 files changed, 4 insertions, 1 deletions
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;