-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: use more explicit statements
Using objectMode with stream_wrap has not worked properly before and would end in an error. Therefore prohibit the usage of objectMode alltogether. This also improves the handling performance due to the cheaper chunk check and by using explicit statements as they produce better code from the compiler. PR-URL: #13863 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
5 changed files
with
40 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const StreamWrap = require('_stream_wrap'); | ||
const Duplex = require('stream').Duplex; | ||
|
||
const stream = new Duplex({ | ||
read: function() { | ||
}, | ||
write: function() { | ||
} | ||
}); | ||
{ | ||
const stream = new Duplex({ | ||
read() {}, | ||
write() {} | ||
}); | ||
|
||
stream.setEncoding('ascii'); | ||
stream.setEncoding('ascii'); | ||
|
||
const wrap = new StreamWrap(stream); | ||
const wrap = new StreamWrap(stream); | ||
|
||
wrap.on('error', common.mustCall(function(err) { | ||
assert(/StringDecoder/.test(err.message)); | ||
})); | ||
wrap.on('error', common.expectsError({ | ||
type: Error, | ||
code: 'ERR_STREAM_WRAP', | ||
message: 'Stream has StringDecoder set or is in objectMode' | ||
})); | ||
|
||
stream.push('ohai'); | ||
stream.push('ohai'); | ||
} | ||
|
||
{ | ||
const stream = new Duplex({ | ||
read() {}, | ||
write() {}, | ||
objectMode: true | ||
}); | ||
|
||
const wrap = new StreamWrap(stream); | ||
|
||
wrap.on('error', common.expectsError({ | ||
type: Error, | ||
code: 'ERR_STREAM_WRAP', | ||
message: 'Stream has StringDecoder set or is in objectMode' | ||
})); | ||
|
||
stream.push(new Error('foo')); | ||
} |