-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Closed
Labels
streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.
Description
- Version: Node v8.4.0
- Platform: macOS
- Subsystem: Stream
The implementation for Writable
's @@hasInstance
method is faulty. As described in this Stack Overflow post:
In this snippet, the statement f instanceof PipeWritable returns true (Node v8.4.0):
const stream = require('stream'); const fs = require('fs'); class PipeWritable extends stream.Writable { constructor () { super(); } } const s = new PipeWritable(); const f = fs.createWriteStream('/tmp/test'); console.log(f instanceof PipeWritable); // true ... ???
Because of the hasInstance
implementation, this line:
Line 183 in 467385a
return object && object._writableState instanceof WritableState; |
Allows for Writables to be subclasses of Writable. This is a side-effect of Duplex parasitically inheriting from Writable, making new Duplex() instanceof Writeable
true but also making Writables instances of Writable subclasses. Maybe add another check to make sure only Duplexes can be instances of Writables, but not Writables instances of Writable subclasses?
[refack: replaced code copy with code reference]
addaleax and benjamingr
Metadata
Metadata
Assignees
Labels
streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.