From 2724a6720afd80f04b58e1d94403bfee397be85b Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 4 Apr 2018 17:33:36 +0200 Subject: [PATCH] Updated to Node 8.11.1 (#332) --- README.md | 4 +- lib/_stream_duplex.js | 21 ++++-- lib/_stream_readable.js | 10 +++ lib/_stream_writable.js | 10 +++ test/common/README.md | 14 ++-- test/common/index.js | 66 +++++-------------- test/common/inspector-helper.js | 43 +++++++++++- test/parallel/test-stream-big-packet.js | 2 +- .../test-stream-readable-flow-recursion.js | 2 +- .../test-stream-transform-split-objectmode.js | 12 ++-- .../parallel/test-stream-unshift-read-race.js | 4 +- test/parallel/test-stream-writev.js | 2 +- .../parallel/test-stream2-large-read-stall.js | 6 +- test/parallel/test-stream2-push.js | 2 +- .../test-stream2-readable-non-empty-end.js | 2 +- test/parallel/test-stream2-unpipe-leak.js | 2 +- test/parallel/test-stream3-pause-then-read.js | 2 +- 17 files changed, 122 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index f0d8b47c13..23fe3f3e30 100644 --- a/README.md +++ b/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/) @@ -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). diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index 7d9f0508cd..a1ca813e5a 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -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) { @@ -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, diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index b582f91a91..bf34ac65e1 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -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; diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 0e1c28df51..b3f4e85a2f 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -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. diff --git a/test/common/README.md b/test/common/README.md index 0e25d983de..67e4e4e48f 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -133,15 +133,6 @@ Tests whether `name` and `expected` are part of a raised warning. Checks if `pathname` exists -### fires(promise, [error], [timeoutMs]) -* promise [<Promise] -* error [<String] default = 'timeout' -* timeoutMs [<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` [<Buffer>] * return [<ArrayBufferView[]>] @@ -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 diff --git a/test/common/index.js b/test/common/index.js index 61a5510754..33fa11e8d6 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -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; @@ -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. @@ -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; @@ -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() { @@ -819,8 +828,6 @@ 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, @@ -828,6 +835,9 @@ exports.getArrayBufferViews = function getArrayBufferViews(buf) { var out = []; + + var arrayBufferViews = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView]; + var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; @@ -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'); @@ -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); diff --git a/test/common/inspector-helper.js b/test/common/inspector-helper.js index 6f3e818df5..3e4f16573a 100644 --- a/test/common/inspector-helper.js +++ b/test/common/inspector-helper.js @@ -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) { @@ -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; }; @@ -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, diff --git a/test/parallel/test-stream-big-packet.js b/test/parallel/test-stream-big-packet.js index 19a86498c7..85de251100 100644 --- a/test/parallel/test-stream-big-packet.js +++ b/test/parallel/test-stream-big-packet.js @@ -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)); diff --git a/test/parallel/test-stream-readable-flow-recursion.js b/test/parallel/test-stream-readable-flow-recursion.js index b14fa65a50..0b6704a212 100644 --- a/test/parallel/test-stream-readable-flow-recursion.js +++ b/test/parallel/test-stream-readable-flow-recursion.js @@ -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); diff --git a/test/parallel/test-stream-transform-split-objectmode.js b/test/parallel/test-stream-transform-split-objectmode.js index 0bec5bbf1c..097c3d789f 100644 --- a/test/parallel/test-stream-transform-split-objectmode.js +++ b/test/parallel/test-stream-transform-split-objectmode.js @@ -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] }); @@ -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])); diff --git a/test/parallel/test-stream-unshift-read-race.js b/test/parallel/test-stream-unshift-read-race.js index 89272ccf19..0e615db95d 100644 --- a/test/parallel/test-stream-unshift-read-race.js +++ b/test/parallel/test-stream-unshift-read-race.js @@ -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); diff --git a/test/parallel/test-stream-writev.js b/test/parallel/test-stream-writev.js index c69dfad830..478121e880 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -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) { diff --git a/test/parallel/test-stream2-large-read-stall.js b/test/parallel/test-stream2-large-read-stall.js index a9dd386169..deabcf1b9c 100644 --- a/test/parallel/test-stream2-large-read-stall.js +++ b/test/parallel/test-stream2-large-read-stall.js @@ -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); @@ -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); } \ No newline at end of file diff --git a/test/parallel/test-stream2-push.js b/test/parallel/test-stream2-push.js index 197a37ffd9..358e57a7a5 100644 --- a/test/parallel/test-stream2-push.js +++ b/test/parallel/test-stream2-push.js @@ -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); }; diff --git a/test/parallel/test-stream2-readable-non-empty-end.js b/test/parallel/test-stream2-readable-non-empty-end.js index d062e60258..f9045ae513 100644 --- a/test/parallel/test-stream2-readable-non-empty-end.js +++ b/test/parallel/test-stream2-readable-non-empty-end.js @@ -53,7 +53,7 @@ test.on('readable', function () { var res = test.read(b); if (res) { bytesread += res.length; - console.error('br=%d len=%d', bytesread, len); + console.error('br=' + bytesread + ' len=' + len); setTimeout(next, 1); } test.read(0); diff --git a/test/parallel/test-stream2-unpipe-leak.js b/test/parallel/test-stream2-unpipe-leak.js index b50160a886..e77e939ed1 100644 --- a/test/parallel/test-stream2-unpipe-leak.js +++ b/test/parallel/test-stream2-unpipe-leak.js @@ -93,6 +93,6 @@ console.error(src._readableState); process.on('exit', function () { src._readableState.buffer.length = 0; console.error(src._readableState); - assert(src._readableState.length >= src._readableState.highWaterMark); + assert(src._readableState.length >= src.readableHighWaterMark); console.log('ok'); }); \ No newline at end of file diff --git a/test/parallel/test-stream3-pause-then-read.js b/test/parallel/test-stream3-pause-then-read.js index 8afc1e65a3..a0269492e4 100644 --- a/test/parallel/test-stream3-pause-then-read.js +++ b/test/parallel/test-stream3-pause-then-read.js @@ -57,7 +57,7 @@ function read100() { } function readn(n, then) { - console.error('read %d', n); + console.error('read ' + n); expectEndingData -= n; (function read() { var c = r.read(n);