diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 6cf7390b841a33..8251e8e219a519 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -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; } diff --git a/test/parallel/test-stream-inheritance.js b/test/parallel/test-stream-inheritance.js index 2c6daed0385d4a..aefb39af512646 100644 --- a/test/parallel/test-stream-inheritance.js +++ b/test/parallel/test-stream-inheritance.js @@ -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));