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 <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>
1 parent f0328f6 commit 66187fa

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎lib/_stream_writable.js‎

Lines changed: 2 additions & 0 deletions
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
returntrue;
147+
if(this!==Writable)
148+
returnfalse;
147149

148150
returnobject&&object._writableStateinstanceofWritableState;
149151
}

‎test/parallel/test-stream-inheritance.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ Object.setPrototypeOf(CustomWritable.prototype, Writable.prototype);
4949
newCustomWritable();
5050

5151
assert.throws(CustomWritable,/AssertionError:undefineddoesnotinheritfromCustomWritable/);
52+
53+
classOtherCustomWritableextendsWritable{}
54+
55+
assert(!(newOtherCustomWritable()instanceofCustomWritable));
56+
assert(!(newCustomWritable()instanceofOtherCustomWritable));

0 commit comments

Comments
 (0)