Skip to content

Commit

Permalink
Updated to Node 8.11.1 (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Apr 4, 2018
1 parent 9481763 commit 2724a67
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 82 deletions.
4 changes: 2 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
# readable-stream

***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)
***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)


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

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

If you want to guarantee a stable streams base, regardless of what version of
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).
Expand Down
21 changes: 17 additions & 4 deletions lib/_stream_duplex.js
Expand Up @@ -52,10 +52,13 @@ var Writable = require('./_stream_writable');

util.inherits(Duplex, Readable);

var keys = objectKeys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
var method = keys[v];
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
{
// avoid scope creep, the keys array can then be collected
var keys = objectKeys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
var method = keys[v];
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
}
}

function Duplex(options) {
Expand All @@ -74,6 +77,16 @@ function Duplex(options) {
this.once('end', onend);
}

Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
// making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get: function () {
return this._writableState.highWaterMark;
}
});

// the no-half-open enforcer
function onend() {
// if we allow half-open state, or if the writable side ended,
Expand Down
10 changes: 10 additions & 0 deletions lib/_stream_readable.js
Expand Up @@ -876,6 +876,16 @@ Readable.prototype.wrap = function (stream) {
return this;
};

Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
// making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get: function () {
return this._readableState.highWaterMark;
}
});

// exposed for testing purposes only.
Readable._fromList = fromList;

Expand Down
10 changes: 10 additions & 0 deletions lib/_stream_writable.js
Expand Up @@ -368,6 +368,16 @@ function decodeChunk(state, chunk, encoding) {
return chunk;
}

Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
// making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get: function () {
return this._writableState.highWaterMark;
}
});

// if we're already writing something, then just put this
// in the queue, and wait our turn. Otherwise, call _write
// If we return false, then we need a drain event, so set that flag.
Expand Down
14 changes: 5 additions & 9 deletions test/common/README.md
Expand Up @@ -133,15 +133,6 @@ Tests whether `name` and `expected` are part of a raised warning.

Checks if `pathname` exists

### fires(promise, [error], [timeoutMs])
* promise [&lt;Promise]
* error [&lt;String] default = 'timeout'
* timeoutMs [&lt;Number] default = 100

Returns a new promise that will propagate `promise` resolution or rejection if
that happens within the `timeoutMs` timespan, or rejects with `error` as
a reason otherwise.

### getArrayBufferViews(buf)
* `buf` [&lt;Buffer>]
* return [&lt;ArrayBufferView&#91;&#93;>]
Expand Down Expand Up @@ -367,6 +358,11 @@ Path to the project directory.

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

### skipIfEslintMissing()

Skip the rest of the tests in the current file when `ESLint` is not available
at `tools/node_modules/eslint`

### skipIfInspectorDisabled()

Skip the rest of the tests in the current file when the Inspector
Expand Down
66 changes: 17 additions & 49 deletions test/common/index.js
Expand Up @@ -562,8 +562,11 @@ function _mustCallInner(fn) {
}

exports.hasMultiLocalhost = function hasMultiLocalhost() {
var TCP = process.binding('tcp_wrap').TCP;
var t = new TCP();
var _process$binding = process.binding('tcp_wrap'),
TCP = _process$binding.TCP,
TCPConstants = _process$binding.constants;

var t = new TCP(TCPConstants.SOCKET);
var ret = t.bind('127.0.0.2', 0);
t.close();
return ret === 0;
Expand All @@ -578,6 +581,12 @@ exports.fileExists = function (pathname) {
}
};

exports.skipIfEslintMissing = function () {
if (!exports.fileExists(path.join('..', '..', 'tools', 'node_modules', 'eslint'))) {
exports.skip('missing ESLint');
}
};

exports.canCreateSymLink = function () {
// On Windows, creating symlinks requires admin privileges.
// We'll only try to run symlink test if we have enough privileges.
Expand Down Expand Up @@ -769,7 +778,7 @@ exports.expectsError = function expectsError(fn, settings, exact) {
settings = fn;
fn = undefined;
}
var innerFn = exports.mustCall(function (error) {
function innerFn(error) {
assert.strictEqual(error.code, settings.code);
if ('type' in settings) {
var type = settings.type;
Expand Down Expand Up @@ -799,12 +808,12 @@ exports.expectsError = function expectsError(fn, settings, exact) {
});
}
return true;
}, exact);
}
if (fn) {
assert.throws(fn, innerFn);
return;
}
return innerFn;
return exports.mustCall(innerFn, exact);
};

exports.skipIfInspectorDisabled = function skipIfInspectorDisabled() {
Expand All @@ -819,15 +828,16 @@ exports.skipIf32Bits = function skipIf32Bits() {
}
};

var arrayBufferViews = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView];

exports.getArrayBufferViews = function getArrayBufferViews(buf) {
var buffer = buf.buffer,
byteOffset = buf.byteOffset,
byteLength = buf.byteLength;


var out = [];

var arrayBufferViews = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView];

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
Expand Down Expand Up @@ -909,35 +919,6 @@ function restoreWritable(name) {
delete process[name].writeTimes;
}

function onResolvedOrRejected(promise, callback) {
return promise.then(function (result) {
callback();
return result;
}, function (error) {
callback();
throw error;
});
}

function timeoutPromise(error, timeoutMs) {
var clearCallback = null;
var done = false;
var promise = onResolvedOrRejected(new Promise(function (resolve, reject) {
var timeout = setTimeout(function () {
return reject(error);
}, timeoutMs);
clearCallback = function () {
if (done) return;
clearTimeout(timeout);
resolve();
};
}), function () {
return done = true;
});
promise.clear = clearCallback;
return promise;
}

exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
Expand All @@ -952,19 +933,6 @@ exports.firstInvalidFD = function firstInvalidFD() {
return fd;
};

exports.fires = function fires(promise, error, timeoutMs) {
if (!timeoutMs && util.isNumber(error)) {
timeoutMs = error;
error = null;
}
if (!error) error = 'timeout';
if (!timeoutMs) timeoutMs = 100;
var timeout = timeoutPromise(error, timeoutMs);
return Promise.race([onResolvedOrRejected(promise, function () {
return timeout.clear();
}), timeout]);
};

function forEach(xs, f) {
for (var i = 0, l = xs.length; i < l; i++) {
f(xs[i], i);
Expand Down
43 changes: 41 additions & 2 deletions test/common/inspector-helper.js
Expand Up @@ -271,7 +271,7 @@ var InspectorSession = function () {
InspectorSession.prototype.waitForNotification = function waitForNotification(methodOrPredicate, description) {
var desc = description || methodOrPredicate;
var message = 'Timed out waiting for matching notification (' + desc + '))';
return common.fires(this._asyncWaitForNotification(methodOrPredicate), message, TIMEOUT);
return fires(this._asyncWaitForNotification(methodOrPredicate), message, TIMEOUT);
};

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

function onResolvedOrRejected(promise, callback) {
return promise.then(function (result) {
callback();
return result;
}, function (error) {
callback();
throw error;
});
}

function timeoutPromise(error, timeoutMs) {
var clearCallback = null;
var done = false;
var promise = onResolvedOrRejected(new Promise(function (resolve, reject) {
var timeout = setTimeout(function () {
return reject(error);
}, timeoutMs);
clearCallback = function () {
if (done) return;
clearTimeout(timeout);
resolve();
};
}), function () {
return done = true;
});
promise.clear = clearCallback;
return promise;
}

// Returns a new promise that will propagate `promise` resolution or rejection
// if that happens within the `timeoutMs` timespan, or rejects with `error` as
// a reason otherwise.
function fires(promise, error, timeoutMs) {
var timeout = timeoutPromise(error, timeoutMs);
return Promise.race([onResolvedOrRejected(promise, function () {
return timeout.clear();
}), timeout]);
}

module.exports = {
mainScriptPath: _MAINSCRIPT,
readMainScriptSource: readMainScriptSource,
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-big-packet.js
Expand Up @@ -62,7 +62,7 @@ s1.pipe(s3);
s2.pipe(s3, { end: false });

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

// Since big is larger than highWaterMark, it will be buffered internally.
assert(!s1.write(big));
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readable-flow-recursion.js
Expand Up @@ -64,7 +64,7 @@ flow(stream, 5000, function () {
process.on('exit', function (code) {
assert.strictEqual(reads, 2);
// we pushed up the high water mark
assert.strictEqual(stream._readableState.highWaterMark, 8192);
assert.strictEqual(stream.readableHighWaterMark, 8192);
// length is 0 right now, because we pulled it all out.
assert.strictEqual(stream._readableState.length, 0);
assert(!code);
Expand Down
12 changes: 8 additions & 4 deletions test/parallel/test-stream-transform-split-objectmode.js
Expand Up @@ -31,8 +31,10 @@ var parser = new Transform({ readableObjectMode: true });

assert(parser._readableState.objectMode);
assert(!parser._writableState.objectMode);
assert.strictEqual(parser._readableState.highWaterMark, 16);
assert.strictEqual(parser._writableState.highWaterMark, 16 * 1024);
assert.strictEqual(parser.readableHighWaterMark, 16);
assert.strictEqual(parser.writableHighWaterMark, 16 * 1024);
assert.strictEqual(parser.readableHighWaterMark, parser._readableState.highWaterMark);
assert.strictEqual(parser.writableHighWaterMark, parser._writableState.highWaterMark);

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

assert(!serializer._readableState.objectMode);
assert(serializer._writableState.objectMode);
assert.strictEqual(serializer._readableState.highWaterMark, 16 * 1024);
assert.strictEqual(serializer._writableState.highWaterMark, 16);
assert.strictEqual(serializer.readableHighWaterMark, 16 * 1024);
assert.strictEqual(serializer.writableHighWaterMark, 16);
assert.strictEqual(parser.readableHighWaterMark, parser._readableState.highWaterMark);
assert.strictEqual(parser.writableHighWaterMark, parser._writableState.highWaterMark);

serializer._transform = function (obj, _, callback) {
callback(null, bufferShim.from([obj.val]));
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream-unshift-read-race.js
Expand Up @@ -103,9 +103,9 @@ w.on('finish', common.mustCall(function () {
// lacking that piece.
assert.strictEqual(written[0], 'asdfasdfas');
var asdf = 'd';
console.error('0: %s', written[0]);
console.error('0: ' + written[0]);
for (var _i = 1; _i < written.length; _i++) {
console.error('%s: %s', _i.toString(32), written[_i]);
console.error(_i.toString(32) + ': ' + written[_i]);
assert.strictEqual(written[_i].slice(0, 4), '1234');
for (var j = 4; j < written[_i].length; j++) {
var _c = written[_i].charAt(j);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-writev.js
Expand Up @@ -44,7 +44,7 @@ function run() {
}

function test(decode, uncork, multi, next) {
console.log('# decode=%j uncork=%j multi=%j', decode, uncork, multi);
console.log('# decode=' + decode + ' uncork=' + uncork + ' multi=' + multi);
var counter = 0;
var expectCount = 0;
function cnt(msg) {
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-stream2-large-read-stall.js
Expand Up @@ -45,9 +45,9 @@ r.on('readable', function () {
;false && console.error('>> readable');
var ret = void 0;
do {
;false && console.error(' > read(%d)', READSIZE);
;false && console.error(' > read(' + READSIZE + ')');
ret = r.read(READSIZE);
;false && console.error(' < %j (%d remain)', ret && ret.length, rs.length);
;false && console.error(' < ' + (ret && ret.length) + ' (' + rs.length + ' remain)');
} while (ret && ret.length === READSIZE);

;false && console.error('<< after read()', ret && ret.length, rs.needReadable, rs.length);
Expand All @@ -66,6 +66,6 @@ function push() {
return r.push(null);
}

;false && console.error(' push #%d', pushes);
;false && console.error(' push #' + pushes);
if (r.push(bufferShim.allocUnsafe(PUSHSIZE))) setTimeout(push, 1);
}
2 changes: 1 addition & 1 deletion test/parallel/test-stream2-push.js
Expand Up @@ -85,7 +85,7 @@ var written = [];
var expectWritten = ['asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg'];

writer._write = function (chunk, encoding, cb) {
console.error('WRITE %s', chunk);
console.error('WRITE ' + chunk);
written.push(chunk);
process.nextTick(cb);
};
Expand Down

0 comments on commit 2724a67

Please sign in to comment.