stream: fix Writable instanceof for subclasses · nodejs/node@66187fa

2 files changed

lines changed

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

}

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));