summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-06-22 02:38:41 +0200
committerMatteo Collina <hello@matteocollina.com>2017-06-29 18:03:54 +0200
commit1b54371c50cd6a67f22f6ec0db53bac3917387e5 (patch)
tree9175888abe32e1c3aacf95b39f0de4876f2b21c7 /lib
parenta1ecdcfb154ec79db4da595ca85ce75f9f759c6a (diff)
downloadandroid-node-v8-1b54371c50cd6a67f22f6ec0db53bac3917387e5.tar.gz
android-node-v8-1b54371c50cd6a67f22f6ec0db53bac3917387e5.tar.bz2
android-node-v8-1b54371c50cd6a67f22f6ec0db53bac3917387e5.zip
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: https://github.com/nodejs/node/pull/13863 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/_stream_transform.js2
-rw-r--r--lib/_stream_wrap.js7
-rw-r--r--lib/internal/errors.js2
3 files changed, 4 insertions, 7 deletions
diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js
index 34a83f7632..ba80f5c09c 100644
--- a/lib/_stream_transform.js
+++ b/lib/_stream_transform.js
@@ -76,7 +76,7 @@ function afterTransform(er, data) {
var cb = ts.writecb;
- if (!cb) {
+ if (cb === null) {
return this.emit('error', new errors.Error('ERR_MULTIPLE_CALLBACK'));
}
diff --git a/lib/_stream_wrap.js b/lib/_stream_wrap.js
index 4b92fb6453..00e6de2fd2 100644
--- a/lib/_stream_wrap.js
+++ b/lib/_stream_wrap.js
@@ -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;
}
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 109892f831..cf5bdcf4d2 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -171,7 +171,7 @@ E('ERR_SOCKET_BAD_PORT', 'Port should be > 0 and < 65536');
E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running');
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
-E('ERR_STREAM_HAS_STRINGDECODER', 'Stream has StringDecoder');
+E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode');
E('ERR_TRANSFORM_ALREADY_TRANSFORMING',
'Calling transform done when still transforming');
E('ERR_TRANSFORM_WITH_LENGTH_0',