Skip to content

Commit cbd72df

Browse files
authored
Updated to v10.15.2 (#401)
1 parent e02fcbb commit cbd72df

File tree

6 files changed

+167
-10
lines changed

6 files changed

+167
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npm install --save readable-stream
1515

1616
This package is a mirror of the streams implementations in Node.js.
1717

18-
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.14.2/docs/api/stream.html).
18+
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.15.2/docs/api/stream.html).
1919

2020
If you want to guarantee a stable streams base, regardless of what version of
2121
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).

lib/_stream_readable.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ function ReadableState(options, stream, isDuplex) {
141141
this.needReadable = false;
142142
this.emittedReadable = false;
143143
this.readableListening = false;
144-
this.resumeScheduled = false; // Should close be emitted on destroy. Defaults to true.
144+
this.resumeScheduled = false;
145+
this.paused = true; // Should close be emitted on destroy. Defaults to true.
145146

146147
this.emitClose = options.emitClose !== false; // has it been destroyed
147148

@@ -822,9 +823,14 @@ Readable.prototype.removeAllListeners = function (ev) {
822823
};
823824

824825
function updateReadableListening(self) {
825-
self._readableState.readableListening = self.listenerCount('readable') > 0; // crude way to check if we should resume
826-
827-
if (self.listenerCount('data') > 0) {
826+
var state = self._readableState;
827+
state.readableListening = self.listenerCount('readable') > 0;
828+
829+
if (state.resumeScheduled && !state.paused) {
830+
// flowing needs to be set to true now, otherwise
831+
// the upcoming resume will not flow.
832+
state.flowing = true; // crude way to check if we should resume
833+
} else if (self.listenerCount('data') > 0) {
828834
self.resume();
829835
}
830836
}
@@ -848,6 +854,7 @@ Readable.prototype.resume = function () {
848854
resume(this, state);
849855
}
850856

857+
state.paused = false;
851858
return this;
852859
};
853860

@@ -880,6 +887,7 @@ Readable.prototype.pause = function () {
880887
this.emit('pause');
881888
}
882889

890+
this._readableState.paused = true;
883891
return this;
884892
};
885893

lib/_stream_writable.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ function WritableState(options, stream, isDuplex) {
103103
options = options || {}; // Duplex streams are both readable and writable, but share
104104
// the same options object.
105105
// However, some cases require setting options to different
106-
// values for the readable and the writable sides of the duplex stream.
107-
// These options can be provided separately as readableXXX and writableXXX.
106+
// values for the readable and the writable sides of the duplex stream,
107+
// e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
108108

109109
if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
110110
// contains buffers or objects.
@@ -445,7 +445,7 @@ function onwrite(stream, er) {
445445
onwriteStateUpdate(state);
446446
if (er) onwriteError(stream, state, sync, er, cb);else {
447447
// Check if we're actually ready to finish, but don't emit yet
448-
var finished = needFinish(state);
448+
var finished = needFinish(state) || stream.destroyed;
449449

450450
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
451451
clearBuffer(stream, state);

test/common/inspector-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ function (_EventEmitter) {
635635

636636
console.log('[test]', 'Connecting to a child Node process');
637637
var upgradeRequest = yield this.sendUpgradeRequest();
638-
return new Promise(function (resolve, reject) {
638+
return new Promise(function (resolve) {
639639
upgradeRequest.on('upgrade', function (message, socket) {
640640
return resolve(new InspectorSession(socket, _this8));
641641
}).on('response', common.mustNotCall('Upgrade was not received'));
@@ -655,7 +655,7 @@ function (_EventEmitter) {
655655
var _expectConnectionDeclined = _asyncToGenerator(function* () {
656656
console.log('[test]', 'Checking upgrade is not possible');
657657
var upgradeRequest = yield this.sendUpgradeRequest();
658-
return new Promise(function (resolve, reject) {
658+
return new Promise(function (resolve) {
659659
upgradeRequest.on('upgrade', common.mustNotCall('Upgrade was received')).on('response', function (response) {
660660
return response.on('data', function () {}).on('end', function () {
661661
return resolve(response.statusCode);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use strict";
2+
3+
/*<replacement>*/
4+
var bufferShim = require('safe-buffer').Buffer;
5+
/*</replacement>*/
6+
7+
8+
var common = require('../common');
9+
10+
var _require = require('../../'),
11+
Readable = _require.Readable; // This test verifies that a stream could be resumed after
12+
// removing the readable event in the same tick
13+
14+
15+
check(new Readable({
16+
objectMode: true,
17+
highWaterMark: 1,
18+
read: function read() {
19+
if (!this.first) {
20+
this.push('hello');
21+
this.first = true;
22+
return;
23+
}
24+
25+
this.push(null);
26+
}
27+
}));
28+
29+
function check(s) {
30+
var readableListener = common.mustNotCall();
31+
s.on('readable', readableListener);
32+
s.on('end', common.mustCall());
33+
s.removeListener('readable', readableListener);
34+
s.resume();
35+
}
36+
37+
;
38+
39+
require('tap').pass('sync run');
40+
41+
var _list = process.listeners('uncaughtException');
42+
43+
process.removeAllListeners('uncaughtException');
44+
45+
_list.pop();
46+
47+
_list.forEach(function (e) {
48+
return process.on('uncaughtException', e);
49+
});
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"use strict";
2+
3+
/*<replacement>*/
4+
var bufferShim = require('safe-buffer').Buffer;
5+
/*</replacement>*/
6+
7+
8+
require('../common');
9+
10+
var assert = require('assert/');
11+
12+
var _require = require('../../'),
13+
Writable = _require.Writable; // Test interaction between calling .destroy() on a writable and pending
14+
// writes.
15+
16+
17+
var _arr = [false, true];
18+
19+
for (var _i = 0; _i < _arr.length; _i++) {
20+
var withPendingData = _arr[_i];
21+
var _arr2 = [false, true];
22+
23+
var _loop = function _loop() {
24+
var useEnd = _arr2[_i2];
25+
var callbacks = [];
26+
var w = new Writable({
27+
write: function write(data, enc, cb) {
28+
callbacks.push(cb);
29+
},
30+
// Effectively disable the HWM to observe 'drain' events more easily.
31+
highWaterMark: 1
32+
});
33+
var chunksWritten = 0;
34+
var drains = 0;
35+
var finished = false;
36+
w.on('drain', function () {
37+
return drains++;
38+
});
39+
w.on('finish', function () {
40+
return finished = true;
41+
});
42+
w.write('abc', function () {
43+
return chunksWritten++;
44+
});
45+
assert.strictEqual(chunksWritten, 0);
46+
assert.strictEqual(drains, 0);
47+
callbacks.shift()();
48+
assert.strictEqual(chunksWritten, 1);
49+
assert.strictEqual(drains, 1);
50+
51+
if (withPendingData) {
52+
// Test 2 cases: There either is or is not data still in the write queue.
53+
// (The second write will never actually get executed either way.)
54+
w.write('def', function () {
55+
return chunksWritten++;
56+
});
57+
}
58+
59+
if (useEnd) {
60+
// Again, test 2 cases: Either we indicate that we want to end the
61+
// writable or not.
62+
w.end('ghi', function () {
63+
return chunksWritten++;
64+
});
65+
} else {
66+
w.write('ghi', function () {
67+
return chunksWritten++;
68+
});
69+
}
70+
71+
assert.strictEqual(chunksWritten, 1);
72+
w.destroy();
73+
assert.strictEqual(chunksWritten, 1);
74+
callbacks.shift()();
75+
assert.strictEqual(chunksWritten, 2);
76+
assert.strictEqual(callbacks.length, 0);
77+
assert.strictEqual(drains, 1); // When we used `.end()`, we see the 'finished' event if and only if
78+
// we actually finished processing the write queue.
79+
80+
assert.strictEqual(finished, !withPendingData && useEnd);
81+
};
82+
83+
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
84+
_loop();
85+
}
86+
}
87+
88+
;
89+
90+
require('tap').pass('sync run');
91+
92+
var _list = process.listeners('uncaughtException');
93+
94+
process.removeAllListeners('uncaughtException');
95+
96+
_list.pop();
97+
98+
_list.forEach(function (e) {
99+
return process.on('uncaughtException', e);
100+
});

0 commit comments

Comments
 (0)