Permalink
Browse files

stream: fix Writable instanceof for subclasses

The current custom instanceof for `Writable` subclasses previously
returned false positives for instances of *other* subclasses of
`Writable` because it was inherited by these subclasses.

Fixes: #14943
PR-URL: #14945
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
addaleax authored and MylesBorins committed Aug 19, 2017
1 parent f0328f6 commit 66187fa0445019cee8a4684870a7ea76e93de6df
Showing with 7 additions and 0 deletions.
  1. +2 −0 lib/_stream_writable.js
  2. +5 −0 test/parallel/test-stream-inheritance.js
View
@@ -144,6 +144,8 @@ if (typeof Symbol === 'function' && Symbol.hasInstance) {
value: function(object) {
if (realHasInstance.call(this, object))
return true;
if (this !== Writable)
return false;
return object && object._writableState instanceof WritableState;
}
@@ -49,3 +49,8 @@ Object.setPrototypeOf(CustomWritable.prototype, Writable.prototype);
new CustomWritable();
assert.throws(CustomWritable, /AssertionError: undefined does not inherit from CustomWritable/);
class OtherCustomWritable extends Writable {}
assert(!(new OtherCustomWritable() instanceof CustomWritable));
assert(!(new CustomWritable() instanceof OtherCustomWritable));

0 comments on commit 66187fa

Please sign in to comment.