-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
stream: use more explicit statements #13863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,6 @@ const assert = require('assert'); | |
const util = require('util'); | ||
const Socket = require('net').Socket; | ||
const JSStream = process.binding('js_stream').JSStream; | ||
// TODO(bmeurer): Change this back to const once hole checks are | ||
// properly optimized away early in Ignition+TurboFan. | ||
var Buffer = require('buffer').Buffer; | ||
const uv = process.binding('uv'); | ||
const debug = util.debuglog('stream_wrap'); | ||
const errors = require('internal/errors'); | ||
|
@@ -47,12 +44,12 @@ function StreamWrap(stream) { | |
self.emit('error', err); | ||
}); | ||
this.stream.on('data', function ondata(chunk) { | ||
if (!(chunk instanceof Buffer)) { | ||
if (typeof chunk === 'string' || this._readableState.objectMode === true) { | ||
|
||
// Make sure that no further `data` events will happen | ||
this.pause(); | ||
this.removeListener('data', ondata); | ||
|
||
self.emit('error', new errors.Error('ERR_STREAM_HAS_STRINGDECODER')); | ||
self.emit('error', new errors.Error('ERR_STREAM_WRAP')); | ||
|
||
return; | ||
} | ||
|
||
|
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')); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This potentially could be a breaking change given that it would miss other falsy values potentially passed for
cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked. We are setting this internally, it's not user-driven.