Skip to content

Commit c861462

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 f1bc168 commit c861462

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
@@ -179,6 +179,8 @@ if (typeof Symbol === 'function' && Symbol.hasInstance) {
179179
value: function(object) {
180180
if (realHasInstance.call(this, object))
181181
return true;
182+
if (this !== Writable)
183+
return false;
182184

183185
return object && object._writableState instanceof WritableState;
184186
}

test/parallel/test-stream-inheritance.js

+5
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ common.expectsError(
5656
message: 'undefined does not inherit from CustomWritable'
5757
}
5858
);
59+
60+
class OtherCustomWritable extends Writable {}
61+
62+
assert(!(new OtherCustomWritable() instanceof CustomWritable));
63+
assert(!(new CustomWritable() instanceof OtherCustomWritable));

0 commit comments

Comments
 (0)