Skip to content

Commit 66187fa

Browse files
addaleaxMylesBorins
authored andcommitted
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 <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f0328f6 commit 66187fa

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/_stream_writable.js

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ if (typeof Symbol === 'function' && Symbol.hasInstance) {
144144
value: function(object) {
145145
if (realHasInstance.call(this, object))
146146
return true;
147+
if (this !== Writable)
148+
return false;
147149

148150
return object && object._writableState instanceof WritableState;
149151
}

test/parallel/test-stream-inheritance.js

+5
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ Object.setPrototypeOf(CustomWritable.prototype, Writable.prototype);
4949
new CustomWritable();
5050

5151
assert.throws(CustomWritable, /AssertionError: undefined does not inherit from CustomWritable/);
52+
53+
class OtherCustomWritable extends Writable {}
54+
55+
assert(!(new OtherCustomWritable() instanceof CustomWritable));
56+
assert(!(new CustomWritable() instanceof OtherCustomWritable));

0 commit comments

Comments
 (0)