Skip to content

Commit 2724a67

Browse files
authored
Updated to Node 8.11.1 (#332)
1 parent 9481763 commit 2724a67

17 files changed

+122
-82
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# readable-stream
22

3-
***Node-core v8.9.4 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream)
3+
***Node-core v8.11.1 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream)
44

55

66
[![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/)
@@ -18,7 +18,7 @@ npm install --save readable-stream
1818
This package is a mirror of the Streams2 and Streams3 implementations in
1919
Node-core.
2020

21-
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.9.4/docs/api/stream.html).
21+
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.11.1/docs/api/stream.html).
2222

2323
If you want to guarantee a stable streams base, regardless of what version of
2424
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_duplex.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ var Writable = require('./_stream_writable');
5252

5353
util.inherits(Duplex, Readable);
5454

55-
var keys = objectKeys(Writable.prototype);
56-
for (var v = 0; v < keys.length; v++) {
57-
var method = keys[v];
58-
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
55+
{
56+
// avoid scope creep, the keys array can then be collected
57+
var keys = objectKeys(Writable.prototype);
58+
for (var v = 0; v < keys.length; v++) {
59+
var method = keys[v];
60+
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
61+
}
5962
}
6063

6164
function Duplex(options) {
@@ -74,6 +77,16 @@ function Duplex(options) {
7477
this.once('end', onend);
7578
}
7679

80+
Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
81+
// making it explicit this property is not enumerable
82+
// because otherwise some prototype manipulation in
83+
// userland will fail
84+
enumerable: false,
85+
get: function () {
86+
return this._writableState.highWaterMark;
87+
}
88+
});
89+
7790
// the no-half-open enforcer
7891
function onend() {
7992
// if we allow half-open state, or if the writable side ended,

lib/_stream_readable.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,16 @@ Readable.prototype.wrap = function (stream) {
876876
return this;
877877
};
878878

879+
Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
880+
// making it explicit this property is not enumerable
881+
// because otherwise some prototype manipulation in
882+
// userland will fail
883+
enumerable: false,
884+
get: function () {
885+
return this._readableState.highWaterMark;
886+
}
887+
});
888+
879889
// exposed for testing purposes only.
880890
Readable._fromList = fromList;
881891

lib/_stream_writable.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,16 @@ function decodeChunk(state, chunk, encoding) {
368368
return chunk;
369369
}
370370

371+
Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
372+
// making it explicit this property is not enumerable
373+
// because otherwise some prototype manipulation in
374+
// userland will fail
375+
enumerable: false,
376+
get: function () {
377+
return this._writableState.highWaterMark;
378+
}
379+
});
380+
371381
// if we're already writing something, then just put this
372382
// in the queue, and wait our turn. Otherwise, call _write
373383
// If we return false, then we need a drain event, so set that flag.

test/common/README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ Tests whether `name` and `expected` are part of a raised warning.
133133

134134
Checks if `pathname` exists
135135

136-
### fires(promise, [error], [timeoutMs])
137-
* promise [&lt;Promise]
138-
* error [&lt;String] default = 'timeout'
139-
* timeoutMs [&lt;Number] default = 100
140-
141-
Returns a new promise that will propagate `promise` resolution or rejection if
142-
that happens within the `timeoutMs` timespan, or rejects with `error` as
143-
a reason otherwise.
144-
145136
### getArrayBufferViews(buf)
146137
* `buf` [&lt;Buffer>]
147138
* return [&lt;ArrayBufferView&#91;&#93;>]
@@ -367,6 +358,11 @@ Path to the project directory.
367358

368359
Logs '1..0 # Skipped: ' + `msg` and exits with exit code `0`.
369360

361+
### skipIfEslintMissing()
362+
363+
Skip the rest of the tests in the current file when `ESLint` is not available
364+
at `tools/node_modules/eslint`
365+
370366
### skipIfInspectorDisabled()
371367

372368
Skip the rest of the tests in the current file when the Inspector

test/common/index.js

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,11 @@ function _mustCallInner(fn) {
562562
}
563563

564564
exports.hasMultiLocalhost = function hasMultiLocalhost() {
565-
var TCP = process.binding('tcp_wrap').TCP;
566-
var t = new TCP();
565+
var _process$binding = process.binding('tcp_wrap'),
566+
TCP = _process$binding.TCP,
567+
TCPConstants = _process$binding.constants;
568+
569+
var t = new TCP(TCPConstants.SOCKET);
567570
var ret = t.bind('127.0.0.2', 0);
568571
t.close();
569572
return ret === 0;
@@ -578,6 +581,12 @@ exports.fileExists = function (pathname) {
578581
}
579582
};
580583

584+
exports.skipIfEslintMissing = function () {
585+
if (!exports.fileExists(path.join('..', '..', 'tools', 'node_modules', 'eslint'))) {
586+
exports.skip('missing ESLint');
587+
}
588+
};
589+
581590
exports.canCreateSymLink = function () {
582591
// On Windows, creating symlinks requires admin privileges.
583592
// We'll only try to run symlink test if we have enough privileges.
@@ -769,7 +778,7 @@ exports.expectsError = function expectsError(fn, settings, exact) {
769778
settings = fn;
770779
fn = undefined;
771780
}
772-
var innerFn = exports.mustCall(function (error) {
781+
function innerFn(error) {
773782
assert.strictEqual(error.code, settings.code);
774783
if ('type' in settings) {
775784
var type = settings.type;
@@ -799,12 +808,12 @@ exports.expectsError = function expectsError(fn, settings, exact) {
799808
});
800809
}
801810
return true;
802-
}, exact);
811+
}
803812
if (fn) {
804813
assert.throws(fn, innerFn);
805814
return;
806815
}
807-
return innerFn;
816+
return exports.mustCall(innerFn, exact);
808817
};
809818

810819
exports.skipIfInspectorDisabled = function skipIfInspectorDisabled() {
@@ -819,15 +828,16 @@ exports.skipIf32Bits = function skipIf32Bits() {
819828
}
820829
};
821830

822-
var arrayBufferViews = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView];
823-
824831
exports.getArrayBufferViews = function getArrayBufferViews(buf) {
825832
var buffer = buf.buffer,
826833
byteOffset = buf.byteOffset,
827834
byteLength = buf.byteLength;
828835

829836

830837
var out = [];
838+
839+
var arrayBufferViews = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView];
840+
831841
var _iteratorNormalCompletion = true;
832842
var _didIteratorError = false;
833843
var _iteratorError = undefined;
@@ -909,35 +919,6 @@ function restoreWritable(name) {
909919
delete process[name].writeTimes;
910920
}
911921

912-
function onResolvedOrRejected(promise, callback) {
913-
return promise.then(function (result) {
914-
callback();
915-
return result;
916-
}, function (error) {
917-
callback();
918-
throw error;
919-
});
920-
}
921-
922-
function timeoutPromise(error, timeoutMs) {
923-
var clearCallback = null;
924-
var done = false;
925-
var promise = onResolvedOrRejected(new Promise(function (resolve, reject) {
926-
var timeout = setTimeout(function () {
927-
return reject(error);
928-
}, timeoutMs);
929-
clearCallback = function () {
930-
if (done) return;
931-
clearTimeout(timeout);
932-
resolve();
933-
};
934-
}), function () {
935-
return done = true;
936-
});
937-
promise.clear = clearCallback;
938-
return promise;
939-
}
940-
941922
exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
942923
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
943924
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
@@ -952,19 +933,6 @@ exports.firstInvalidFD = function firstInvalidFD() {
952933
return fd;
953934
};
954935

955-
exports.fires = function fires(promise, error, timeoutMs) {
956-
if (!timeoutMs && util.isNumber(error)) {
957-
timeoutMs = error;
958-
error = null;
959-
}
960-
if (!error) error = 'timeout';
961-
if (!timeoutMs) timeoutMs = 100;
962-
var timeout = timeoutPromise(error, timeoutMs);
963-
return Promise.race([onResolvedOrRejected(promise, function () {
964-
return timeout.clear();
965-
}), timeout]);
966-
};
967-
968936
function forEach(xs, f) {
969937
for (var i = 0, l = xs.length; i < l; i++) {
970938
f(xs[i], i);

test/common/inspector-helper.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ var InspectorSession = function () {
271271
InspectorSession.prototype.waitForNotification = function waitForNotification(methodOrPredicate, description) {
272272
var desc = description || methodOrPredicate;
273273
var message = 'Timed out waiting for matching notification (' + desc + '))';
274-
return common.fires(this._asyncWaitForNotification(methodOrPredicate), message, TIMEOUT);
274+
return fires(this._asyncWaitForNotification(methodOrPredicate), message, TIMEOUT);
275275
};
276276

277277
InspectorSession.prototype._asyncWaitForNotification = async function _asyncWaitForNotification(methodOrPredicate) {
@@ -409,7 +409,7 @@ var NodeInstance = function () {
409409
NodeInstance.startViaSignal = async function startViaSignal(scriptContents) {
410410
var instance = new NodeInstance([], scriptContents + '\nprocess._rawDebug(\'started\');', undefined);
411411
var msg = 'Timed out waiting for process to start';
412-
while ((await common.fires(instance.nextStderrString(), msg, TIMEOUT)) !== 'started') {}
412+
while ((await fires(instance.nextStderrString(), msg, TIMEOUT)) !== 'started') {}
413413
process._debugProcess(instance._process.pid);
414414
return instance;
415415
};
@@ -508,6 +508,45 @@ function readMainScriptSource() {
508508
return fs.readFileSync(_MAINSCRIPT, 'utf8');
509509
}
510510

511+
function onResolvedOrRejected(promise, callback) {
512+
return promise.then(function (result) {
513+
callback();
514+
return result;
515+
}, function (error) {
516+
callback();
517+
throw error;
518+
});
519+
}
520+
521+
function timeoutPromise(error, timeoutMs) {
522+
var clearCallback = null;
523+
var done = false;
524+
var promise = onResolvedOrRejected(new Promise(function (resolve, reject) {
525+
var timeout = setTimeout(function () {
526+
return reject(error);
527+
}, timeoutMs);
528+
clearCallback = function () {
529+
if (done) return;
530+
clearTimeout(timeout);
531+
resolve();
532+
};
533+
}), function () {
534+
return done = true;
535+
});
536+
promise.clear = clearCallback;
537+
return promise;
538+
}
539+
540+
// Returns a new promise that will propagate `promise` resolution or rejection
541+
// if that happens within the `timeoutMs` timespan, or rejects with `error` as
542+
// a reason otherwise.
543+
function fires(promise, error, timeoutMs) {
544+
var timeout = timeoutPromise(error, timeoutMs);
545+
return Promise.race([onResolvedOrRejected(promise, function () {
546+
return timeout.clear();
547+
}), timeout]);
548+
}
549+
511550
module.exports = {
512551
mainScriptPath: _MAINSCRIPT,
513552
readMainScriptSource: readMainScriptSource,

test/parallel/test-stream-big-packet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ s1.pipe(s3);
6262
s2.pipe(s3, { end: false });
6363

6464
// We must write a buffer larger than highWaterMark
65-
var big = bufferShim.alloc(s1._writableState.highWaterMark + 1, 'x');
65+
var big = bufferShim.alloc(s1.writableHighWaterMark + 1, 'x');
6666

6767
// Since big is larger than highWaterMark, it will be buffered internally.
6868
assert(!s1.write(big));

test/parallel/test-stream-readable-flow-recursion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ flow(stream, 5000, function () {
6464
process.on('exit', function (code) {
6565
assert.strictEqual(reads, 2);
6666
// we pushed up the high water mark
67-
assert.strictEqual(stream._readableState.highWaterMark, 8192);
67+
assert.strictEqual(stream.readableHighWaterMark, 8192);
6868
// length is 0 right now, because we pulled it all out.
6969
assert.strictEqual(stream._readableState.length, 0);
7070
assert(!code);

test/parallel/test-stream-transform-split-objectmode.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ var parser = new Transform({ readableObjectMode: true });
3131

3232
assert(parser._readableState.objectMode);
3333
assert(!parser._writableState.objectMode);
34-
assert.strictEqual(parser._readableState.highWaterMark, 16);
35-
assert.strictEqual(parser._writableState.highWaterMark, 16 * 1024);
34+
assert.strictEqual(parser.readableHighWaterMark, 16);
35+
assert.strictEqual(parser.writableHighWaterMark, 16 * 1024);
36+
assert.strictEqual(parser.readableHighWaterMark, parser._readableState.highWaterMark);
37+
assert.strictEqual(parser.writableHighWaterMark, parser._writableState.highWaterMark);
3638

3739
parser._transform = function (chunk, enc, callback) {
3840
callback(null, { val: chunk[0] });
@@ -54,8 +56,10 @@ var serializer = new Transform({ writableObjectMode: true });
5456

5557
assert(!serializer._readableState.objectMode);
5658
assert(serializer._writableState.objectMode);
57-
assert.strictEqual(serializer._readableState.highWaterMark, 16 * 1024);
58-
assert.strictEqual(serializer._writableState.highWaterMark, 16);
59+
assert.strictEqual(serializer.readableHighWaterMark, 16 * 1024);
60+
assert.strictEqual(serializer.writableHighWaterMark, 16);
61+
assert.strictEqual(parser.readableHighWaterMark, parser._readableState.highWaterMark);
62+
assert.strictEqual(parser.writableHighWaterMark, parser._writableState.highWaterMark);
5963

6064
serializer._transform = function (obj, _, callback) {
6165
callback(null, bufferShim.from([obj.val]));

0 commit comments

Comments
 (0)