Skip to content

Commit b7dc912

Browse files
committed
stream: name anonymous functions
Ref: #8913
1 parent 6ca1bdf commit b7dc912

File tree

5 files changed

+58
-54
lines changed

5 files changed

+58
-54
lines changed

lib/_stream_passthrough.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ function PassThrough(options) {
1717
Transform.call(this, options);
1818
}
1919

20-
PassThrough.prototype._transform = function(chunk, encoding, cb) {
20+
PassThrough.prototype._transform = function passThrough_transform(chunk, encoding, cb) {
2121
cb(null, chunk);
2222
};

lib/_stream_readable.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function Readable(options) {
120120
// This returns true if the highWaterMark has not been hit yet,
121121
// similar to how Writable.write() returns true if you should
122122
// write() some more.
123-
Readable.prototype.push = function(chunk, encoding) {
123+
Readable.prototype.push = function readablePush(chunk, encoding) {
124124
var state = this._readableState;
125125

126126
if (!state.objectMode && typeof chunk === 'string') {
@@ -135,12 +135,12 @@ Readable.prototype.push = function(chunk, encoding) {
135135
};
136136

137137
// Unshift should *always* be something directly out of read()
138-
Readable.prototype.unshift = function(chunk) {
138+
Readable.prototype.unshift = function readableUnshift(chunk) {
139139
var state = this._readableState;
140140
return readableAddChunk(this, state, chunk, '', true);
141141
};
142142

143-
Readable.prototype.isPaused = function() {
143+
Readable.prototype.isPaused = function readableIsPaused() {
144144
return this._readableState.flowing === false;
145145
};
146146

@@ -213,7 +213,7 @@ function needMoreData(state) {
213213
}
214214

215215
// backwards compatibility.
216-
Readable.prototype.setEncoding = function(enc) {
216+
Readable.prototype.setEncoding = function readableSetEncoding(enc) {
217217
if (!StringDecoder)
218218
StringDecoder = require('string_decoder').StringDecoder;
219219
this._readableState.decoder = new StringDecoder(enc);
@@ -268,7 +268,7 @@ function howMuchToRead(n, state) {
268268
}
269269

270270
// you can override either this method, or the async _read(n) below.
271-
Readable.prototype.read = function(n) {
271+
Readable.prototype.read = function readableRead(n) {
272272
debug('read', n);
273273
n = parseInt(n, 10);
274274
var state = this._readableState;
@@ -466,11 +466,11 @@ function maybeReadMore_(stream, state) {
466466
// call cb(er, data) where data is <= n in length.
467467
// for virtual (non-string, non-buffer) streams, "length" is somewhat
468468
// arbitrary, and perhaps not very meaningful.
469-
Readable.prototype._read = function(n) {
469+
Readable.prototype._read = function readable_read(n) {
470470
this.emit('error', new Error('_read() is not implemented'));
471471
};
472472

473-
Readable.prototype.pipe = function(dest, pipeOpts) {
473+
Readable.prototype.pipe = function readablePipe(dest, pipeOpts) {
474474
var src = this;
475475
var state = this._readableState;
476476

@@ -613,7 +613,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
613613
};
614614

615615
function pipeOnDrain(src) {
616-
return function() {
616+
return function onPipeOnDrain() {
617617
var state = src._readableState;
618618
debug('pipeOnDrain', state.awaitDrain);
619619
if (state.awaitDrain)
@@ -626,7 +626,7 @@ function pipeOnDrain(src) {
626626
}
627627

628628

629-
Readable.prototype.unpipe = function(dest) {
629+
Readable.prototype.unpipe = function readableUnpipe(dest) {
630630
var state = this._readableState;
631631

632632
// if we're not piping anywhere, then do nothing.
@@ -683,7 +683,7 @@ Readable.prototype.unpipe = function(dest) {
683683

684684
// set up data events if they are asked for
685685
// Ensure readable listeners eventually get something
686-
Readable.prototype.on = function(ev, fn) {
686+
Readable.prototype.on = function readableOn(ev, fn) {
687687
const res = Stream.prototype.on.call(this, ev, fn);
688688

689689
if (ev === 'data') {
@@ -714,7 +714,7 @@ function nReadingNextTick(self) {
714714

715715
// pause() and resume() are remnants of the legacy readable stream API
716716
// If the user uses them, then switch into old mode.
717-
Readable.prototype.resume = function() {
717+
Readable.prototype.resume = function readableResume() {
718718
var state = this._readableState;
719719
if (!state.flowing) {
720720
debug('resume');
@@ -745,7 +745,7 @@ function resume_(stream, state) {
745745
stream.read(0);
746746
}
747747

748-
Readable.prototype.pause = function() {
748+
Readable.prototype.pause = function readablePause() {
749749
debug('call pause flowing=%j', this._readableState.flowing);
750750
if (false !== this._readableState.flowing) {
751751
debug('pause');
@@ -764,12 +764,12 @@ function flow(stream) {
764764
// wrap an old-style stream as the async data source.
765765
// This is *not* part of the readable stream interface.
766766
// It is an ugly unfortunate mess of history.
767-
Readable.prototype.wrap = function(stream) {
767+
Readable.prototype.wrap = function readableWrap(stream) {
768768
var state = this._readableState;
769769
var paused = false;
770770

771771
var self = this;
772-
stream.on('end', function() {
772+
stream.on('end', function onEnd() {
773773
debug('wrapped end');
774774
if (state.decoder && !state.ended) {
775775
var chunk = state.decoder.end();
@@ -780,7 +780,7 @@ Readable.prototype.wrap = function(stream) {
780780
self.push(null);
781781
});
782782

783-
stream.on('data', function(chunk) {
783+
stream.on('data', function onData(chunk) {
784784
debug('wrapped data');
785785
if (state.decoder)
786786
chunk = state.decoder.write(chunk);
@@ -802,8 +802,8 @@ Readable.prototype.wrap = function(stream) {
802802
// important when wrapping filters and duplexes.
803803
for (var i in stream) {
804804
if (this[i] === undefined && typeof stream[i] === 'function') {
805-
this[i] = function(method) {
806-
return function() {
805+
this[i] = function proxyMethods(method) {
806+
return function onProxyMethods() {
807807
return stream[method].apply(stream, arguments);
808808
};
809809
}(i);
@@ -812,13 +812,13 @@ Readable.prototype.wrap = function(stream) {
812812

813813
// proxy certain important events.
814814
const events = ['error', 'close', 'destroy', 'pause', 'resume'];
815-
events.forEach(function(ev) {
816-
stream.on(ev, self.emit.bind(self, ev));
817-
});
815+
for (var ev = 0; ev < events.length; ev++) {
816+
stream.on(events[ev], self.emit.bind(self, events[ev]));
817+
}
818818

819819
// when we try to consume some more bytes, simply unpause the
820820
// underlying stream.
821-
self._read = function(n) {
821+
self._read = function _read(n) {
822822
debug('wrapped _read', n);
823823
if (paused) {
824824
paused = false;

lib/_stream_transform.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ util.inherits(Transform, Duplex);
5050

5151

5252
function TransformState(stream) {
53-
this.afterTransform = function(er, data) {
53+
this.afterTransform = function _afterTransform(er, data) {
5454
return afterTransform(stream, er, data);
5555
};
5656

@@ -113,17 +113,17 @@ function Transform(options) {
113113
}
114114

115115
// When the writable side finishes, then flush out anything remaining.
116-
this.once('prefinish', function() {
116+
this.once('prefinish', function prefinish() {
117117
if (typeof this._flush === 'function')
118-
this._flush(function(er, data) {
118+
this._flush(function _flush(er, data) {
119119
done(stream, er, data);
120120
});
121121
else
122122
done(stream);
123123
});
124124
}
125125

126-
Transform.prototype.push = function(chunk, encoding) {
126+
Transform.prototype.push = function push(chunk, encoding) {
127127
this._transformState.needTransform = false;
128128
return Duplex.prototype.push.call(this, chunk, encoding);
129129
};
@@ -138,11 +138,11 @@ Transform.prototype.push = function(chunk, encoding) {
138138
// Call `cb(err)` when you are done with this chunk. If you pass
139139
// an error, then that'll put the hurt on the whole operation. If you
140140
// never call cb(), then you'll never get another chunk.
141-
Transform.prototype._transform = function(chunk, encoding, cb) {
141+
Transform.prototype._transform = function _transform(chunk, encoding, cb) {
142142
throw new Error('_transform() is not implemented');
143143
};
144144

145-
Transform.prototype._write = function(chunk, encoding, cb) {
145+
Transform.prototype._write = function _write(chunk, encoding, cb) {
146146
var ts = this._transformState;
147147
ts.writecb = cb;
148148
ts.writechunk = chunk;
@@ -159,7 +159,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
159159
// Doesn't matter what the args are here.
160160
// _transform does all the work.
161161
// That we got here means that the readable side wants more data.
162-
Transform.prototype._read = function(n) {
162+
Transform.prototype._read = function _read(n) {
163163
var ts = this._transformState;
164164

165165
if (ts.writechunk !== null && ts.writecb && !ts.transforming) {

lib/_stream_wrap.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ function StreamWrap(stream) {
1616
this._list = null;
1717

1818
const self = this;
19-
handle.close = function(cb) {
19+
handle.close = function handleClose(cb) {
2020
debug('close');
2121
self.doClose(cb);
2222
};
23-
handle.isAlive = function() {
23+
handle.isAlive = function handleIsAlive() {
2424
return self.isAlive();
2525
};
26-
handle.isClosing = function() {
26+
handle.isClosing = function handleIsClosing() {
2727
return self.isClosing();
2828
};
29-
handle.onreadstart = function() {
29+
handle.onreadstart = function handleOnreadstart() {
3030
return self.readStart();
3131
};
32-
handle.onreadstop = function() {
32+
handle.onreadstop = function handleOnreadstop() {
3333
return self.readStop();
3434
};
35-
handle.onshutdown = function(req) {
35+
handle.onshutdown = function handleOnshutdown(req) {
3636
return self.doShutdown(req);
3737
};
38-
handle.onwrite = function(req, bufs) {
38+
handle.onwrite = function handleOnwrite(req, bufs) {
3939
return self.doWrite(req, bufs);
4040
};
4141

@@ -57,7 +57,7 @@ function StreamWrap(stream) {
5757
if (self._handle)
5858
self._handle.readBuffer(chunk);
5959
});
60-
this.stream.once('end', function onend() {
60+
this.stream.once('end', function onEnd() {
6161
debug('end');
6262
if (self._handle)
6363
self._handle.emitEOF();
@@ -96,9 +96,9 @@ StreamWrap.prototype.doShutdown = function doShutdown(req) {
9696
const handle = this._handle;
9797
const item = this._enqueue('shutdown', req);
9898

99-
this.stream.end(function() {
99+
this.stream.end(function streamEnd() {
100100
// Ensure that write was dispatched
101-
setImmediate(function() {
101+
setImmediate(function setImmediateDoShutdown() {
102102
if (!self._dequeue(item))
103103
return;
104104

@@ -118,9 +118,11 @@ StreamWrap.prototype.doWrite = function doWrite(req, bufs) {
118118
const item = self._enqueue('write', req);
119119

120120
self.stream.cork();
121-
bufs.forEach(function(buf) {
122-
self.stream.write(buf, done);
123-
});
121+
for (var buf in bufs) {
122+
if (bufs.hasOwnProperty(buf)) {
123+
self.stream.write(buf, done);
124+
}
125+
}
124126
self.stream.uncork();
125127

126128
function done(err) {
@@ -131,7 +133,7 @@ StreamWrap.prototype.doWrite = function doWrite(req, bufs) {
131133
pending = 0;
132134

133135
// Ensure that write was dispatched
134-
setImmediate(function() {
136+
setImmediate(function setImmediateDoWrite() {
135137
// Do not invoke callback twice
136138
if (!self._dequeue(item))
137139
return;
@@ -204,7 +206,7 @@ StreamWrap.prototype.doClose = function doClose(cb) {
204206
const self = this;
205207
const handle = self._handle;
206208

207-
setImmediate(function() {
209+
function setImmediateDoClose() {
208210
while (self._list !== null) {
209211
const item = self._list;
210212
const req = item.req;
@@ -222,5 +224,7 @@ StreamWrap.prototype.doClose = function doClose(cb) {
222224
// Should be already set by net.js
223225
assert(self._handle === null);
224226
cb();
225-
});
227+
}
228+
229+
setImmediate(setImmediateDoClose);
226230
};

lib/_stream_writable.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ WritableState.prototype.getBuffer = function getBuffer() {
122122
};
123123

124124
Object.defineProperty(WritableState.prototype, 'buffer', {
125-
get: internalUtil.deprecate(function() {
125+
get: internalUtil.deprecate(function getBuffer() {
126126
return this.getBuffer();
127127
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' +
128128
'instead.', 'DEP0003')
@@ -134,15 +134,15 @@ var realHasInstance;
134134
if (typeof Symbol === 'function' && Symbol.hasInstance) {
135135
realHasInstance = Function.prototype[Symbol.hasInstance];
136136
Object.defineProperty(Writable, Symbol.hasInstance, {
137-
value: function(object) {
137+
value: function writableHasInstance(object) {
138138
if (realHasInstance.call(this, object))
139139
return true;
140140

141141
return object && object._writableState instanceof WritableState;
142142
}
143143
});
144144
} else {
145-
realHasInstance = function(object) {
145+
realHasInstance = function _hasInstancePolyfill(object) {
146146
return object instanceof this;
147147
};
148148
}
@@ -177,7 +177,7 @@ function Writable(options) {
177177
}
178178

179179
// Otherwise people can pipe Writable streams, which is just wrong.
180-
Writable.prototype.pipe = function() {
180+
Writable.prototype.pipe = function writablePipe() {
181181
this.emit('error', new Error('Cannot pipe, not readable'));
182182
};
183183

@@ -211,7 +211,7 @@ function validChunk(stream, state, chunk, cb) {
211211
return valid;
212212
}
213213

214-
Writable.prototype.write = function(chunk, encoding, cb) {
214+
Writable.prototype.write = function writableWrite(chunk, encoding, cb) {
215215
var state = this._writableState;
216216
var ret = false;
217217
var isBuf = (chunk instanceof Buffer);
@@ -239,13 +239,13 @@ Writable.prototype.write = function(chunk, encoding, cb) {
239239
return ret;
240240
};
241241

242-
Writable.prototype.cork = function() {
242+
Writable.prototype.cork = function writableCork() {
243243
var state = this._writableState;
244244

245245
state.corked++;
246246
};
247247

248-
Writable.prototype.uncork = function() {
248+
Writable.prototype.uncork = function writableUncork() {
249249
var state = this._writableState;
250250

251251
if (state.corked) {
@@ -452,13 +452,13 @@ function clearBuffer(stream, state) {
452452
state.bufferProcessing = false;
453453
}
454454

455-
Writable.prototype._write = function(chunk, encoding, cb) {
455+
Writable.prototype._write = function writable_write(chunk, encoding, cb) {
456456
cb(new Error('_write() is not implemented'));
457457
};
458458

459459
Writable.prototype._writev = null;
460460

461-
Writable.prototype.end = function(chunk, encoding, cb) {
461+
Writable.prototype.end = function writableEnd(chunk, encoding, cb) {
462462
var state = this._writableState;
463463

464464
if (typeof chunk === 'function') {

0 commit comments

Comments
 (0)