diff --git a/.babelrc b/.babelrc index 465861f3d..e61393e66 100644 --- a/.babelrc +++ b/.babelrc @@ -2,9 +2,7 @@ "presets": [ ["@babel/preset-env", { "targets": [ - "last 2 versions", - "not dead", - "node 6.0" + "node 0.10" ], "modules": "commonjs", "exclude": [ diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index c51c67d41..19abfa604 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -35,14 +35,14 @@ var objectKeys = Object.keys || function (obj) { /**/ module.exports = Duplex; -const Readable = require('./_stream_readable'); -const Writable = require('./_stream_writable'); +var Readable = require('./_stream_readable'); +var Writable = require('./_stream_writable'); require('inherits')(Duplex, Readable); { // Allow the keys array to be GC'ed. - const keys = objectKeys(Writable.prototype); + var keys = objectKeys(Writable.prototype); for (var v = 0; v < keys.length; v++) { - const method = keys[v]; + var method = keys[v]; if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; } } @@ -65,7 +65,7 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { // because otherwise some prototype manipulation in // userland will fail enumerable: false, - get() { + get: function get() { return this._writableState.highWaterMark; } }); @@ -83,7 +83,7 @@ Object.defineProperty(Duplex.prototype, 'writableLength', { // because otherwise some prototype manipulation in // userland will fail enumerable: false, - get() { + get: function get() { return this._writableState.length; } }); @@ -105,13 +105,13 @@ Object.defineProperty(Duplex.prototype, 'destroyed', { // because otherwise some prototype manipulation in // userland will fail enumerable: false, - get() { + get: function get() { if (this._readableState === undefined || this._writableState === undefined) { return false; } return this._readableState.destroyed && this._writableState.destroyed; }, - set(value) { + set: function set(value) { // we ignore the value if the stream // has not been initialized yet if (this._readableState === undefined || this._writableState === undefined) { diff --git a/lib/_stream_passthrough.js b/lib/_stream_passthrough.js index 38a1eaac8..24a6bdde2 100644 --- a/lib/_stream_passthrough.js +++ b/lib/_stream_passthrough.js @@ -26,7 +26,7 @@ 'use strict'; module.exports = PassThrough; -const Transform = require('./_stream_transform'); +var Transform = require('./_stream_transform'); require('inherits')(PassThrough, Transform); function PassThrough(options) { if (!(this instanceof PassThrough)) return new PassThrough(options); diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 8e3af6c9e..df1f608d5 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -30,7 +30,7 @@ var Duplex; Readable.ReadableState = ReadableState; /**/ -const EE = require('events').EventEmitter; +var EE = require('events').EventEmitter; var EElistenerCount = function EElistenerCount(emitter, type) { return emitter.listeners(type).length; }; @@ -40,8 +40,8 @@ var EElistenerCount = function EElistenerCount(emitter, type) { var Stream = require('./internal/streams/stream'); /**/ -const Buffer = require('buffer').Buffer; -const OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; +var Buffer = require('buffer').Buffer; +var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; function _uint8ArrayToBuffer(chunk) { return Buffer.from(chunk); } @@ -50,8 +50,8 @@ function _isUint8Array(obj) { } /**/ -const debugUtil = require('util'); -let debug; +var debugUtil = require('util'); +var debug; if (debugUtil && debugUtil.debuglog) { debug = debugUtil.debuglog('stream'); } else { @@ -59,23 +59,23 @@ if (debugUtil && debugUtil.debuglog) { } /**/ -const BufferList = require('./internal/streams/buffer_list'); -const destroyImpl = require('./internal/streams/destroy'); -const _require = require('./internal/streams/state'), +var BufferList = require('./internal/streams/buffer_list'); +var destroyImpl = require('./internal/streams/destroy'); +var _require = require('./internal/streams/state'), getHighWaterMark = _require.getHighWaterMark; -const _require$codes = require('../errors').codes, +var _require$codes = require('../errors').codes, ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF, ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance. -let StringDecoder; -let createReadableStreamAsyncIterator; -let from; +var StringDecoder; +var createReadableStreamAsyncIterator; +var from; require('inherits')(Readable, Stream); -const errorOrDestroy = destroyImpl.errorOrDestroy; -const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; +var errorOrDestroy = destroyImpl.errorOrDestroy; +var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; function prependListener(emitter, event, fn) { // Sadly this is not cacheable as some libraries bundle their own // event emitter implementation with them. @@ -166,7 +166,7 @@ function Readable(options) { // Checking for a Stream.Duplex instance is faster here instead of inside // the ReadableState constructor, at least with V8 6.5 - const isDuplex = this instanceof Duplex; + var isDuplex = this instanceof Duplex; this._readableState = new ReadableState(options, this, isDuplex); // legacy @@ -182,13 +182,13 @@ Object.defineProperty(Readable.prototype, 'destroyed', { // because otherwise some prototype manipulation in // userland will fail enumerable: false, - get() { + get: function get() { if (this._readableState === undefined) { return false; } return this._readableState.destroyed; }, - set(value) { + set: function set(value) { // we ignore the value if the stream // has not been initialized yet if (!this._readableState) { @@ -299,14 +299,14 @@ Readable.prototype.isPaused = function () { // backwards compatibility. Readable.prototype.setEncoding = function (enc) { if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; - const decoder = new StringDecoder(enc); + var decoder = new StringDecoder(enc); this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8 this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers: - let p = this._readableState.buffer.head; - let content = ''; + var p = this._readableState.buffer.head; + var content = ''; while (p !== null) { content += decoder.write(p.data); p = p.next; @@ -318,7 +318,7 @@ Readable.prototype.setEncoding = function (enc) { }; // Don't raise the hwm > 1GB -const MAX_HWM = 0x40000000; +var MAX_HWM = 0x40000000; function computeNewHighWaterMark(n) { if (n >= MAX_HWM) { // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE. @@ -545,7 +545,7 @@ function maybeReadMore_(stream, state) { // read()s. The execution ends in this method again after the _read() ends // up calling push() with more data. while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) { - const len = state.length; + var len = state.length; debug('maybeReadMore read 0'); stream.read(0); if (len === state.length) @@ -742,8 +742,8 @@ Readable.prototype.unpipe = function (dest) { // set up data events if they are asked for // Ensure readable listeners eventually get something Readable.prototype.on = function (ev, fn) { - const res = Stream.prototype.on.call(this, ev, fn); - const state = this._readableState; + var res = Stream.prototype.on.call(this, ev, fn); + var state = this._readableState; if (ev === 'data') { // update readableListening so that resume() may be a no-op // a few lines down. This is needed to support once('readable'). @@ -768,7 +768,7 @@ Readable.prototype.on = function (ev, fn) { }; Readable.prototype.addListener = Readable.prototype.on; Readable.prototype.removeListener = function (ev, fn) { - const res = Stream.prototype.removeListener.call(this, ev, fn); + var res = Stream.prototype.removeListener.call(this, ev, fn); if (ev === 'readable') { // We need to check if there is someone still listening to // readable and reset the state. However this needs to happen @@ -781,7 +781,7 @@ Readable.prototype.removeListener = function (ev, fn) { return res; }; Readable.prototype.removeAllListeners = function (ev) { - const res = Stream.prototype.removeAllListeners.apply(this, arguments); + var res = Stream.prototype.removeAllListeners.apply(this, arguments); if (ev === 'readable' || ev === undefined) { // We need to check if there is someone still listening to // readable and reset the state. However this needs to happen @@ -794,7 +794,7 @@ Readable.prototype.removeAllListeners = function (ev) { return res; }; function updateReadableListening(self) { - const state = self._readableState; + var state = self._readableState; state.readableListening = self.listenerCount('readable') > 0; if (state.resumeScheduled && !state.paused) { // flowing needs to be set to true now, otherwise @@ -853,7 +853,7 @@ Readable.prototype.pause = function () { return this; }; function flow(stream) { - const state = stream._readableState; + var state = stream._readableState; debug('flow', state.flowing); while (state.flowing && stream.read() !== null); } @@ -862,23 +862,24 @@ function flow(stream) { // This is *not* part of the readable stream interface. // It is an ugly unfortunate mess of history. Readable.prototype.wrap = function (stream) { + var _this = this; var state = this._readableState; var paused = false; - stream.on('end', () => { + stream.on('end', function () { debug('wrapped end'); if (state.decoder && !state.ended) { var chunk = state.decoder.end(); - if (chunk && chunk.length) this.push(chunk); + if (chunk && chunk.length) _this.push(chunk); } - this.push(null); + _this.push(null); }); - stream.on('data', chunk => { + stream.on('data', function (chunk) { debug('wrapped data'); if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; - var ret = this.push(chunk); + var ret = _this.push(chunk); if (!ret) { paused = true; stream.pause(); @@ -904,7 +905,7 @@ Readable.prototype.wrap = function (stream) { // when we try to consume some more bytes, simply unpause the // underlying stream. - this._read = n => { + this._read = function (n) { debug('wrapped _read', n); if (paused) { paused = false; @@ -961,7 +962,7 @@ Object.defineProperty(Readable.prototype, 'readableLength', { // because otherwise some prototype manipulation in // userland will fail enumerable: false, - get() { + get: function get() { return this._readableState.length; } }); @@ -1003,7 +1004,7 @@ function endReadableNT(state, stream) { if (state.autoDestroy) { // In case of duplex streams we need a way to detect // if the writable side is ready for autoDestroy as well - const wState = stream._writableState; + var wState = stream._writableState; if (!wState || wState.autoDestroy && wState.finished) { stream.destroy(); } diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js index a2fcca219..1ccb7157b 100644 --- a/lib/_stream_transform.js +++ b/lib/_stream_transform.js @@ -64,12 +64,12 @@ 'use strict'; module.exports = Transform; -const _require$codes = require('../errors').codes, +var _require$codes = require('../errors').codes, ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING, ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0; -const Duplex = require('./_stream_duplex'); +var Duplex = require('./_stream_duplex'); require('inherits')(Transform, Duplex); function afterTransform(er, data) { var ts = this._transformState; @@ -118,9 +118,10 @@ function Transform(options) { this.on('prefinish', prefinish); } function prefinish() { + var _this = this; if (typeof this._flush === 'function' && !this._readableState.destroyed) { - this._flush((er, data) => { - done(this, er, data); + this._flush(function (er, data) { + done(_this, er, data); }); } else { done(this, null, null); @@ -170,7 +171,7 @@ Transform.prototype._read = function (n) { } }; Transform.prototype._destroy = function (err, cb) { - Duplex.prototype._destroy.call(this, err, err2 => { + Duplex.prototype._destroy.call(this, err, function (err2) { cb(err2); }); }; diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index feece0227..292415e23 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -38,10 +38,11 @@ function WriteReq(chunk, encoding, cb) { // It seems a linked list but it is not // there will be only 2 of these for each stream function CorkedRequest(state) { + var _this = this; this.next = null; this.entry = null; - this.finish = () => { - onCorkedFinish(this, state); + this.finish = function () { + onCorkedFinish(_this, state); }; } /* */ @@ -53,7 +54,7 @@ var Duplex; Writable.WritableState = WritableState; /**/ -const internalUtil = { +var internalUtil = { deprecate: require('util-deprecate') }; /**/ @@ -62,18 +63,18 @@ const internalUtil = { var Stream = require('./internal/streams/stream'); /**/ -const Buffer = require('buffer').Buffer; -const OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; +var Buffer = require('buffer').Buffer; +var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; function _uint8ArrayToBuffer(chunk) { return Buffer.from(chunk); } function _isUint8Array(obj) { return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; } -const destroyImpl = require('./internal/streams/destroy'); -const _require = require('./internal/streams/state'), +var destroyImpl = require('./internal/streams/destroy'); +var _require = require('./internal/streams/state'), getHighWaterMark = _require.getHighWaterMark; -const _require$codes = require('../errors').codes, +var _require$codes = require('../errors').codes, ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, @@ -82,7 +83,7 @@ const _require$codes = require('../errors').codes, ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES, ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END, ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING; -const errorOrDestroy = destroyImpl.errorOrDestroy; +var errorOrDestroy = destroyImpl.errorOrDestroy; require('inherits')(Writable, Stream); function nop() {} function WritableState(options, stream, isDuplex) { @@ -240,7 +241,7 @@ function Writable(options) { // Checking for a Stream.Duplex instance is faster here instead of inside // the WritableState constructor, at least with V8 6.5 - const isDuplex = this instanceof Duplex; + var isDuplex = this instanceof Duplex; if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options); this._writableState = new WritableState(options, this, isDuplex); @@ -364,9 +365,9 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { if (state.writing || state.corked) { var last = state.lastBufferedRequest; state.lastBufferedRequest = { - chunk, - encoding, - isBuf, + chunk: chunk, + encoding: encoding, + isBuf: isBuf, callback: cb, next: null }; @@ -539,7 +540,7 @@ Object.defineProperty(Writable.prototype, 'writableLength', { // because otherwise some prototype manipulation in // userland will fail enumerable: false, - get() { + get: function get() { return this._writableState.length; } }); @@ -547,7 +548,7 @@ function needFinish(state) { return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; } function callFinal(stream, state) { - stream._final(err => { + stream._final(function (err) { state.pendingcb--; if (err) { errorOrDestroy(stream, err); @@ -579,7 +580,7 @@ function finishMaybe(stream, state) { if (state.autoDestroy) { // In case of duplex streams we need a way to detect // if the readable side is ready for autoDestroy as well - const rState = stream._readableState; + var rState = stream._readableState; if (!rState || rState.autoDestroy && rState.endEmitted) { stream.destroy(); } @@ -615,13 +616,13 @@ Object.defineProperty(Writable.prototype, 'destroyed', { // because otherwise some prototype manipulation in // userland will fail enumerable: false, - get() { + get: function get() { if (this._writableState === undefined) { return false; } return this._writableState.destroyed; }, - set(value) { + set: function set(value) { // we ignore the value if the stream // has not been initialized yet if (!this._writableState) { diff --git a/lib/internal/streams/async_iterator.js b/lib/internal/streams/async_iterator.js index bcae6108c..742c5a467 100644 --- a/lib/internal/streams/async_iterator.js +++ b/lib/internal/streams/async_iterator.js @@ -1,23 +1,27 @@ 'use strict'; -const finished = require('./end-of-stream'); -const kLastResolve = Symbol('lastResolve'); -const kLastReject = Symbol('lastReject'); -const kError = Symbol('error'); -const kEnded = Symbol('ended'); -const kLastPromise = Symbol('lastPromise'); -const kHandlePromise = Symbol('handlePromise'); -const kStream = Symbol('stream'); +var _Object$setPrototypeO; +function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var finished = require('./end-of-stream'); +var kLastResolve = Symbol('lastResolve'); +var kLastReject = Symbol('lastReject'); +var kError = Symbol('error'); +var kEnded = Symbol('ended'); +var kLastPromise = Symbol('lastPromise'); +var kHandlePromise = Symbol('handlePromise'); +var kStream = Symbol('stream'); function createIterResult(value, done) { return { - value, - done + value: value, + done: done }; } function readAndResolve(iter) { - const resolve = iter[kLastResolve]; + var resolve = iter[kLastResolve]; if (resolve !== null) { - const data = iter[kStream].read(); + var data = iter[kStream].read(); // we defer if data is null // we can be expecting either 'end' or // 'error' @@ -35,8 +39,8 @@ function onReadable(iter) { process.nextTick(readAndResolve, iter); } function wrapForNext(lastPromise, iter) { - return (resolve, reject) => { - lastPromise.then(() => { + return function (resolve, reject) { + lastPromise.then(function () { if (iter[kEnded]) { resolve(createIterResult(undefined, true)); return; @@ -45,15 +49,16 @@ function wrapForNext(lastPromise, iter) { }, reject); }; } -const AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); -const ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf({ +var AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); +var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = { get stream() { return this[kStream]; }, - next() { + next: function next() { + var _this = this; // if we have detected an error in the meanwhile // reject straight away - const error = this[kError]; + var error = this[kError]; if (error !== null) { return Promise.reject(error); } @@ -65,10 +70,10 @@ const ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf({ // called, the error will be emitted via nextTick, and // we cannot guarantee that there is no error lingering around // waiting to be emitted. - return new Promise((resolve, reject) => { - process.nextTick(() => { - if (this[kError]) { - reject(this[kError]); + return new Promise(function (resolve, reject) { + process.nextTick(function () { + if (_this[kError]) { + reject(_this[kError]); } else { resolve(createIterResult(undefined, true)); } @@ -80,14 +85,14 @@ const ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf({ // we will wait for the previous Promise to finish // this logic is optimized to support for await loops, // where next() is only called once at a time - const lastPromise = this[kLastPromise]; - let promise; + var lastPromise = this[kLastPromise]; + var promise; if (lastPromise) { promise = new Promise(wrapForNext(lastPromise, this)); } else { // fast path needed to support multiple this.push() // without triggering the next() queue - const data = this[kStream].read(); + var data = this[kStream].read(); if (data !== null) { return Promise.resolve(createIterResult(data, false)); } @@ -95,70 +100,60 @@ const ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf({ } this[kLastPromise] = promise; return promise; - }, - [Symbol.asyncIterator]() { - return this; - }, - return() { - // destroy(err, cb) is a private API - // we can guarantee we have that here, because we control the - // Readable class this is attached to - return new Promise((resolve, reject) => { - this[kStream].destroy(null, err => { - if (err) { - reject(err); - return; - } - resolve(createIterResult(undefined, true)); - }); - }); } -}, AsyncIteratorPrototype); -const createReadableStreamAsyncIterator = stream => { - const iterator = Object.create(ReadableStreamAsyncIteratorPrototype, { - [kStream]: { - value: stream, - writable: true - }, - [kLastResolve]: { - value: null, - writable: true - }, - [kLastReject]: { - value: null, - writable: true - }, - [kError]: { - value: null, - writable: true - }, - [kEnded]: { - value: stream._readableState.endEmitted, - writable: true - }, - // the function passed to new Promise - // is cached so we avoid allocating a new - // closure at every run - [kHandlePromise]: { - value: (resolve, reject) => { - const data = iterator[kStream].read(); - if (data) { - iterator[kLastPromise] = null; - iterator[kLastResolve] = null; - iterator[kLastReject] = null; - resolve(createIterResult(data, false)); - } else { - iterator[kLastResolve] = resolve; - iterator[kLastReject] = reject; - } - }, - writable: true - } +}, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () { + return this; +}), _defineProperty(_Object$setPrototypeO, "return", function _return() { + var _this2 = this; + // destroy(err, cb) is a private API + // we can guarantee we have that here, because we control the + // Readable class this is attached to + return new Promise(function (resolve, reject) { + _this2[kStream].destroy(null, function (err) { + if (err) { + reject(err); + return; + } + resolve(createIterResult(undefined, true)); + }); }); +}), _Object$setPrototypeO), AsyncIteratorPrototype); +var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) { + var _Object$create; + var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, { + value: stream, + writable: true + }), _defineProperty(_Object$create, kLastResolve, { + value: null, + writable: true + }), _defineProperty(_Object$create, kLastReject, { + value: null, + writable: true + }), _defineProperty(_Object$create, kError, { + value: null, + writable: true + }), _defineProperty(_Object$create, kEnded, { + value: stream._readableState.endEmitted, + writable: true + }), _defineProperty(_Object$create, kHandlePromise, { + value: function value(resolve, reject) { + var data = iterator[kStream].read(); + if (data) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + resolve(createIterResult(data, false)); + } else { + iterator[kLastResolve] = resolve; + iterator[kLastReject] = reject; + } + }, + writable: true + }), _Object$create)); iterator[kLastPromise] = null; - finished(stream, err => { + finished(stream, function (err) { if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') { - const reject = iterator[kLastReject]; + var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise // returned by next() and store the error if (reject !== null) { @@ -170,7 +165,7 @@ const createReadableStreamAsyncIterator = stream => { iterator[kError] = err; return; } - const resolve = iterator[kLastResolve]; + var resolve = iterator[kLastResolve]; if (resolve !== null) { iterator[kLastPromise] = null; iterator[kLastResolve] = null; diff --git a/lib/internal/streams/buffer_list.js b/lib/internal/streams/buffer_list.js index 352ac3438..69bda497d 100644 --- a/lib/internal/streams/buffer_list.js +++ b/lib/internal/streams/buffer_list.js @@ -3,153 +3,181 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } -const _require = require('buffer'), +var _require = require('buffer'), Buffer = _require.Buffer; -const _require2 = require('util'), +var _require2 = require('util'), inspect = _require2.inspect; -const custom = inspect && inspect.custom || 'inspect'; +var custom = inspect && inspect.custom || 'inspect'; function copyBuffer(src, target, offset) { Buffer.prototype.copy.call(src, target, offset); } -module.exports = class BufferList { - constructor() { +module.exports = /*#__PURE__*/function () { + function BufferList() { + _classCallCheck(this, BufferList); this.head = null; this.tail = null; this.length = 0; } - push(v) { - const entry = { - data: v, - next: null - }; - if (this.length > 0) this.tail.next = entry;else this.head = entry; - this.tail = entry; - ++this.length; - } - unshift(v) { - const entry = { - data: v, - next: this.head - }; - if (this.length === 0) this.tail = entry; - this.head = entry; - ++this.length; - } - shift() { - if (this.length === 0) return; - const ret = this.head.data; - if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; - --this.length; - return ret; - } - clear() { - this.head = this.tail = null; - this.length = 0; - } - join(s) { - if (this.length === 0) return ''; - var p = this.head; - var ret = '' + p.data; - while (p = p.next) ret += s + p.data; - return ret; - } - concat(n) { - if (this.length === 0) return Buffer.alloc(0); - const ret = Buffer.allocUnsafe(n >>> 0); - var p = this.head; - var i = 0; - while (p) { - copyBuffer(p.data, ret, i); - i += p.data.length; - p = p.next; + _createClass(BufferList, [{ + key: "push", + value: function push(v) { + var entry = { + data: v, + next: null + }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; + } + }, { + key: "unshift", + value: function unshift(v) { + var entry = { + data: v, + next: this.head + }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; + } + }, { + key: "shift", + value: function shift() { + if (this.length === 0) return; + var ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; + } + }, { + key: "clear", + value: function clear() { + this.head = this.tail = null; + this.length = 0; + } + }, { + key: "join", + value: function join(s) { + if (this.length === 0) return ''; + var p = this.head; + var ret = '' + p.data; + while (p = p.next) ret += s + p.data; + return ret; + } + }, { + key: "concat", + value: function concat(n) { + if (this.length === 0) return Buffer.alloc(0); + var ret = Buffer.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + while (p) { + copyBuffer(p.data, ret, i); + i += p.data.length; + p = p.next; + } + return ret; } - return ret; - } - // Consumes a specified amount of bytes or characters from the buffered data. - consume(n, hasStrings) { - var ret; - if (n < this.head.data.length) { - // `slice` is the same for buffers and strings. - ret = this.head.data.slice(0, n); - this.head.data = this.head.data.slice(n); - } else if (n === this.head.data.length) { - // First chunk is a perfect match. - ret = this.shift(); - } else { - // Result spans more than one buffer. - ret = hasStrings ? this._getString(n) : this._getBuffer(n); + // Consumes a specified amount of bytes or characters from the buffered data. + }, { + key: "consume", + value: function consume(n, hasStrings) { + var ret; + if (n < this.head.data.length) { + // `slice` is the same for buffers and strings. + ret = this.head.data.slice(0, n); + this.head.data = this.head.data.slice(n); + } else if (n === this.head.data.length) { + // First chunk is a perfect match. + ret = this.shift(); + } else { + // Result spans more than one buffer. + ret = hasStrings ? this._getString(n) : this._getBuffer(n); + } + return ret; + } + }, { + key: "first", + value: function first() { + return this.head.data; } - return ret; - } - first() { - return this.head.data; - } - // Consumes a specified amount of characters from the buffered data. - _getString(n) { - var p = this.head; - var c = 1; - var ret = p.data; - n -= ret.length; - while (p = p.next) { - const str = p.data; - const nb = n > str.length ? str.length : n; - if (nb === str.length) ret += str;else ret += str.slice(0, n); - n -= nb; - if (n === 0) { - if (nb === str.length) { - ++c; - if (p.next) this.head = p.next;else this.head = this.tail = null; - } else { - this.head = p; - p.data = str.slice(nb); + // Consumes a specified amount of characters from the buffered data. + }, { + key: "_getString", + value: function _getString(n) { + var p = this.head; + var c = 1; + var ret = p.data; + n -= ret.length; + while (p = p.next) { + var str = p.data; + var nb = n > str.length ? str.length : n; + if (nb === str.length) ret += str;else ret += str.slice(0, n); + n -= nb; + if (n === 0) { + if (nb === str.length) { + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + this.head = p; + p.data = str.slice(nb); + } + break; } - break; + ++c; } - ++c; + this.length -= c; + return ret; } - this.length -= c; - return ret; - } - // Consumes a specified amount of bytes from the buffered data. - _getBuffer(n) { - const ret = Buffer.allocUnsafe(n); - var p = this.head; - var c = 1; - p.data.copy(ret); - n -= p.data.length; - while (p = p.next) { - const buf = p.data; - const nb = n > buf.length ? buf.length : n; - buf.copy(ret, ret.length - n, 0, nb); - n -= nb; - if (n === 0) { - if (nb === buf.length) { - ++c; - if (p.next) this.head = p.next;else this.head = this.tail = null; - } else { - this.head = p; - p.data = buf.slice(nb); + // Consumes a specified amount of bytes from the buffered data. + }, { + key: "_getBuffer", + value: function _getBuffer(n) { + var ret = Buffer.allocUnsafe(n); + var p = this.head; + var c = 1; + p.data.copy(ret); + n -= p.data.length; + while (p = p.next) { + var buf = p.data; + var nb = n > buf.length ? buf.length : n; + buf.copy(ret, ret.length - n, 0, nb); + n -= nb; + if (n === 0) { + if (nb === buf.length) { + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + this.head = p; + p.data = buf.slice(nb); + } + break; } - break; + ++c; } - ++c; + this.length -= c; + return ret; } - this.length -= c; - return ret; - } - // Make sure the linked list only shows the minimal necessary information. - [custom](_, options) { - return inspect(this, _objectSpread(_objectSpread({}, options), {}, { - // Only inspect one level. - depth: 0, - // It should not recurse. - customInspect: false - })); - } -}; \ No newline at end of file + // Make sure the linked list only shows the minimal necessary information. + }, { + key: custom, + value: function value(_, options) { + return inspect(this, _objectSpread(_objectSpread({}, options), {}, { + // Only inspect one level. + depth: 0, + // It should not recurse. + customInspect: false + })); + } + }]); + return BufferList; +}(); \ No newline at end of file diff --git a/lib/internal/streams/destroy.js b/lib/internal/streams/destroy.js index 7e8275567..31a17c4dc 100644 --- a/lib/internal/streams/destroy.js +++ b/lib/internal/streams/destroy.js @@ -2,8 +2,9 @@ // undocumented cb() API, needed for core, not for public API function destroy(err, cb) { - const readableDestroyed = this._readableState && this._readableState.destroyed; - const writableDestroyed = this._writableState && this._writableState.destroyed; + var _this = this; + var readableDestroyed = this._readableState && this._readableState.destroyed; + var writableDestroyed = this._writableState && this._writableState.destroyed; if (readableDestroyed || writableDestroyed) { if (cb) { cb(err); @@ -29,21 +30,21 @@ function destroy(err, cb) { if (this._writableState) { this._writableState.destroyed = true; } - this._destroy(err || null, err => { + this._destroy(err || null, function (err) { if (!cb && err) { - if (!this._writableState) { - process.nextTick(emitErrorAndCloseNT, this, err); - } else if (!this._writableState.errorEmitted) { - this._writableState.errorEmitted = true; - process.nextTick(emitErrorAndCloseNT, this, err); + if (!_this._writableState) { + process.nextTick(emitErrorAndCloseNT, _this, err); + } else if (!_this._writableState.errorEmitted) { + _this._writableState.errorEmitted = true; + process.nextTick(emitErrorAndCloseNT, _this, err); } else { - process.nextTick(emitCloseNT, this); + process.nextTick(emitCloseNT, _this); } } else if (cb) { - process.nextTick(emitCloseNT, this); + process.nextTick(emitCloseNT, _this); cb(err); } else { - process.nextTick(emitCloseNT, this); + process.nextTick(emitCloseNT, _this); } }); return this; @@ -84,12 +85,12 @@ function errorOrDestroy(stream, err) { // the error to be emitted nextTick. In a future // semver major update we should change the default to this. - const rState = stream._readableState; - const wState = stream._writableState; + var rState = stream._readableState; + var wState = stream._writableState; if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err); } module.exports = { - destroy, - undestroy, - errorOrDestroy + destroy: destroy, + undestroy: undestroy, + errorOrDestroy: errorOrDestroy }; \ No newline at end of file diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index b6d101691..59c671b5a 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -3,9 +3,9 @@ 'use strict'; -const ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE; +var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE; function once(callback) { - let called = false; + var called = false; return function () { if (called) return; called = true; @@ -23,28 +23,28 @@ function eos(stream, opts, callback) { if (typeof opts === 'function') return eos(stream, null, opts); if (!opts) opts = {}; callback = once(callback || noop); - let readable = opts.readable || opts.readable !== false && stream.readable; - let writable = opts.writable || opts.writable !== false && stream.writable; - const onlegacyfinish = () => { + var readable = opts.readable || opts.readable !== false && stream.readable; + var writable = opts.writable || opts.writable !== false && stream.writable; + var onlegacyfinish = function onlegacyfinish() { if (!stream.writable) onfinish(); }; var writableEnded = stream._writableState && stream._writableState.finished; - const onfinish = () => { + var onfinish = function onfinish() { writable = false; writableEnded = true; if (!readable) callback.call(stream); }; var readableEnded = stream._readableState && stream._readableState.endEmitted; - const onend = () => { + var onend = function onend() { readable = false; readableEnded = true; if (!writable) callback.call(stream); }; - const onerror = err => { + var onerror = function onerror(err) { callback.call(stream, err); }; - const onclose = () => { - let err; + var onclose = function onclose() { + var err; if (readable && !readableEnded) { if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); return callback.call(stream, err); @@ -54,7 +54,7 @@ function eos(stream, opts, callback) { return callback.call(stream, err); } }; - const onrequest = () => { + var onrequest = function onrequest() { stream.req.on('finish', onfinish); }; if (isRequest(stream)) { diff --git a/lib/internal/streams/from.js b/lib/internal/streams/from.js index 4ca2cd199..0a34ee92e 100644 --- a/lib/internal/streams/from.js +++ b/lib/internal/streams/from.js @@ -7,18 +7,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } -const ERR_INVALID_ARG_TYPE = require('../../../errors').codes.ERR_INVALID_ARG_TYPE; +var ERR_INVALID_ARG_TYPE = require('../../../errors').codes.ERR_INVALID_ARG_TYPE; function from(Readable, iterable, opts) { - let iterator; + var iterator; if (iterable && typeof iterable.next === 'function') { iterator = iterable; } else if (iterable && iterable[Symbol.asyncIterator]) iterator = iterable[Symbol.asyncIterator]();else if (iterable && iterable[Symbol.iterator]) iterator = iterable[Symbol.iterator]();else throw new ERR_INVALID_ARG_TYPE('iterable', ['Iterable'], iterable); - const readable = new Readable(_objectSpread({ + var readable = new Readable(_objectSpread({ objectMode: true }, opts)); // Reading boolean to protect against _read // being called before last iteration completion. - let reading = false; + var reading = false; readable._read = function () { if (!reading) { reading = true; @@ -31,7 +31,7 @@ function from(Readable, iterable, opts) { function _next2() { _next2 = _asyncToGenerator(function* () { try { - const _yield$iterator$next = yield iterator.next(), + var _yield$iterator$next = yield iterator.next(), value = _yield$iterator$next.value, done = _yield$iterator$next.done; if (done) { @@ -49,4 +49,4 @@ function from(Readable, iterable, opts) { } return readable; } -module.exports = from; \ No newline at end of file +module.exports = from; diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 272546db8..e6f39241f 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -3,16 +3,16 @@ 'use strict'; -let eos; +var eos; function once(callback) { - let called = false; + var called = false; return function () { if (called) return; called = true; - callback(...arguments); + callback.apply(void 0, arguments); }; } -const _require$codes = require('../../../errors').codes, +var _require$codes = require('../../../errors').codes, ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS, ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED; function noop(err) { @@ -24,21 +24,21 @@ function isRequest(stream) { } function destroyer(stream, reading, writing, callback) { callback = once(callback); - let closed = false; - stream.on('close', () => { + var closed = false; + stream.on('close', function () { closed = true; }); if (eos === undefined) eos = require('./end-of-stream'); eos(stream, { readable: reading, writable: writing - }, err => { + }, function (err) { if (err) return callback(err); closed = true; callback(); }); - let destroyed = false; - return err => { + var destroyed = false; + return function (err) { if (closed) return; if (destroyed) return; destroyed = true; @@ -64,15 +64,15 @@ function pipeline() { for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) { streams[_key] = arguments[_key]; } - const callback = popCallback(streams); + var callback = popCallback(streams); if (Array.isArray(streams[0])) streams = streams[0]; if (streams.length < 2) { throw new ERR_MISSING_ARGS('streams'); } - let error; - const destroys = streams.map(function (stream, i) { - const reading = i < streams.length - 1; - const writing = i > 0; + var error; + var destroys = streams.map(function (stream, i) { + var reading = i < streams.length - 1; + var writing = i > 0; return destroyer(stream, reading, writing, function (err) { if (!error) error = err; if (err) destroys.forEach(call); diff --git a/lib/internal/streams/state.js b/lib/internal/streams/state.js index 8a994b442..3fbf8927e 100644 --- a/lib/internal/streams/state.js +++ b/lib/internal/streams/state.js @@ -1,14 +1,14 @@ 'use strict'; -const ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE; +var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE; function highWaterMarkFrom(options, isDuplex, duplexKey) { return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null; } function getHighWaterMark(state, options, duplexKey, isDuplex) { - const hwm = highWaterMarkFrom(options, isDuplex, duplexKey); + var hwm = highWaterMarkFrom(options, isDuplex, duplexKey); if (hwm != null) { if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) { - const name = isDuplex ? duplexKey : 'highWaterMark'; + var name = isDuplex ? duplexKey : 'highWaterMark'; throw new ERR_INVALID_OPT_VALUE(name, hwm); } return Math.floor(hwm); @@ -18,5 +18,5 @@ function getHighWaterMark(state, options, duplexKey, isDuplex) { return state.objectMode ? 16 : 16 * 1024; } module.exports = { - getHighWaterMark + getHighWaterMark: getHighWaterMark }; \ No newline at end of file diff --git a/test/common/arraystream.js b/test/common/arraystream.js index 3f02b0dc5..3734c1720 100644 --- a/test/common/arraystream.js +++ b/test/common/arraystream.js @@ -15,15 +15,16 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const _require = require('../../'), +var _require = require('../../'), Stream = _require.Stream; function noop() {} // A stream to push an array into a REPL function ArrayStream() { this.run = function (data) { - forEach(data, line => { - this.emit('data', `${line}\n`); + var _this = this; + forEach(data, function (line) { + _this.emit('data', "".concat(line, "\n")); }); }; } diff --git a/test/common/benchmark.js b/test/common/benchmark.js index c9455213f..2ab30d952 100644 --- a/test/common/benchmark.js +++ b/test/common/benchmark.js @@ -16,28 +16,28 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const assert = require('assert'); -const fork = require('child_process').fork; -const path = require('path'); -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); +var assert = require('assert'); +var fork = require('child_process').fork; +var path = require('path'); +var runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); function runBenchmark(name, args, env) { - const argv = []; - for (let i = 0; i < args.length; i++) { + var argv = []; + for (var _i = 0; _i < args.length; _i++) { argv.push('--set'); - argv.push(args[i]); + argv.push(args[_i]); } argv.push(name); - const mergedEnv = Object.assign({}, process.env, env); - const child = fork(runjs, argv, { + var mergedEnv = Object.assign({}, process.env, env); + var child = fork(runjs, argv, { env: mergedEnv, stdio: ['inherit', 'pipe', 'inherit', 'ipc'] }); child.stdout.setEncoding('utf8'); - let stdout = ''; - child.stdout.on('data', line => { + var stdout = ''; + child.stdout.on('data', function (line) { stdout += line; }); - child.on('exit', (code, signal) => { + child.on('exit', function (code, signal) { assert.strictEqual(code, 0); assert.strictEqual(signal, null); // This bit makes sure that each benchmark file is being sent settings such @@ -46,7 +46,7 @@ function runBenchmark(name, args, env) { // file should result in three lines of output: a blank line, a line with // the name of the benchmark file, and a line with the only results that we // get from testing the benchmark file. - assert.ok(/^(?:\n.+?\n.+?\n)+$/.test(stdout), `benchmark file not running exactly one configuration in test: ${stdout}`); + assert.ok(/^(?:\n.+?\n.+?\n)+$/.test(stdout), "benchmark file not running exactly one configuration in test: ".concat(stdout)); }); } module.exports = runBenchmark; diff --git a/test/common/countdown.js b/test/common/countdown.js index 502f4d9a5..dd1d92fb9 100644 --- a/test/common/countdown.js +++ b/test/common/countdown.js @@ -1,5 +1,10 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**/ require('@babel/polyfill'); var util = require('util'); @@ -16,26 +21,33 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const assert = require('assert'); -const kLimit = Symbol('limit'); -const kCallback = Symbol('callback'); -const common = require('./'); -class Countdown { - constructor(limit, cb) { +var assert = require('assert'); +var kLimit = Symbol('limit'); +var kCallback = Symbol('callback'); +var common = require('./'); +var Countdown = /*#__PURE__*/function () { + function Countdown(limit, cb) { + _classCallCheck(this, Countdown); assert.strictEqual(typeof limit, 'number'); assert.strictEqual(typeof cb, 'function'); this[kLimit] = limit; this[kCallback] = common.mustCall(cb); } - dec() { - assert(this[kLimit] > 0, 'Countdown expired'); - if (--this[kLimit] === 0) this[kCallback](); - return this[kLimit]; - } - get remaining() { - return this[kLimit]; - } -} + _createClass(Countdown, [{ + key: "dec", + value: function dec() { + assert(this[kLimit] > 0, 'Countdown expired'); + if (--this[kLimit] === 0) this[kCallback](); + return this[kLimit]; + } + }, { + key: "remaining", + get: function get() { + return this[kLimit]; + } + }]); + return Countdown; +}(); module.exports = Countdown; function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { diff --git a/test/common/dns.js b/test/common/dns.js index 8e4fc3c43..581b7a1bb 100644 --- a/test/common/dns.js +++ b/test/common/dns.js @@ -22,9 +22,9 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const assert = require('assert'); -const os = require('os'); -const types = { +var assert = require('assert'); +var os = require('os'); +var types = { A: 1, AAAA: 28, NS: 2, @@ -35,7 +35,7 @@ const types = { TXT: 16, ANY: 255 }; -const classes = { +var classes = { IN: 1 }; @@ -43,7 +43,7 @@ const classes = { function readDomainFromPacket(buffer, offset) { assert.ok(offset < buffer.length); - const length = buffer[offset]; + var length = buffer[offset]; if (length === 0) { return { nread: 1, @@ -51,20 +51,20 @@ function readDomainFromPacket(buffer, offset) { }; } else if ((length & 0xC0) === 0) { offset += 1; - const chunk = buffer.toString('ascii', offset, offset + length); + var chunk = buffer.toString('ascii', offset, offset + length); // Read the rest of the domain. - const _readDomainFromPacket = readDomainFromPacket(buffer, offset + length), + var _readDomainFromPacket = readDomainFromPacket(buffer, offset + length), nread = _readDomainFromPacket.nread, domain = _readDomainFromPacket.domain; return { nread: 1 + length + nread, - domain: domain ? `${chunk}.${domain}` : chunk + domain: domain ? "".concat(chunk, ".").concat(domain) : chunk }; } else { // Pointer to another part of the packet. assert.strictEqual(length & 0xC0, 0xC0); // eslint-disable-next-line space-infix-ops, space-unary-ops - const pointeeOffset = buffer.readUInt16BE(offset) & ~0xC000; + var pointeeOffset = buffer.readUInt16BE(offset) & ~0xC000; return { nread: 2, domain: readDomainFromPacket(buffer, pointeeOffset) @@ -73,39 +73,39 @@ function readDomainFromPacket(buffer, offset) { } function parseDNSPacket(buffer) { assert.ok(buffer.length > 12); - const parsed = { + var parsed = { id: buffer.readUInt16BE(0), flags: buffer.readUInt16BE(2) }; - const counts = [['questions', buffer.readUInt16BE(4)], ['answers', buffer.readUInt16BE(6)], ['authorityAnswers', buffer.readUInt16BE(8)], ['additionalRecords', buffer.readUInt16BE(10)]]; - let offset = 12; + var counts = [['questions', buffer.readUInt16BE(4)], ['answers', buffer.readUInt16BE(6)], ['authorityAnswers', buffer.readUInt16BE(8)], ['additionalRecords', buffer.readUInt16BE(10)]]; + var offset = 12; for (var _i = 0, _counts = counts; _i < _counts.length; _i++) { - const _counts$_i = _slicedToArray(_counts[_i], 2), + var _counts$_i = _slicedToArray(_counts[_i], 2), sectionName = _counts$_i[0], count = _counts$_i[1]; parsed[sectionName] = []; - for (let i = 0; i < count; ++i) { - const _readDomainFromPacket2 = readDomainFromPacket(buffer, offset), + for (var _i2 = 0; _i2 < count; ++_i2) { + var _readDomainFromPacket2 = readDomainFromPacket(buffer, offset), nread = _readDomainFromPacket2.nread, domain = _readDomainFromPacket2.domain; offset += nread; - const type = buffer.readUInt16BE(offset); - const rr = { - domain, + var type = buffer.readUInt16BE(offset); + var rr = { + domain: domain, cls: buffer.readUInt16BE(offset + 2) }; offset += 4; - for (const name in types) { + for (var name in types) { if (types[name] === type) rr.type = name; } if (sectionName !== 'questions') { rr.ttl = buffer.readInt32BE(offset); - const dataLength = buffer.readUInt16BE(offset); + var dataLength = buffer.readUInt16BE(offset); offset += 6; switch (type) { case types.A: assert.strictEqual(dataLength, 4); - rr.address = `${buffer[offset + 0]}.${buffer[offset + 1]}.` + `${buffer[offset + 2]}.${buffer[offset + 3]}`; + rr.address = "".concat(buffer[offset + 0], ".").concat(buffer[offset + 1], ".") + "".concat(buffer[offset + 2], ".").concat(buffer[offset + 3]); break; case types.AAAA: assert.strictEqual(dataLength, 16); @@ -113,10 +113,10 @@ function parseDNSPacket(buffer) { break; case types.TXT: { - let position = offset; + var position = offset; rr.entries = []; while (position < offset + dataLength) { - const txtLength = buffer[offset]; + var txtLength = buffer[offset]; rr.entries.push(buffer.toString('utf8', position + 1, position + 1 + txtLength)); position += 1 + txtLength; } @@ -127,31 +127,31 @@ function parseDNSPacket(buffer) { { rr.priority = buffer.readInt16BE(buffer, offset); offset += 2; - const _readDomainFromPacket3 = readDomainFromPacket(buffer, offset), - nread = _readDomainFromPacket3.nread, - domain = _readDomainFromPacket3.domain; - rr.exchange = domain; - assert.strictEqual(nread, dataLength); + var _readDomainFromPacket3 = readDomainFromPacket(buffer, offset), + _nread = _readDomainFromPacket3.nread, + _domain = _readDomainFromPacket3.domain; + rr.exchange = _domain; + assert.strictEqual(_nread, dataLength); break; } case types.NS: case types.CNAME: case types.PTR: { - const _readDomainFromPacket4 = readDomainFromPacket(buffer, offset), - nread = _readDomainFromPacket4.nread, - domain = _readDomainFromPacket4.domain; - rr.value = domain; - assert.strictEqual(nread, dataLength); + var _readDomainFromPacket4 = readDomainFromPacket(buffer, offset), + _nread2 = _readDomainFromPacket4.nread, + _domain2 = _readDomainFromPacket4.domain; + rr.value = _domain2; + assert.strictEqual(_nread2, dataLength); break; } case types.SOA: { - const mname = readDomainFromPacket(buffer, offset); - const rname = readDomainFromPacket(buffer, offset + mname.nread); + var mname = readDomainFromPacket(buffer, offset); + var rname = readDomainFromPacket(buffer, offset + mname.nread); rr.nsname = mname.domain; rr.hostmaster = rname.domain; - const trailerOffset = offset + mname.nread + rname.nread; + var trailerOffset = offset + mname.nread + rname.nread; rr.serial = buffer.readUInt32BE(trailerOffset); rr.refresh = buffer.readUInt32BE(trailerOffset + 4); rr.retry = buffer.readUInt32BE(trailerOffset + 8); @@ -161,7 +161,7 @@ function parseDNSPacket(buffer) { break; } default: - throw new Error(`Unknown RR type ${rr.type}`); + throw new Error("Unknown RR type ".concat(rr.type)); } offset += dataLength; } @@ -173,14 +173,14 @@ function parseDNSPacket(buffer) { return parsed; } function writeIPv6(ip) { - const parts = ip.replace(/^:|:$/g, '').split(':'); - const buf = Buffer.alloc(16); - let offset = 0; + var parts = ip.replace(/^:|:$/g, '').split(':'); + var buf = Buffer.alloc(16); + var offset = 0; var _iterator = _createForOfIteratorHelper(parts), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { - const part = _step.value; + var part = _step.value; if (part === '') { offset += 16 - 2 * (parts.length - 1); } else { @@ -196,20 +196,20 @@ function writeIPv6(ip) { return buf; } function writeDomainName(domain) { - return Buffer.concat(domain.split('.').map(label => { + return Buffer.concat(domain.split('.').map(function (label) { assert(label.length < 64); return Buffer.concat([Buffer.from([label.length]), Buffer.from(label, 'ascii')]); }).concat([Buffer.alloc(1)])); } function writeDNSPacket(parsed) { - const buffers = []; - const kStandardResponseFlags = 0x8180; + var buffers = []; + var kStandardResponseFlags = 0x8180; buffers.push(new Uint16Array([parsed.id, parsed.flags === undefined ? kStandardResponseFlags : parsed.flags, parsed.questions && parsed.questions.length, parsed.answers && parsed.answers.length, parsed.authorityAnswers && parsed.authorityAnswers.length, parsed.additionalRecords && parsed.additionalRecords.length])); var _iterator2 = _createForOfIteratorHelper(parsed.questions), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - const q = _step2.value; + var q = _step2.value; assert(types[q.type]); buffers.push(writeDomainName(q.domain)); buffers.push(new Uint16Array([types[q.type], q.cls === undefined ? classes.IN : q.cls])); @@ -223,13 +223,13 @@ function writeDNSPacket(parsed) { _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - const rr = _step3.value; + var rr = _step3.value; if (!rr) continue; assert(types[rr.type]); buffers.push(writeDomainName(rr.domain)); buffers.push(new Uint16Array([types[rr.type], rr.cls === undefined ? classes.IN : rr.cls])); buffers.push(new Int32Array([rr.ttl])); - const rdLengthBuf = new Uint16Array(1); + var rdLengthBuf = new Uint16Array(1); buffers.push(rdLengthBuf); switch (rr.type) { case 'A': @@ -241,14 +241,18 @@ function writeDNSPacket(parsed) { buffers.push(writeIPv6(rr.address)); break; case 'TXT': - const total = rr.entries.map(s => s.length).reduce((a, b) => a + b); + var total = rr.entries.map(function (s) { + return s.length; + }).reduce(function (a, b) { + return a + b; + }); // Total length of all strings + 1 byte each for their lengths. rdLengthBuf[0] = rr.entries.length + total; var _iterator4 = _createForOfIteratorHelper(rr.entries), _step4; try { for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - const txt = _step4.value; + var txt = _step4.value; buffers.push(new Uint8Array([Buffer.byteLength(txt)])); buffers.push(Buffer.from(txt)); } @@ -266,22 +270,22 @@ function writeDNSPacket(parsed) { case 'CNAME': case 'PTR': { - const domain = writeDomainName(rr.exchange || rr.value); + var domain = writeDomainName(rr.exchange || rr.value); rdLengthBuf[0] += domain.length; buffers.push(domain); break; } case 'SOA': { - const mname = writeDomainName(rr.nsname); - const rname = writeDomainName(rr.hostmaster); + var mname = writeDomainName(rr.nsname); + var rname = writeDomainName(rr.hostmaster); rdLengthBuf[0] = mname.length + rname.length + 20; buffers.push(mname, rname); buffers.push(new Uint32Array([rr.serial, rr.refresh, rr.retry, rr.expire, rr.minttl])); break; } default: - throw new Error(`Unknown RR type ${rr.type}`); + throw new Error("Unknown RR type ".concat(rr.type)); } } } catch (err) { @@ -289,8 +293,8 @@ function writeDNSPacket(parsed) { } finally { _iterator3.f(); } - return Buffer.concat(buffers.map(typedArray => { - const buf = Buffer.from(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); + return Buffer.concat(buffers.map(function (typedArray) { + var buf = Buffer.from(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); if (os.endianness() === 'LE') { if (typedArray.BYTES_PER_ELEMENT === 2) buf.swap16(); if (typedArray.BYTES_PER_ELEMENT === 4) buf.swap32(); @@ -298,13 +302,13 @@ function writeDNSPacket(parsed) { return buf; })); } -const mockedErrorCode = 'ENOTFOUND'; -const mockedSysCall = 'getaddrinfo'; +var mockedErrorCode = 'ENOTFOUND'; +var mockedSysCall = 'getaddrinfo'; function errorLookupMock() { - let code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : mockedErrorCode; - let syscall = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mockedSysCall; + var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : mockedErrorCode; + var syscall = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mockedSysCall; return function lookupWithError(hostname, dnsopts, cb) { - const err = new Error(`${syscall} ${code} ${hostname}`); + var err = new Error("".concat(syscall, " ").concat(code, " ").concat(hostname)); err.code = code; err.errno = code; err.syscall = syscall; @@ -313,13 +317,13 @@ function errorLookupMock() { }; } module.exports = { - types, - classes, - writeDNSPacket, - parseDNSPacket, - errorLookupMock, - mockedErrorCode, - mockedSysCall + types: types, + classes: classes, + writeDNSPacket: writeDNSPacket, + parseDNSPacket: parseDNSPacket, + errorLookupMock: errorLookupMock, + mockedErrorCode: mockedErrorCode, + mockedSysCall: mockedSysCall }; function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { diff --git a/test/common/duplexpair.js b/test/common/duplexpair.js index 05e3bc107..0fe421c58 100644 --- a/test/common/duplexpair.js +++ b/test/common/duplexpair.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**/ require('@babel/polyfill'); var util = require('util'); @@ -15,43 +27,56 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const _require = require('../../'), +var _require = require('../../'), Duplex = _require.Duplex; -const assert = require('assert'); -const kCallback = Symbol('Callback'); -const kOtherSide = Symbol('Other'); -class DuplexSocket extends Duplex { - constructor() { - super(); - this[kCallback] = null; - this[kOtherSide] = null; +var assert = require('assert'); +var kCallback = Symbol('Callback'); +var kOtherSide = Symbol('Other'); +var DuplexSocket = /*#__PURE__*/function (_Duplex) { + _inherits(DuplexSocket, _Duplex); + var _super = _createSuper(DuplexSocket); + function DuplexSocket() { + var _this; + _classCallCheck(this, DuplexSocket); + _this = _super.call(this); + _this[kCallback] = null; + _this[kOtherSide] = null; + return _this; } - _read() { - const callback = this[kCallback]; - if (callback) { - this[kCallback] = null; - callback(); + _createClass(DuplexSocket, [{ + key: "_read", + value: function _read() { + var callback = this[kCallback]; + if (callback) { + this[kCallback] = null; + callback(); + } } - } - _write(chunk, encoding, callback) { - assert.notStrictEqual(this[kOtherSide], null); - assert.strictEqual(this[kOtherSide][kCallback], null); - this[kOtherSide][kCallback] = callback; - this[kOtherSide].push(chunk); - } - _final(callback) { - this[kOtherSide].on('end', callback); - this[kOtherSide].push(null); - } -} + }, { + key: "_write", + value: function _write(chunk, encoding, callback) { + assert.notStrictEqual(this[kOtherSide], null); + assert.strictEqual(this[kOtherSide][kCallback], null); + this[kOtherSide][kCallback] = callback; + this[kOtherSide].push(chunk); + } + }, { + key: "_final", + value: function _final(callback) { + this[kOtherSide].on('end', callback); + this[kOtherSide].push(null); + } + }]); + return DuplexSocket; +}(Duplex); function makeDuplexPair() { - const clientSide = new DuplexSocket(); - const serverSide = new DuplexSocket(); + var clientSide = new DuplexSocket(); + var serverSide = new DuplexSocket(); clientSide[kOtherSide] = serverSide; serverSide[kOtherSide] = clientSide; return { - clientSide, - serverSide + clientSide: clientSide, + serverSide: serverSide }; } module.exports = makeDuplexPair; diff --git a/test/common/fixtures.js b/test/common/fixtures.js index 017197f0c..57cd3075d 100644 --- a/test/common/fixtures.js +++ b/test/common/fixtures.js @@ -1,5 +1,11 @@ "use strict"; +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /**/ require('@babel/polyfill'); var util = require('util'); @@ -15,24 +21,24 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const path = require('path'); -const fs = require('fs'); -const fixturesDir = path.join(__dirname, '..', 'fixtures'); +var path = require('path'); +var fs = require('fs'); +var fixturesDir = path.join(__dirname, '..', 'fixtures'); function fixturesPath() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } - return path.join(fixturesDir, ...args); + return path.join.apply(path, [fixturesDir].concat(args)); } function readFixtureSync(args, enc) { - if (Array.isArray(args)) return fs.readFileSync(fixturesPath(...args), enc); + if (Array.isArray(args)) return fs.readFileSync(fixturesPath.apply(void 0, _toConsumableArray(args)), enc); return fs.readFileSync(fixturesPath(args), enc); } function readFixtureKey(name, enc) { return fs.readFileSync(fixturesPath('keys', name), enc); } module.exports = { - fixturesDir, + fixturesDir: fixturesDir, path: fixturesPath, readSync: readFixtureSync, readKey: readFixtureKey diff --git a/test/common/heap.js b/test/common/heap.js index 9c4e27f48..8d1c2dfb1 100644 --- a/test/common/heap.js +++ b/test/common/heap.js @@ -3,6 +3,11 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**/ require('@babel/polyfill'); var util = require('util'); @@ -18,21 +23,21 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const assert = require('assert'); +var assert = require('assert'); /**/ var util = require('core-util-is'); util.inherits = require('inherits'); /**/ -let internalTestHeap; +var internalTestHeap; try { internalTestHeap = require('internal/test/heap'); } catch (e) { console.log('using `test/common/heap.js` requires `--expose-internals`'); throw e; } -const _internalTestHeap = internalTestHeap, +var _internalTestHeap = internalTestHeap, createJSHeapDump = _internalTestHeap.createJSHeapDump, buildEmbedderGraph = _internalTestHeap.buildEmbedderGraph; function inspectNode(snapshot) { @@ -41,7 +46,7 @@ function inspectNode(snapshot) { }); } function isEdge(edge, _ref) { - let node_name = _ref.node_name, + var node_name = _ref.node_name, edge_name = _ref.edge_name; // For ABI compatibility, we did not backport the virtual function // AddEdge() with a name as last argument back to v10.x, so edge_name. @@ -59,122 +64,150 @@ function isEdge(edge, _ref) { } return true; } -class State { - constructor() { +var State = /*#__PURE__*/function () { + function State() { + _classCallCheck(this, State); this.snapshot = createJSHeapDump(); this.embedderGraph = buildEmbedderGraph(); } // Validate the v8 heap snapshot - validateSnapshot(rootName, expected) { - let _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - _ref2$loose = _ref2.loose, - loose = _ref2$loose === void 0 ? false : _ref2$loose; - const rootNodes = this.snapshot.filter(node => node.name === rootName && node.type !== 'string'); - if (loose) { - assert(rootNodes.length >= expected.length, `Expect to find at least ${expected.length} '${rootName}', ` + `found ${rootNodes.length}`); - } else { - assert.strictEqual(rootNodes.length, expected.length, `Expect to find ${expected.length} '${rootName}', ` + `found ${rootNodes.length}`); - } - var _iterator = _createForOfIteratorHelper(expected), - _step; - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - const expectation = _step.value; - if (expectation.children) { - var _iterator2 = _createForOfIteratorHelper(expectation.children), - _step2; - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - const expectedEdge = _step2.value; - const check = typeof expectedEdge === 'function' ? expectedEdge : edge => isEdge(edge, expectedEdge); - const hasChild = rootNodes.some(node => node.outgoingEdges.some(check)); - // Don't use assert with a custom message here. Otherwise the - // inspection in the message is done eagerly and wastes a lot of CPU - // time. - if (!hasChild) { - throw new Error('expected to find child ' + `${util.inspect(expectedEdge)} in ${inspectNode(rootNodes)}`); + _createClass(State, [{ + key: "validateSnapshot", + value: function validateSnapshot(rootName, expected) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$loose = _ref2.loose, + loose = _ref2$loose === void 0 ? false : _ref2$loose; + var rootNodes = this.snapshot.filter(function (node) { + return node.name === rootName && node.type !== 'string'; + }); + if (loose) { + assert(rootNodes.length >= expected.length, "Expect to find at least ".concat(expected.length, " '").concat(rootName, "', ") + "found ".concat(rootNodes.length)); + } else { + assert.strictEqual(rootNodes.length, expected.length, "Expect to find ".concat(expected.length, " '").concat(rootName, "', ") + "found ".concat(rootNodes.length)); + } + var _iterator = _createForOfIteratorHelper(expected), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var expectation = _step.value; + if (expectation.children) { + var _iterator2 = _createForOfIteratorHelper(expectation.children), + _step2; + try { + var _loop = function _loop() { + var expectedEdge = _step2.value; + var check = typeof expectedEdge === 'function' ? expectedEdge : function (edge) { + return isEdge(edge, expectedEdge); + }; + var hasChild = rootNodes.some(function (node) { + return node.outgoingEdges.some(check); + }); + // Don't use assert with a custom message here. Otherwise the + // inspection in the message is done eagerly and wastes a lot of CPU + // time. + if (!hasChild) { + throw new Error('expected to find child ' + "".concat(util.inspect(expectedEdge), " in ").concat(inspectNode(rootNodes))); + } + }; + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + _loop(); } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); } } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); } - } - // Validate our internal embedded graph representation - validateGraph(rootName, expected) { - let _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - _ref3$loose = _ref3.loose, - loose = _ref3$loose === void 0 ? false : _ref3$loose; - const rootNodes = this.embedderGraph.filter(node => node.name === rootName); - if (loose) { - assert(rootNodes.length >= expected.length, `Expect to find at least ${expected.length} '${rootName}', ` + `found ${rootNodes.length}`); - } else { - assert.strictEqual(rootNodes.length, expected.length, `Expect to find ${expected.length} '${rootName}', ` + `found ${rootNodes.length}`); - } - var _iterator3 = _createForOfIteratorHelper(expected), - _step3; - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - const expectation = _step3.value; - if (expectation.children) { - var _iterator4 = _createForOfIteratorHelper(expectation.children), - _step4; - try { - for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - const expectedEdge = _step4.value; - const check = typeof expectedEdge === 'function' ? expectedEdge : edge => isEdge(edge, expectedEdge); - // Don't use assert with a custom message here. Otherwise the - // inspection in the message is done eagerly and wastes a lot of CPU - // time. - const hasChild = rootNodes.some(node => node.edges.some(check)); - if (!hasChild) { - throw new Error('expected to find child ' + `${util.inspect(expectedEdge)} in ${inspectNode(rootNodes)}`); + // Validate our internal embedded graph representation + }, { + key: "validateGraph", + value: function validateGraph(rootName, expected) { + var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref3$loose = _ref3.loose, + loose = _ref3$loose === void 0 ? false : _ref3$loose; + var rootNodes = this.embedderGraph.filter(function (node) { + return node.name === rootName; + }); + if (loose) { + assert(rootNodes.length >= expected.length, "Expect to find at least ".concat(expected.length, " '").concat(rootName, "', ") + "found ".concat(rootNodes.length)); + } else { + assert.strictEqual(rootNodes.length, expected.length, "Expect to find ".concat(expected.length, " '").concat(rootName, "', ") + "found ".concat(rootNodes.length)); + } + var _iterator3 = _createForOfIteratorHelper(expected), + _step3; + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var expectation = _step3.value; + if (expectation.children) { + var _iterator4 = _createForOfIteratorHelper(expectation.children), + _step4; + try { + var _loop2 = function _loop2() { + var expectedEdge = _step4.value; + var check = typeof expectedEdge === 'function' ? expectedEdge : function (edge) { + return isEdge(edge, expectedEdge); + }; + // Don't use assert with a custom message here. Otherwise the + // inspection in the message is done eagerly and wastes a lot of CPU + // time. + var hasChild = rootNodes.some(function (node) { + return node.edges.some(check); + }); + if (!hasChild) { + throw new Error('expected to find child ' + "".concat(util.inspect(expectedEdge), " in ").concat(inspectNode(rootNodes))); + } + }; + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + _loop2(); } + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); } - } catch (err) { - _iterator4.e(err); - } finally { - _iterator4.f(); } } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); } - } - validateSnapshotNodes(rootName, expected) { - let _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - _ref4$loose = _ref4.loose, - loose = _ref4$loose === void 0 ? false : _ref4$loose; - this.validateSnapshot(rootName, expected, { - loose - }); - this.validateGraph(rootName, expected, { - loose - }); - } -} + }, { + key: "validateSnapshotNodes", + value: function validateSnapshotNodes(rootName, expected) { + var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref4$loose = _ref4.loose, + loose = _ref4$loose === void 0 ? false : _ref4$loose; + this.validateSnapshot(rootName, expected, { + loose: loose + }); + this.validateGraph(rootName, expected, { + loose: loose + }); + } + }]); + return State; +}(); function recordState() { return new State(); } function validateSnapshotNodes() { - return recordState().validateSnapshotNodes(...arguments); + var _recordState; + return (_recordState = recordState()).validateSnapshotNodes.apply(_recordState, arguments); } module.exports = { - recordState, - validateSnapshotNodes + recordState: recordState, + validateSnapshotNodes: validateSnapshotNodes }; function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { diff --git a/test/common/hijackstdio.js b/test/common/hijackstdio.js index aeb8ef366..9288841d6 100644 --- a/test/common/hijackstdio.js +++ b/test/common/hijackstdio.js @@ -16,16 +16,16 @@ var objectKeys = objectKeys || function (obj) { /**/ // Hijack stdout and stderr -const stdWrite = {}; +var stdWrite = {}; function hijackStdWritable(name, listener) { - const stream = process[name]; - const _write = stdWrite[name] = stream.write; + var stream = process[name]; + var _write = stdWrite[name] = stream.write; stream.writeTimes = 0; stream.write = function (data, callback) { try { listener(data); } catch (e) { - process.nextTick(() => { + process.nextTick(function () { throw e; }); } diff --git a/test/common/http2.js b/test/common/http2.js index 6042fbb30..25c6e748b 100644 --- a/test/common/http2.js +++ b/test/common/http2.js @@ -1,5 +1,17 @@ "use strict"; +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**/ require('@babel/polyfill'); var util = require('util'); @@ -18,15 +30,15 @@ var objectKeys = objectKeys || function (obj) { // An HTTP/2 testing tool used to create mock frames for direct testing // of HTTP/2 endpoints. -const kFrameData = Symbol('frame-data'); -const FLAG_EOS = 0x1; -const FLAG_ACK = 0x1; -const FLAG_EOH = 0x4; -const FLAG_PADDED = 0x8; -const PADDING = Buffer.alloc(255); -const kClientMagic = Buffer.from('505249202a20485454502f322' + 'e300d0a0d0a534d0d0a0d0a', 'hex'); -const kFakeRequestHeaders = Buffer.from('828684410f7777772e65' + '78616d706c652e636f6d', 'hex'); -const kFakeResponseHeaders = Buffer.from('4803333032580770726976617465611d' + '4d6f6e2c203231204f63742032303133' + '2032303a31333a323120474d546e1768' + '747470733a2f2f7777772e6578616d70' + '6c652e636f6d', 'hex'); +var kFrameData = Symbol('frame-data'); +var FLAG_EOS = 0x1; +var FLAG_ACK = 0x1; +var FLAG_EOH = 0x4; +var FLAG_PADDED = 0x8; +var PADDING = Buffer.alloc(255); +var kClientMagic = Buffer.from('505249202a20485454502f322' + 'e300d0a0d0a534d0d0a0d0a', 'hex'); +var kFakeRequestHeaders = Buffer.from('828684410f7777772e65' + '78616d706c652e636f6d', 'hex'); +var kFakeResponseHeaders = Buffer.from('4803333032580770726976617465611d' + '4d6f6e2c203231204f63742032303133' + '2032303a31333a323120474d546e1768' + '747470733a2f2f7777772e6578616d70' + '6c652e636f6d', 'hex'); function isUint32(val) { return val >>> 0 === val; } @@ -53,91 +65,124 @@ function write8(array, pos, val) { if (!isUint8(val)) throw new RangeError('val is not an 8-bit number'); array[pos] = val; } -class Frame { - constructor(length, type, flags, id) { +var Frame = /*#__PURE__*/function () { + function Frame(length, type, flags, id) { + _classCallCheck(this, Frame); this[kFrameData] = Buffer.alloc(9); write24BE(this[kFrameData], 0, length); write8(this[kFrameData], 3, type); write8(this[kFrameData], 4, flags); write32BE(this[kFrameData], 5, id); } - get data() { - return this[kFrameData]; - } -} -class SettingsFrame extends Frame { - constructor() { - let ack = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; - let flags = 0; + _createClass(Frame, [{ + key: "data", + get: function get() { + return this[kFrameData]; + } + }]); + return Frame; +}(); +var SettingsFrame = /*#__PURE__*/function (_Frame) { + _inherits(SettingsFrame, _Frame); + var _super = _createSuper(SettingsFrame); + function SettingsFrame() { + var ack = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + _classCallCheck(this, SettingsFrame); + var flags = 0; if (ack) flags |= FLAG_ACK; - super(0, 4, flags, 0); + return _super.call(this, 0, 4, flags, 0); } -} -class DataFrame extends Frame { - constructor(id, payload) { - let padlen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; - let final = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; - let len = payload.length; - let flags = 0; + return _createClass(SettingsFrame); +}(Frame); +var DataFrame = /*#__PURE__*/function (_Frame2) { + _inherits(DataFrame, _Frame2); + var _super2 = _createSuper(DataFrame); + function DataFrame(id, payload) { + var _this; + var padlen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var final = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + _classCallCheck(this, DataFrame); + var len = payload.length; + var flags = 0; if (final) flags |= FLAG_EOS; - const buffers = [payload]; + var buffers = [payload]; if (padlen > 0) { buffers.unshift(Buffer.from([padlen])); buffers.push(PADDING.slice(0, padlen)); len += padlen + 1; flags |= FLAG_PADDED; } - super(len, 0, flags, id); - buffers.unshift(this[kFrameData]); - this[kFrameData] = Buffer.concat(buffers); + _this = _super2.call(this, len, 0, flags, id); + buffers.unshift(_this[kFrameData]); + _this[kFrameData] = Buffer.concat(buffers); + return _this; } -} -class HeadersFrame extends Frame { - constructor(id, payload) { - let padlen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; - let final = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; - let len = payload.length; - let flags = FLAG_EOH; + return _createClass(DataFrame); +}(Frame); +var HeadersFrame = /*#__PURE__*/function (_Frame3) { + _inherits(HeadersFrame, _Frame3); + var _super3 = _createSuper(HeadersFrame); + function HeadersFrame(id, payload) { + var _this2; + var padlen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var final = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + _classCallCheck(this, HeadersFrame); + var len = payload.length; + var flags = FLAG_EOH; if (final) flags |= FLAG_EOS; - const buffers = [payload]; + var buffers = [payload]; if (padlen > 0) { buffers.unshift(Buffer.from([padlen])); buffers.push(PADDING.slice(0, padlen)); len += padlen + 1; flags |= FLAG_PADDED; } - super(len, 1, flags, id); - buffers.unshift(this[kFrameData]); - this[kFrameData] = Buffer.concat(buffers); + _this2 = _super3.call(this, len, 1, flags, id); + buffers.unshift(_this2[kFrameData]); + _this2[kFrameData] = Buffer.concat(buffers); + return _this2; } -} -class PingFrame extends Frame { - constructor() { - let ack = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; - const buffers = [Buffer.alloc(8)]; - super(8, 6, ack ? 1 : 0, 0); - buffers.unshift(this[kFrameData]); - this[kFrameData] = Buffer.concat(buffers); + return _createClass(HeadersFrame); +}(Frame); +var PingFrame = /*#__PURE__*/function (_Frame4) { + _inherits(PingFrame, _Frame4); + var _super4 = _createSuper(PingFrame); + function PingFrame() { + var _this3; + var ack = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + _classCallCheck(this, PingFrame); + var buffers = [Buffer.alloc(8)]; + _this3 = _super4.call(this, 8, 6, ack ? 1 : 0, 0); + buffers.unshift(_this3[kFrameData]); + _this3[kFrameData] = Buffer.concat(buffers); + return _this3; } -} -class AltSvcFrame extends Frame { - constructor(size) { - const buffers = [Buffer.alloc(size)]; - super(size, 10, 0, 0); - buffers.unshift(this[kFrameData]); - this[kFrameData] = Buffer.concat(buffers); + return _createClass(PingFrame); +}(Frame); +var AltSvcFrame = /*#__PURE__*/function (_Frame5) { + _inherits(AltSvcFrame, _Frame5); + var _super5 = _createSuper(AltSvcFrame); + function AltSvcFrame(size) { + var _this4; + _classCallCheck(this, AltSvcFrame); + var buffers = [Buffer.alloc(size)]; + _this4 = _super5.call(this, size, 10, 0, 0); + buffers.unshift(_this4[kFrameData]); + _this4[kFrameData] = Buffer.concat(buffers); + return _this4; } -} + return _createClass(AltSvcFrame); +}(Frame); module.exports = { - Frame, - AltSvcFrame, - DataFrame, - HeadersFrame, - SettingsFrame, - PingFrame, - kFakeRequestHeaders, - kFakeResponseHeaders, - kClientMagic + Frame: Frame, + AltSvcFrame: AltSvcFrame, + DataFrame: DataFrame, + HeadersFrame: HeadersFrame, + SettingsFrame: SettingsFrame, + PingFrame: PingFrame, + kFakeRequestHeaders: kFakeRequestHeaders, + kFakeResponseHeaders: kFakeResponseHeaders, + kClientMagic: kClientMagic }; function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { diff --git a/test/common/index.js b/test/common/index.js index d8977c016..a9edce03e 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -1,5 +1,15 @@ "use strict"; +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } @@ -39,12 +49,12 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const process = global.process; // Some tests tamper with the process global. -const path = require('path'); -const fs = require('fs'); -const assert = require('assert'); -const os = require('os'); -const _require = require('child_process'), +var process = global.process; // Some tests tamper with the process global. +var path = require('path'); +var fs = require('fs'); +var assert = require('assert'); +var os = require('os'); +var _require = require('child_process'), exec = _require.exec, execSync = _require.execSync, spawnSync = _require.spawnSync; @@ -54,47 +64,49 @@ var util = require('core-util-is'); util.inherits = require('inherits'); /**/ -const Timer = { +var Timer = { now: function now() {} }; -const tmpdir = require('./tmpdir'); -const _process$binding = process.binding('config'), +var tmpdir = require('./tmpdir'); +var _process$binding = process.binding('config'), bits = _process$binding.bits, hasIntl = _process$binding.hasIntl; -const noop = () => {}; -const hasCrypto = true; -const isMainThread = (() => { +var noop = function noop() {}; +var hasCrypto = true; +var isMainThread = function () { if (false) { return require('worker_threads').isMainThread; } // Worker module not enabled → only a single main thread exists. return true; -})(); +}(); // Check for flags. Skip this for workers (both, the `cluster` module and // `worker_threads`) and child processes. if (false && isMainThread && module.parent && require('cluster').isMaster) { // The copyright notice is relatively big and the flags could come afterwards. - const bytesToRead = 1500; - const buffer = Buffer.allocUnsafe(bytesToRead); - const fd = fs.openSync(module.parent.filename, 'r'); - const bytesRead = fs.readSync(fd, buffer, 0, bytesToRead); + var bytesToRead = 1500; + var buffer = Buffer.allocUnsafe(bytesToRead); + var fd = fs.openSync(module.parent.filename, 'r'); + var bytesRead = fs.readSync(fd, buffer, 0, bytesToRead); fs.closeSync(fd); - const source = buffer.toString('utf8', 0, bytesRead); - const flagStart = source.indexOf('// Flags: --') + 10; + var source = buffer.toString('utf8', 0, bytesRead); + var flagStart = source.indexOf('// Flags: --') + 10; if (flagStart !== 9) { - let flagEnd = source.indexOf('\n', flagStart); + var flagEnd = source.indexOf('\n', flagStart); // Normalize different EOL. if (source[flagEnd - 1] === '\r') { flagEnd--; } - const flags = source.substring(flagStart, flagEnd).replace(/_/g, '-').split(' '); - const args = process.execArgv.map(arg => arg.replace(/_/g, '-')); + var flags = source.substring(flagStart, flagEnd).replace(/_/g, '-').split(' '); + var args = process.execArgv.map(function (arg) { + return arg.replace(/_/g, '-'); + }); var _iterator = _createForOfIteratorHelper(flags), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { - const flag = _step.value; + var flag = _step.value; if (!args.includes(flag) && // If the binary was built without-ssl then the crypto flags are // invalid (bad option). The test itself should handle this case. @@ -102,7 +114,7 @@ if (false && isMainThread && module.parent && require('cluster').isMaster) { // If the binary is build without `intl` the inspect option is // invalid. The test itself should handle this case. process.config.variables.v8_enable_inspector !== 0 || !flag.startsWith('--inspect'))) { - throw new Error(`Test has to be started with the flag: '${flag}'`); + throw new Error("Test has to be started with the flag: '".concat(flag, "'")); } } } catch (err) { @@ -112,38 +124,38 @@ if (false && isMainThread && module.parent && require('cluster').isMaster) { } } } -const isWindows = process.platform === 'win32'; -const isAIX = process.platform === 'aix'; -const isLinuxPPCBE = process.platform === 'linux' && process.arch === 'ppc64' && os.endianness() === 'BE'; -const isSunOS = process.platform === 'sunos'; -const isFreeBSD = process.platform === 'freebsd'; -const isOpenBSD = process.platform === 'openbsd'; -const isLinux = process.platform === 'linux'; -const isOSX = process.platform === 'darwin'; -const enoughTestMem = os.totalmem() > 0x70000000; /* 1.75 Gb */ -const cpus = os.cpus().length === 0 ? [{ +var isWindows = process.platform === 'win32'; +var isAIX = process.platform === 'aix'; +var isLinuxPPCBE = process.platform === 'linux' && process.arch === 'ppc64' && os.endianness() === 'BE'; +var isSunOS = process.platform === 'sunos'; +var isFreeBSD = process.platform === 'freebsd'; +var isOpenBSD = process.platform === 'openbsd'; +var isLinux = process.platform === 'linux'; +var isOSX = process.platform === 'darwin'; +var enoughTestMem = os.totalmem() > 0x70000000; /* 1.75 Gb */ +var cpus = os.cpus().length === 0 ? [{ speed: 1000 }] : os.cpus(); -const enoughTestCpu = Array.isArray(cpus) && (cpus.length > 1 || cpus[0].speed > 999); -const rootDir = isWindows ? 'c:\\' : '/'; -const buildType = 'readable-stream'; +var enoughTestCpu = Array.isArray(cpus) && (cpus.length > 1 || cpus[0].speed > 999); +var rootDir = isWindows ? 'c:\\' : '/'; +var buildType = 'readable-stream'; // If env var is set then enable async_hook hooks for all tests. if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) { - const destroydIdsList = {}; - const destroyListList = {}; - const initHandles = {}; - const async_wrap = process.binding('async_wrap'); - process.on('exit', () => { + var destroydIdsList = {}; + var destroyListList = {}; + var initHandles = {}; + var async_wrap = process.binding('async_wrap'); + process.on('exit', function () { // iterate through handles to make sure nothing crashes - for (const k in initHandles) util.inspect(initHandles[k]); + for (var k in initHandles) util.inspect(initHandles[k]); }); - const _queueDestroyAsyncId = async_wrap.queueDestroyAsyncId; + var _queueDestroyAsyncId = async_wrap.queueDestroyAsyncId; async_wrap.queueDestroyAsyncId = function queueDestroyAsyncId(id) { if (destroyListList[id] !== undefined) { process._rawDebug(destroyListList[id]); process._rawDebug(); - throw new Error(`same id added to destroy list twice (${id})`); + throw new Error("same id added to destroy list twice (".concat(id, ")")); } destroyListList[id] = new Error().stack; _queueDestroyAsyncId(id); @@ -172,32 +184,32 @@ if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) { }).enable();*/ } -let opensslCli = null; -let inFreeBSDJail = null; -let localhostIPv4 = null; -const localIPv6Hosts = isLinux ? [ +var opensslCli = null; +var inFreeBSDJail = null; +var localhostIPv4 = null; +var localIPv6Hosts = isLinux ? [ // Debian/Ubuntu 'ip6-localhost', 'ip6-loopback', // SUSE 'ipv6-localhost', 'ipv6-loopback', // Typically universal 'localhost'] : ['localhost']; -const PIPE = (() => { - const localRelative = path.relative(process.cwd(), `${tmpdir.path}/`); - const pipePrefix = isWindows ? '\\\\.\\pipe\\' : localRelative; - const pipeName = `node-test.${process.pid}.sock`; +var PIPE = function () { + var localRelative = path.relative(process.cwd(), "".concat(tmpdir.path, "/")); + var pipePrefix = isWindows ? '\\\\.\\pipe\\' : localRelative; + var pipeName = "node-test.".concat(process.pid, ".sock"); return path.join(pipePrefix, pipeName); -})(); -const hasIPv6 = (() => { - const iFaces = os.networkInterfaces(); - const re = isWindows ? /Loopback Pseudo-Interface/ : /lo/; - return objectKeys(iFaces).some(name => { - return re.test(name) && iFaces[name].some(_ref => { - let family = _ref.family; +}(); +var hasIPv6 = function () { + var iFaces = os.networkInterfaces(); + var re = isWindows ? /Loopback Pseudo-Interface/ : /lo/; + return objectKeys(iFaces).some(function (name) { + return re.test(name) && iFaces[name].some(function (_ref) { + var family = _ref.family; return family === 'IPv6'; }); }); -})(); +}(); /* * Check that when running a test with @@ -205,33 +217,33 @@ const hasIPv6 = (() => { * the process aborts. */ function childShouldThrowAndAbort() { - let testCmd = ''; + var testCmd = ''; if (!isWindows) { // Do not create core files, as it can take a lot of disk space on // continuous testing and developers' machines testCmd += 'ulimit -c 0 && '; } - testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception `; - testCmd += `"${process.argv[1]}" child`; - const child = exec(testCmd); + testCmd += "\"".concat(process.argv[0], "\" --abort-on-uncaught-exception "); + testCmd += "\"".concat(process.argv[1], "\" child"); + var child = exec(testCmd); child.on('exit', function onExit(exitCode, signal) { - const errMsg = 'Test should have aborted ' + `but instead exited with exit code ${exitCode}` + ` and signal ${signal}`; + var errMsg = 'Test should have aborted ' + "but instead exited with exit code ".concat(exitCode) + " and signal ".concat(signal); assert(nodeProcessAborted(exitCode, signal), errMsg); }); } function createZeroFilledFile(filename) { - const fd = fs.openSync(filename, 'w'); + var fd = fs.openSync(filename, 'w'); fs.ftruncateSync(fd, 10 * 1024 * 1024); fs.closeSync(fd); } -const pwdCommand = isWindows ? ['cmd.exe', ['/d', '/c', 'cd']] : ['pwd', []]; +var pwdCommand = isWindows ? ['cmd.exe', ['/d', '/c', 'cd']] : ['pwd', []]; function platformTimeout(ms) { if (process.features.debug) ms = 2 * ms; if (global.__coverage__) ms = 4 * ms; if (isAIX) return 2 * ms; // default localhost speed is slower on AIX if (process.arch !== 'arm') return ms; - const armv = process.config.variables.arm_version; + var armv = process.config.variables.arm_version; if (armv === '6') return 7 * ms; // ARMv6 if (armv === '7') return 2 * ms; // ARMv7 @@ -239,7 +251,7 @@ function platformTimeout(ms) { return ms; // ARMv8+ } -let knownGlobals = [Buffer, clearImmediate, clearInterval, clearTimeout, global, process, setImmediate, setInterval, setTimeout]; +var knownGlobals = [Buffer, clearImmediate, clearInterval, clearTimeout, global, process, setImmediate, setInterval, setTimeout]; if (global.gc) { knownGlobals.push(global.gc); } @@ -260,8 +272,8 @@ if (global.COUNTER_NET_SERVER_CONNECTION) { knownGlobals.push(COUNTER_HTTP_CLIENT_RESPONSE); } if (process.env.NODE_TEST_KNOWN_GLOBALS) { - const knownFromEnv = process.env.NODE_TEST_KNOWN_GLOBALS.split(','); - allowGlobals(...knownFromEnv); + var knownFromEnv = process.env.NODE_TEST_KNOWN_GLOBALS.split(','); + allowGlobals.apply(void 0, _toConsumableArray(knownFromEnv)); } function allowGlobals() { for (var _len = arguments.length, whitelist = new Array(_len), _key = 0; _key < _len; _key++) { @@ -282,33 +294,35 @@ if (global.__coverage__) knownGlobals.push(__coverage__); }); /**/ function leakedGlobals() { - const leaked = []; - for (const val in global) { + var leaked = []; + for (var val in global) { if (!knownGlobals.includes(global[val])) { leaked.push(val); } } if (global.__coverage__) { - return leaked.filter(varname => !/^(?:cov_|__cov)/.test(varname)); + return leaked.filter(function (varname) { + return !/^(?:cov_|__cov)/.test(varname); + }); } else { return leaked; } } process.on('exit', function () { - const leaked = leakedGlobals(); + var leaked = leakedGlobals(); if (leaked.length > 0) { - assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`); + assert.fail("Unexpected global(s) found: ".concat(leaked.join(', '))); } }); -const mustCallChecks = []; +var mustCallChecks = []; function runCallChecks(exitCode) { if (exitCode !== 0) return; - const failed = mustCallChecks.filter(function (context) { + var failed = mustCallChecks.filter(function (context) { if ('minimum' in context) { - context.messageSegment = `at least ${context.minimum}`; + context.messageSegment = "at least ".concat(context.minimum); return context.actual < context.minimum; } else { - context.messageSegment = `exactly ${context.exact}`; + context.messageSegment = "exactly ".concat(context.exact); return context.actual !== context.exact; } }); @@ -325,8 +339,9 @@ function mustCallAtLeast(fn, minimum) { return _mustCallInner(fn, minimum, 'minimum'); } function _mustCallInner(fn) { - let criteria = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; - let field = arguments.length > 2 ? arguments[2] : undefined; + var _context; + var criteria = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + var field = arguments.length > 2 ? arguments[2] : undefined; if (process._exiting) throw new Error('Cannot use common.mustCall*() in process exit handler'); if (typeof fn === 'number') { criteria = fn; @@ -334,13 +349,8 @@ function _mustCallInner(fn) { } else if (fn === undefined) { fn = noop; } - if (typeof criteria !== 'number') throw new TypeError(`Invalid ${field} value: ${criteria}`); - const context = { - [field]: criteria, - actual: 0, - stack: new Error().stack, - name: fn.name || '' - }; + if (typeof criteria !== 'number') throw new TypeError("Invalid ".concat(field, " value: ").concat(criteria)); + var context = (_context = {}, _defineProperty(_context, field, criteria), _defineProperty(_context, "actual", 0), _defineProperty(_context, "stack", new Error().stack), _defineProperty(_context, "name", fn.name || ''), _context); // add the exit listener only once to avoid listener leak warnings if (mustCallChecks.length === 0) process.on('exit', runCallChecks); @@ -351,11 +361,11 @@ function _mustCallInner(fn) { }; } function hasMultiLocalhost() { - const _process$binding2 = process.binding('tcp_wrap'), + var _process$binding2 = process.binding('tcp_wrap'), TCP = _process$binding2.TCP, TCPConstants = _process$binding2.constants; - const t = new TCP(TCPConstants.SOCKET); - const ret = t.bind('127.0.0.2', 0); + var t = new TCP(TCPConstants.SOCKET); + var ret = t.bind('127.0.0.2', 0); t.close(); return ret === 0; } @@ -372,9 +382,9 @@ function canCreateSymLink() { // whoami.exe needs to be the one from System32 // If unix tools are in the path, they can shadow the one we want, // so use the full path while executing whoami - const whoamiPath = path.join(process.env.SystemRoot, 'System32', 'whoami.exe'); + var whoamiPath = path.join(process.env.SystemRoot, 'System32', 'whoami.exe'); try { - const output = execSync(`${whoamiPath} /priv`, { + var output = execSync("".concat(whoamiPath, " /priv"), { timout: 1000 }); return output.includes('SeCreateSymbolicLinkPrivilege'); @@ -386,9 +396,11 @@ function canCreateSymLink() { return true; } function getCallSite(top) { - const originalStackFormatter = Error.prepareStackTrace; - Error.prepareStackTrace = (err, stack) => `${stack[0].getFileName()}:${stack[0].getLineNumber()}`; - const err = new Error(); + var originalStackFormatter = Error.prepareStackTrace; + Error.prepareStackTrace = function (err, stack) { + return "".concat(stack[0].getFileName(), ":").concat(stack[0].getLineNumber()); + }; + var err = new Error(); Error.captureStackTrace(err, top); // with the V8 Error API, the stack is not formatted until it is accessed err.stack; @@ -396,13 +408,13 @@ function getCallSite(top) { return err.stack; } function mustNotCall(msg) { - const callSite = getCallSite(mustNotCall); + var callSite = getCallSite(mustNotCall); return function mustNotCall() { - assert.fail(`${msg || 'function should not have been called'} at ${callSite}`); + assert.fail("".concat(msg || 'function should not have been called', " at ").concat(callSite)); }; } function printSkipMessage(msg) { - console.log(`1..0 # Skipped: ${msg}`); + console.log("1..0 # Skipped: ".concat(msg)); } function skip(msg) { printSkipMessage(msg); @@ -415,14 +427,14 @@ function skip(msg) { function nodeProcessAborted(exitCode, signal) { // Depending on the compiler used, node will exit with either // exit code 132 (SIGILL), 133 (SIGTRAP) or 134 (SIGABRT). - let expectedExitCodes = [132, 133, 134]; + var expectedExitCodes = [132, 133, 134]; // On platforms using KSH as the default shell (like SmartOS), // when a process aborts, KSH exits with an exit code that is // greater than 256, and thus the exit code emitted with the 'exit' // event is null and the signal is set to either SIGILL, SIGTRAP, // or SIGABRT (depending on the compiler). - const expectedSignals = ['SIGILL', 'SIGTRAP', 'SIGABRT']; + var expectedSignals = ['SIGILL', 'SIGTRAP', 'SIGABRT']; // On Windows, 'aborts' are of 2 types, depending on the context: // (i) Forced access violation, if --abort-on-uncaught-exception is on @@ -445,8 +457,8 @@ function nodeProcessAborted(exitCode, signal) { } } function busyLoop(time) { - const startTime = Timer.now(); - const stopTime = startTime + time; + var startTime = Timer.now(); + var stopTime = startTime + time; while (Timer.now() < stopTime) {} } function isAlive(pid) { @@ -458,11 +470,11 @@ function isAlive(pid) { } } function _expectWarning(name, expected) { - const map = new Map(expected); - return mustCall(warning => { + var map = new Map(expected); + return mustCall(function (warning) { assert.strictEqual(warning.name, name); - assert.ok(map.has(warning.message), `unexpected error message: "${warning.message}"`); - const code = map.get(warning.message); + assert.ok(map.has(warning.message), "unexpected error message: \"".concat(warning.message, "\"")); + var code = map.get(warning.message); assert.strictEqual(warning.code, code); // Remove a warning message after it is seen so that we guarantee that we // get each message only once. @@ -476,9 +488,9 @@ function expectWarningByName(name, expected, code) { process.on('warning', _expectWarning(name, expected)); } function expectWarningByMap(warningMap) { - const catchWarning = {}; - forEach(objectKeys(warningMap), name => { - let expected = warningMap[name]; + var catchWarning = {}; + forEach(objectKeys(warningMap), function (name) { + var expected = warningMap[name]; if (!Array.isArray(expected)) { throw new Error('warningMap entries must be arrays consisting of two ' + 'entries: [message, warningCode]'); } @@ -490,7 +502,9 @@ function expectWarningByMap(warningMap) { } catchWarning[name] = _expectWarning(name, expected); }); - process.on('warning', warning => catchWarning[warning.name](warning)); + process.on('warning', function (warning) { + return catchWarning[warning.name](warning); + }); } // accepts a warning name and description or array of descriptions or a map @@ -503,24 +517,21 @@ function expectWarning(nameOrMap, expected, code) { expectWarningByMap(nameOrMap); } } -class Comparison { - constructor(obj, keys) { - var _iterator2 = _createForOfIteratorHelper(keys), - _step2; - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - const key = _step2.value; - if (key in obj) this[key] = obj[key]; - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); +var Comparison = /*#__PURE__*/_createClass(function Comparison(obj, keys) { + _classCallCheck(this, Comparison); + var _iterator2 = _createForOfIteratorHelper(keys), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var key = _step2.value; + if (key in obj) this[key] = obj[key]; } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); } -} - -// Useful for testing expected internal/error objects +}); // Useful for testing expected internal/error objects function expectsError(fn, settings, exact) { if (typeof fn !== 'function') { exact = settings; @@ -531,23 +542,23 @@ function expectsError(fn, settings, exact) { if (arguments.length !== 1) { // Do not use `assert.strictEqual()` to prevent `util.inspect` from // always being called. - assert.fail(`Expected one argument, got ${util.inspect(arguments)}`); + assert.fail("Expected one argument, got ".concat(util.inspect(arguments))); } - const descriptor = Object.getOwnPropertyDescriptor(error, 'message'); + var descriptor = Object.getOwnPropertyDescriptor(error, 'message'); // The error message should be non-enumerable assert.strictEqual(descriptor.enumerable, false); - let innerSettings = settings; + var innerSettings = settings; if ('type' in settings) { - const type = settings.type; + var type = settings.type; if (type !== Error && !Error.isPrototypeOf(type)) { throw new TypeError('`settings.type` must inherit from `Error`'); } - let constructor = error.constructor; - if (constructor.name === 'NodeError' && type.name !== 'NodeError') { - constructor = Object.getPrototypeOf(error.constructor); + var _constructor = error.constructor; + if (_constructor.name === 'NodeError' && type.name !== 'NodeError') { + _constructor = Object.getPrototypeOf(error.constructor); } // Add the `type` to the error to properly compare and visualize it. - if (!('type' in error)) error.type = constructor; + if (!('type' in error)) error.type = _constructor; } if ('message' in settings && typeof settings.message === 'object' && settings.message.test(error.message)) { // Make a copy so we are able to modify the settings. @@ -557,19 +568,19 @@ function expectsError(fn, settings, exact) { } // Check all error properties. - const keys = objectKeys(settings); + var keys = objectKeys(settings); var _iterator3 = _createForOfIteratorHelper(keys), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - const key = _step3.value; + var key = _step3.value; if (!require('deep-strict-equal')(error[key], innerSettings[key])) { // Create placeholder objects to create a nice output. - const a = new Comparison(error, keys); - const b = new Comparison(innerSettings, keys); - const tmpLimit = Error.stackTraceLimit; + var a = new Comparison(error, keys); + var b = new Comparison(innerSettings, keys); + var tmpLimit = Error.stackTraceLimit; Error.stackTraceLimit = 0; - const err = new assert.AssertionError({ + var err = new assert.AssertionError({ actual: a, expected: b, operator: 'strictEqual', @@ -613,14 +624,14 @@ function skipIfWorker() { } } function getArrayBufferViews(buf) { - const buffer = buf.buffer, + var buffer = buf.buffer, byteOffset = buf.byteOffset, byteLength = buf.byteLength; - const out = []; - const arrayBufferViews = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView]; + var out = []; + var arrayBufferViews = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView]; for (var _i = 0, _arrayBufferViews = arrayBufferViews; _i < _arrayBufferViews.length; _i++) { - const type = _arrayBufferViews[_i]; - const _type$BYTES_PER_ELEME = type.BYTES_PER_ELEMENT, + var type = _arrayBufferViews[_i]; + var _type$BYTES_PER_ELEME = type.BYTES_PER_ELEMENT, BYTES_PER_ELEMENT = _type$BYTES_PER_ELEME === void 0 ? 1 : _type$BYTES_PER_ELEME; if (byteLength % BYTES_PER_ELEMENT === 0) { out.push(new type(buffer, byteOffset, byteLength / BYTES_PER_ELEMENT)); @@ -629,11 +640,11 @@ function getArrayBufferViews(buf) { return out; } function getBufferSources(buf) { - return [...getArrayBufferViews(buf), new Uint8Array(buf).buffer]; + return [].concat(_toConsumableArray(getArrayBufferViews(buf)), [new Uint8Array(buf).buffer]); } // Crash the process on unhandled rejections. -const crashOnUnhandledRejection = err => { +var crashOnUnhandledRejection = function crashOnUnhandledRejection(err) { throw err; }; process.on('unhandledRejection', crashOnUnhandledRejection); @@ -642,10 +653,10 @@ function disableCrashOnUnhandledRejection() { } function getTTYfd() { // Do our best to grab a tty fd. - const tty = require('tty'); + var tty = require('tty'); // Don't attempt fd 0 as it is not writable on Windows. // Ref: ef2861961c3d9e9ed6972e1e84d969683b25cf95 - const ttyFd = [1, 2, 4, 5].find(tty.isatty); + var ttyFd = [1, 2, 4, 5].find(tty.isatty); if (ttyFd === undefined) { try { return fs.openSync('/dev/tty'); @@ -657,7 +668,7 @@ function getTTYfd() { return ttyFd; } function runWithInvalidFD(func) { - let fd = 1 << 30; + var fd = 1 << 30; // Get first known bad file descriptor. 1 << 30 is usually unlikely to // be an valid one. try { @@ -668,52 +679,52 @@ function runWithInvalidFD(func) { printSkipMessage('Could not generate an invalid fd'); } module.exports = { - allowGlobals, - buildType, - busyLoop, - canCreateSymLink, - childShouldThrowAndAbort, - createZeroFilledFile, - disableCrashOnUnhandledRejection, - enoughTestCpu, - enoughTestMem, - expectsError, - expectWarning, - getArrayBufferViews, - getBufferSources, - getCallSite, - getTTYfd, - hasIntl, - hasCrypto, - hasIPv6, - hasMultiLocalhost, - isAIX, - isAlive, - isFreeBSD, - isLinux, - isLinuxPPCBE, - isMainThread, - isOpenBSD, - isOSX, - isSunOS, - isWindows, - localIPv6Hosts, - mustCall, - mustCallAtLeast, - mustNotCall, - nodeProcessAborted, + allowGlobals: allowGlobals, + buildType: buildType, + busyLoop: busyLoop, + canCreateSymLink: canCreateSymLink, + childShouldThrowAndAbort: childShouldThrowAndAbort, + createZeroFilledFile: createZeroFilledFile, + disableCrashOnUnhandledRejection: disableCrashOnUnhandledRejection, + enoughTestCpu: enoughTestCpu, + enoughTestMem: enoughTestMem, + expectsError: expectsError, + expectWarning: expectWarning, + getArrayBufferViews: getArrayBufferViews, + getBufferSources: getBufferSources, + getCallSite: getCallSite, + getTTYfd: getTTYfd, + hasIntl: hasIntl, + hasCrypto: hasCrypto, + hasIPv6: hasIPv6, + hasMultiLocalhost: hasMultiLocalhost, + isAIX: isAIX, + isAlive: isAlive, + isFreeBSD: isFreeBSD, + isLinux: isLinux, + isLinuxPPCBE: isLinuxPPCBE, + isMainThread: isMainThread, + isOpenBSD: isOpenBSD, + isOSX: isOSX, + isSunOS: isSunOS, + isWindows: isWindows, + localIPv6Hosts: localIPv6Hosts, + mustCall: mustCall, + mustCallAtLeast: mustCallAtLeast, + mustNotCall: mustNotCall, + nodeProcessAborted: nodeProcessAborted, noWarnCode: undefined, - PIPE, - platformTimeout, - printSkipMessage, - pwdCommand, - rootDir, - runWithInvalidFD, - skip, - skipIf32Bits, - skipIfEslintMissing, - skipIfInspectorDisabled, - skipIfWorker, + PIPE: PIPE, + platformTimeout: platformTimeout, + printSkipMessage: printSkipMessage, + pwdCommand: pwdCommand, + rootDir: rootDir, + runWithInvalidFD: runWithInvalidFD, + skip: skip, + skipIf32Bits: skipIf32Bits, + skipIfEslintMissing: skipIfEslintMissing, + skipIfInspectorDisabled: skipIfInspectorDisabled, + skipIfWorker: skipIfWorker, get localhostIPv6() { return '::1'; }, @@ -755,7 +766,7 @@ module.exports = { opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli'); } if (exports.isWindows) opensslCli += '.exe'; - const opensslCmd = spawnSync(opensslCli, ['version']); + var opensslCmd = spawnSync(opensslCli, ['version']); if (opensslCmd.status !== 0 || opensslCmd.error !== undefined) { // openssl command cannot be executed opensslCli = false; diff --git a/test/common/inspector-helper.js b/test/common/inspector-helper.js index c325dc259..bbca6d3e7 100644 --- a/test/common/inspector-helper.js +++ b/test/common/inspector-helper.js @@ -1,7 +1,19 @@ "use strict"; +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } @@ -20,31 +32,31 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const common = require('../common'); -const assert = require('assert'); -const fs = require('fs'); -const http = require('http'); -const fixtures = require('../common/fixtures'); -const _require = require('child_process'), +var common = require('../common'); +var assert = require('assert'); +var fs = require('fs'); +var http = require('http'); +var fixtures = require('../common/fixtures'); +var _require = require('child_process'), spawn = _require.spawn; -const _require2 = require('url'), +var _require2 = require('url'), parseURL = _require2.parse; -const _require3 = require('internal/url'), +var _require3 = require('internal/url'), pathToFileURL = _require3.pathToFileURL; -const _require4 = require('events'), +var _require4 = require('events'), EventEmitter = _require4.EventEmitter; -const _MAINSCRIPT = fixtures.path('loop.js'); -const DEBUG = false; -const TIMEOUT = common.platformTimeout(15 * 1000); +var _MAINSCRIPT = fixtures.path('loop.js'); +var DEBUG = false; +var TIMEOUT = common.platformTimeout(15 * 1000); function spawnChildProcess(inspectorFlags, scriptContents, scriptFile) { - const args = [].concat(inspectorFlags); + var args = [].concat(inspectorFlags); if (scriptContents) { args.push('-e', scriptContents); } else { args.push(scriptFile); } - const child = spawn(process.execPath, args); - const handler = tearDown.bind(null, child); + var child = spawn(process.execPath, args); + var handler = tearDown.bind(null, child); process.on('exit', handler); process.on('uncaughtException', handler); common.disableCrashOnUnhandledRejection(); @@ -53,17 +65,17 @@ function spawnChildProcess(inspectorFlags, scriptContents, scriptFile) { return child; } function makeBufferingDataCallback(dataCallback) { - let buffer = Buffer.alloc(0); - return data => { - const newData = Buffer.concat([buffer, data]); - const str = newData.toString('utf8'); - const lines = str.replace(/\r/g, '').split('\n'); + var buffer = Buffer.alloc(0); + return function (data) { + var newData = Buffer.concat([buffer, data]); + var str = newData.toString('utf8'); + var lines = str.replace(/\r/g, '').split('\n'); if (str.endsWith('\n')) buffer = Buffer.alloc(0);else buffer = Buffer.from(lines.pop(), 'utf8'); var _iterator = _createForOfIteratorHelper(lines), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { - const line = _step.value; + var line = _step.value; dataCallback(line); } } catch (err) { @@ -82,21 +94,21 @@ function tearDown(child, err) { } function parseWSFrame(buffer) { // Protocol described in https://tools.ietf.org/html/rfc6455#section-5 - let message = null; + var message = null; if (buffer.length < 2) return { length: 0, - message + message: message }; if (buffer[0] === 0x88 && buffer[1] === 0x00) { return { length: 2, - message, + message: message, closed: true }; } assert.strictEqual(buffer[0], 0x81); - let dataLen = 0x7F & buffer[1]; - let bodyOffset = 2; + var dataLen = 0x7F & buffer[1]; + var bodyOffset = 2; if (buffer.length < bodyOffset + dataLen) return 0; if (dataLen === 126) { dataLen = buffer.readUInt16BE(2); @@ -108,28 +120,28 @@ function parseWSFrame(buffer) { } if (buffer.length < bodyOffset + dataLen) return { length: 0, - message + message: message }; - const jsonPayload = buffer.slice(bodyOffset, bodyOffset + dataLen).toString('utf8'); + var jsonPayload = buffer.slice(bodyOffset, bodyOffset + dataLen).toString('utf8'); try { message = JSON.parse(jsonPayload); } catch (e) { - console.error(`JSON.parse() failed for: ${jsonPayload}`); + console.error("JSON.parse() failed for: ".concat(jsonPayload)); throw e; } if (DEBUG) console.log('[received]', JSON.stringify(message)); return { length: bodyOffset + dataLen, - message + message: message }; } function formatWSFrame(message) { - const messageBuf = Buffer.from(JSON.stringify(message)); - const wsHeaderBuf = Buffer.allocUnsafe(16); + var messageBuf = Buffer.from(JSON.stringify(message)); + var wsHeaderBuf = Buffer.allocUnsafe(16); wsHeaderBuf.writeUInt8(0x81, 0); - let byte2 = 0x80; - const bodyLen = messageBuf.length; - let maskOffset = 2; + var byte2 = 0x80; + var bodyLen = messageBuf.length; + var maskOffset = 2; if (bodyLen < 126) { byte2 = 0x80 + bodyLen; } else if (bodyLen < 65536) { @@ -144,11 +156,13 @@ function formatWSFrame(message) { } wsHeaderBuf.writeUInt8(byte2, 1); wsHeaderBuf.writeUInt32BE(0x01020408, maskOffset); - for (let i = 0; i < messageBuf.length; i++) messageBuf[i] = messageBuf[i] ^ 1 << i % 4; + for (var _i = 0; _i < messageBuf.length; _i++) messageBuf[_i] = messageBuf[_i] ^ 1 << _i % 4; return Buffer.concat([wsHeaderBuf.slice(0, maskOffset + 4), messageBuf]); } -class InspectorSession { - constructor(socket, instance) { +var InspectorSession = /*#__PURE__*/function () { + function InspectorSession(socket, instance) { + var _this = this; + _classCallCheck(this, InspectorSession); this._instance = instance; this._socket = socket; this._nextId = 1; @@ -156,11 +170,11 @@ class InspectorSession { this._unprocessedNotifications = []; this._notificationCallback = null; this._scriptsIdsByUrl = new Map(); - let buffer = Buffer.alloc(0); - socket.on('data', data => { + var buffer = Buffer.alloc(0); + socket.on('data', function (data) { buffer = Buffer.concat([buffer, data]); do { - const _parseWSFrame = parseWSFrame(buffer), + var _parseWSFrame = parseWSFrame(buffer), length = _parseWSFrame.length, message = _parseWSFrame.message, closed = _parseWSFrame.closed; @@ -170,320 +184,444 @@ class InspectorSession { } buffer = buffer.slice(length); - if (message) this._onMessage(message); + if (message) _this._onMessage(message); } while (true); }); - this._terminationPromise = new Promise(resolve => { + this._terminationPromise = new Promise(function (resolve) { socket.once('close', resolve); }); } - waitForServerDisconnect() { - return this._terminationPromise; - } - disconnect() { - var _this = this; - return _asyncToGenerator(function* () { - _this._socket.destroy(); - return _this.waitForServerDisconnect(); - })(); - } - _onMessage(message) { - if (message.id) { - const _this$_commandRespons = this._commandResponsePromises.get(message.id), - resolve = _this$_commandRespons.resolve, - reject = _this$_commandRespons.reject; - this._commandResponsePromises.delete(message.id); - if (message.result) resolve(message.result);else reject(message.error); - } else { - if (message.method === 'Debugger.scriptParsed') { - const _message$params = message.params, - scriptId = _message$params.scriptId, - url = _message$params.url; - this._scriptsIdsByUrl.set(scriptId, url); - const fileUrl = url.startsWith('file:') ? url : pathToFileURL(url).toString(); - if (fileUrl === this.scriptURL().toString()) { - this.mainScriptId = scriptId; - } + _createClass(InspectorSession, [{ + key: "waitForServerDisconnect", + value: function waitForServerDisconnect() { + return this._terminationPromise; + } + }, { + key: "disconnect", + value: function () { + var _disconnect = _asyncToGenerator(function* () { + this._socket.destroy(); + return this.waitForServerDisconnect(); + }); + function disconnect() { + return _disconnect.apply(this, arguments); } - if (this._notificationCallback) { - // In case callback needs to install another - const callback = this._notificationCallback; - this._notificationCallback = null; - callback(message); + return disconnect; + }() + }, { + key: "_onMessage", + value: function _onMessage(message) { + if (message.id) { + var _this$_commandRespons = this._commandResponsePromises.get(message.id), + resolve = _this$_commandRespons.resolve, + reject = _this$_commandRespons.reject; + this._commandResponsePromises.delete(message.id); + if (message.result) resolve(message.result);else reject(message.error); } else { - this._unprocessedNotifications.push(message); + if (message.method === 'Debugger.scriptParsed') { + var _message$params = message.params, + scriptId = _message$params.scriptId, + url = _message$params.url; + this._scriptsIdsByUrl.set(scriptId, url); + var fileUrl = url.startsWith('file:') ? url : pathToFileURL(url).toString(); + if (fileUrl === this.scriptURL().toString()) { + this.mainScriptId = scriptId; + } + } + if (this._notificationCallback) { + // In case callback needs to install another + var callback = this._notificationCallback; + this._notificationCallback = null; + callback(message); + } else { + this._unprocessedNotifications.push(message); + } } } - } - _sendMessage(message) { - const msg = JSON.parse(JSON.stringify(message)); // Clone! - msg.id = this._nextId++; - if (DEBUG) console.log('[sent]', JSON.stringify(msg)); - const responsePromise = new Promise((resolve, reject) => { - this._commandResponsePromises.set(msg.id, { - resolve, - reject + }, { + key: "_sendMessage", + value: function _sendMessage(message) { + var _this2 = this; + var msg = JSON.parse(JSON.stringify(message)); // Clone! + msg.id = this._nextId++; + if (DEBUG) console.log('[sent]', JSON.stringify(msg)); + var responsePromise = new Promise(function (resolve, reject) { + _this2._commandResponsePromises.set(msg.id, { + resolve: resolve, + reject: reject + }); + }); + return new Promise(function (resolve) { + return _this2._socket.write(formatWSFrame(msg), resolve); + }).then(function () { + return responsePromise; }); - }); - return new Promise(resolve => this._socket.write(formatWSFrame(msg), resolve)).then(() => responsePromise); - } - send(commands) { - if (Array.isArray(commands)) { - // Multiple commands means the response does not matter. There might even - // never be a response. - return Promise.all(commands.map(command => this._sendMessage(command))).then(() => {}); - } else { - return this._sendMessage(commands); } - } - waitForNotification(methodOrPredicate, description) { - const desc = description || methodOrPredicate; - const message = `Timed out waiting for matching notification (${desc}))`; - return fires(this._asyncWaitForNotification(methodOrPredicate), message, TIMEOUT); - } - _asyncWaitForNotification(methodOrPredicate) { - var _this2 = this; - return _asyncToGenerator(function* () { - function matchMethod(notification) { - return notification.method === methodOrPredicate; + }, { + key: "send", + value: function send(commands) { + var _this3 = this; + if (Array.isArray(commands)) { + // Multiple commands means the response does not matter. There might even + // never be a response. + return Promise.all(commands.map(function (command) { + return _this3._sendMessage(command); + })).then(function () {}); + } else { + return this._sendMessage(commands); } - const predicate = typeof methodOrPredicate === 'string' ? matchMethod : methodOrPredicate; - let notification = null; - do { - if (_this2._unprocessedNotifications.length) { - notification = _this2._unprocessedNotifications.shift(); - } else { - notification = yield new Promise(resolve => _this2._notificationCallback = resolve); + } + }, { + key: "waitForNotification", + value: function waitForNotification(methodOrPredicate, description) { + var desc = description || methodOrPredicate; + var message = "Timed out waiting for matching notification (".concat(desc, "))"); + return fires(this._asyncWaitForNotification(methodOrPredicate), message, TIMEOUT); + } + }, { + key: "_asyncWaitForNotification", + value: function () { + var _asyncWaitForNotification2 = _asyncToGenerator(function* (methodOrPredicate) { + var _this4 = this; + function matchMethod(notification) { + return notification.method === methodOrPredicate; } - } while (!predicate(notification)); - return notification; - })(); - } - _isBreakOnLineNotification(message, line, expectedScriptPath) { - if (message.method === 'Debugger.paused') { - const callFrame = message.params.callFrames[0]; - const location = callFrame.location; - const scriptPath = this._scriptsIdsByUrl.get(location.scriptId); - assert.strictEqual(scriptPath.toString(), expectedScriptPath.toString(), `${scriptPath} !== ${expectedScriptPath}`); - assert.strictEqual(location.lineNumber, line); - return true; + var predicate = typeof methodOrPredicate === 'string' ? matchMethod : methodOrPredicate; + var notification = null; + do { + if (this._unprocessedNotifications.length) { + notification = this._unprocessedNotifications.shift(); + } else { + notification = yield new Promise(function (resolve) { + return _this4._notificationCallback = resolve; + }); + } + } while (!predicate(notification)); + return notification; + }); + function _asyncWaitForNotification(_x) { + return _asyncWaitForNotification2.apply(this, arguments); + } + return _asyncWaitForNotification; + }() + }, { + key: "_isBreakOnLineNotification", + value: function _isBreakOnLineNotification(message, line, expectedScriptPath) { + if (message.method === 'Debugger.paused') { + var callFrame = message.params.callFrames[0]; + var location = callFrame.location; + var scriptPath = this._scriptsIdsByUrl.get(location.scriptId); + assert.strictEqual(scriptPath.toString(), expectedScriptPath.toString(), "".concat(scriptPath, " !== ").concat(expectedScriptPath)); + assert.strictEqual(location.lineNumber, line); + return true; + } } - } - waitForBreakOnLine(line, url) { - return this.waitForNotification(notification => this._isBreakOnLineNotification(notification, line, url), `break on ${url}:${line}`); - } - _matchesConsoleOutputNotification(notification, type, values) { - if (!Array.isArray(values)) values = [values]; - if (notification.method === 'Runtime.consoleAPICalled') { - const params = notification.params; - if (params.type === type) { - let i = 0; - var _iterator2 = _createForOfIteratorHelper(params.args), - _step2; - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - const value = _step2.value; - if (value.value !== values[i++]) return false; + }, { + key: "waitForBreakOnLine", + value: function waitForBreakOnLine(line, url) { + var _this5 = this; + return this.waitForNotification(function (notification) { + return _this5._isBreakOnLineNotification(notification, line, url); + }, "break on ".concat(url, ":").concat(line)); + } + }, { + key: "_matchesConsoleOutputNotification", + value: function _matchesConsoleOutputNotification(notification, type, values) { + if (!Array.isArray(values)) values = [values]; + if (notification.method === 'Runtime.consoleAPICalled') { + var params = notification.params; + if (params.type === type) { + var _i2 = 0; + var _iterator2 = _createForOfIteratorHelper(params.args), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var value = _step2.value; + if (value.value !== values[_i2++]) return false; + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); + return _i2 === values.length; } - return i === values.length; } } - } - waitForConsoleOutput(type, values) { - const desc = `Console output matching ${JSON.stringify(values)}`; - return this.waitForNotification(notification => this._matchesConsoleOutputNotification(notification, type, values), desc); - } - runToCompletion() { - var _this3 = this; - return _asyncToGenerator(function* () { - console.log('[test]', 'Verify node waits for the frontend to disconnect'); - yield _this3.send({ - 'method': 'Debugger.resume' - }); - yield _this3.waitForNotification(notification => { - return notification.method === 'Runtime.executionContextDestroyed' && notification.params.executionContextId === 1; + }, { + key: "waitForConsoleOutput", + value: function waitForConsoleOutput(type, values) { + var _this6 = this; + var desc = "Console output matching ".concat(JSON.stringify(values)); + return this.waitForNotification(function (notification) { + return _this6._matchesConsoleOutputNotification(notification, type, values); + }, desc); + } + }, { + key: "runToCompletion", + value: function () { + var _runToCompletion = _asyncToGenerator(function* () { + console.log('[test]', 'Verify node waits for the frontend to disconnect'); + yield this.send({ + 'method': 'Debugger.resume' + }); + yield this.waitForNotification(function (notification) { + return notification.method === 'Runtime.executionContextDestroyed' && notification.params.executionContextId === 1; + }); + while ((yield this._instance.nextStderrString()) !== 'Waiting for the debugger to disconnect...'); + yield this.disconnect(); }); - while ((yield _this3._instance.nextStderrString()) !== 'Waiting for the debugger to disconnect...'); - yield _this3.disconnect(); - })(); - } - scriptPath() { - return this._instance.scriptPath(); - } - script() { - return this._instance.script(); - } - scriptURL() { - return pathToFileURL(this.scriptPath()); - } -} -class NodeInstance extends EventEmitter { - constructor() { - let inspectorFlags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['--inspect-brk=0']; - let scriptContents = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; - let scriptFile = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _MAINSCRIPT; - super(); - this._scriptPath = scriptFile; - this._script = scriptFile ? null : scriptContents; - this._portCallback = null; - this.portPromise = new Promise(resolve => this._portCallback = resolve); - this._process = spawnChildProcess(inspectorFlags, scriptContents, scriptFile); - this._running = true; - this._stderrLineCallback = null; - this._unprocessedStderrLines = []; - this._process.stdout.on('data', makeBufferingDataCallback(line => { - this.emit('stdout', line); + function runToCompletion() { + return _runToCompletion.apply(this, arguments); + } + return runToCompletion; + }() + }, { + key: "scriptPath", + value: function scriptPath() { + return this._instance.scriptPath(); + } + }, { + key: "script", + value: function script() { + return this._instance.script(); + } + }, { + key: "scriptURL", + value: function scriptURL() { + return pathToFileURL(this.scriptPath()); + } + }]); + return InspectorSession; +}(); +var NodeInstance = /*#__PURE__*/function (_EventEmitter) { + _inherits(NodeInstance, _EventEmitter); + var _super = _createSuper(NodeInstance); + function NodeInstance() { + var _this7; + var inspectorFlags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['--inspect-brk=0']; + var scriptContents = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; + var scriptFile = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _MAINSCRIPT; + _classCallCheck(this, NodeInstance); + _this7 = _super.call(this); + _this7._scriptPath = scriptFile; + _this7._script = scriptFile ? null : scriptContents; + _this7._portCallback = null; + _this7.portPromise = new Promise(function (resolve) { + return _this7._portCallback = resolve; + }); + _this7._process = spawnChildProcess(inspectorFlags, scriptContents, scriptFile); + _this7._running = true; + _this7._stderrLineCallback = null; + _this7._unprocessedStderrLines = []; + _this7._process.stdout.on('data', makeBufferingDataCallback(function (line) { + _this7.emit('stdout', line); console.log('[out]', line); })); - this._process.stderr.on('data', makeBufferingDataCallback(message => this.onStderrLine(message))); - this._shutdownPromise = new Promise(resolve => { - this._process.once('exit', (exitCode, signal) => { + _this7._process.stderr.on('data', makeBufferingDataCallback(function (message) { + return _this7.onStderrLine(message); + })); + _this7._shutdownPromise = new Promise(function (resolve) { + _this7._process.once('exit', function (exitCode, signal) { resolve({ - exitCode, - signal + exitCode: exitCode, + signal: signal }); - this._running = false; + _this7._running = false; }); }); - } - static startViaSignal(scriptContents) { - return _asyncToGenerator(function* () { - const instance = new NodeInstance([], `${scriptContents}\nprocess._rawDebug('started');`, undefined); - const msg = 'Timed out waiting for process to start'; - while ((yield fires(instance.nextStderrString(), msg, TIMEOUT)) !== 'started') {} - process._debugProcess(instance._process.pid); - return instance; - })(); - } - onStderrLine(line) { - console.log('[err]', line); - if (this._portCallback) { - const matches = line.match(/Debugger listening on ws:\/\/.+:(\d+)\/.+/); - if (matches) { - this._portCallback(matches[1]); - this._portCallback = null; + return _this7; + } + _createClass(NodeInstance, [{ + key: "onStderrLine", + value: function onStderrLine(line) { + console.log('[err]', line); + if (this._portCallback) { + var matches = line.match(/Debugger listening on ws:\/\/.+:(\d+)\/.+/); + if (matches) { + this._portCallback(matches[1]); + this._portCallback = null; + } + } + if (this._stderrLineCallback) { + this._stderrLineCallback(line); + this._stderrLineCallback = null; + } else { + this._unprocessedStderrLines.push(line); } } - if (this._stderrLineCallback) { - this._stderrLineCallback(line); - this._stderrLineCallback = null; - } else { - this._unprocessedStderrLines.push(line); + }, { + key: "httpGet", + value: function httpGet(host, path, hostHeaderValue) { + console.log('[test]', "Testing ".concat(path)); + var headers = hostHeaderValue ? { + 'Host': hostHeaderValue + } : null; + return this.portPromise.then(function (port) { + return new Promise(function (resolve, reject) { + var req = http.get({ + host: host, + port: port, + path: path, + headers: headers + }, function (res) { + var response = ''; + res.setEncoding('utf8'); + res.on('data', function (data) { + return response += data.toString(); + }).on('end', function () { + resolve(response); + }); + }); + req.on('error', reject); + }); + }).then(function (response) { + try { + return JSON.parse(response); + } catch (e) { + e.body = response; + throw e; + } + }); } - } - httpGet(host, path, hostHeaderValue) { - console.log('[test]', `Testing ${path}`); - const headers = hostHeaderValue ? { - 'Host': hostHeaderValue - } : null; - return this.portPromise.then(port => new Promise((resolve, reject) => { - const req = http.get({ - host, - port, - path, - headers - }, res => { - let response = ''; - res.setEncoding('utf8'); - res.on('data', data => response += data.toString()).on('end', () => { - resolve(response); + }, { + key: "sendUpgradeRequest", + value: function () { + var _sendUpgradeRequest = _asyncToGenerator(function* () { + var response = yield this.httpGet(null, '/json/list'); + var devtoolsUrl = response[0].webSocketDebuggerUrl; + var port = yield this.portPromise; + return http.get({ + port: port, + path: parseURL(devtoolsUrl).path, + headers: { + 'Connection': 'Upgrade', + 'Upgrade': 'websocket', + 'Sec-WebSocket-Version': 13, + 'Sec-WebSocket-Key': 'key==' + } }); }); - req.on('error', reject); - })).then(response => { - try { - return JSON.parse(response); - } catch (e) { - e.body = response; - throw e; + function sendUpgradeRequest() { + return _sendUpgradeRequest.apply(this, arguments); } - }); - } - sendUpgradeRequest() { - var _this4 = this; - return _asyncToGenerator(function* () { - const response = yield _this4.httpGet(null, '/json/list'); - const devtoolsUrl = response[0].webSocketDebuggerUrl; - const port = yield _this4.portPromise; - return http.get({ - port, - path: parseURL(devtoolsUrl).path, - headers: { - 'Connection': 'Upgrade', - 'Upgrade': 'websocket', - 'Sec-WebSocket-Version': 13, - 'Sec-WebSocket-Key': 'key==' - } + return sendUpgradeRequest; + }() + }, { + key: "connectInspectorSession", + value: function () { + var _connectInspectorSession = _asyncToGenerator(function* () { + var _this8 = this; + console.log('[test]', 'Connecting to a child Node process'); + var upgradeRequest = yield this.sendUpgradeRequest(); + return new Promise(function (resolve) { + upgradeRequest.on('upgrade', function (message, socket) { + return resolve(new InspectorSession(socket, _this8)); + }).on('response', common.mustNotCall('Upgrade was not received')); + }); }); - })(); - } - connectInspectorSession() { - var _this5 = this; - return _asyncToGenerator(function* () { - console.log('[test]', 'Connecting to a child Node process'); - const upgradeRequest = yield _this5.sendUpgradeRequest(); - return new Promise(resolve => { - upgradeRequest.on('upgrade', (message, socket) => resolve(new InspectorSession(socket, _this5))).on('response', common.mustNotCall('Upgrade was not received')); + function connectInspectorSession() { + return _connectInspectorSession.apply(this, arguments); + } + return connectInspectorSession; + }() + }, { + key: "expectConnectionDeclined", + value: function () { + var _expectConnectionDeclined = _asyncToGenerator(function* () { + console.log('[test]', 'Checking upgrade is not possible'); + var upgradeRequest = yield this.sendUpgradeRequest(); + return new Promise(function (resolve) { + upgradeRequest.on('upgrade', common.mustNotCall('Upgrade was received')).on('response', function (response) { + return response.on('data', function () {}).on('end', function () { + return resolve(response.statusCode); + }); + }); + }); }); - })(); - } - expectConnectionDeclined() { - var _this6 = this; - return _asyncToGenerator(function* () { - console.log('[test]', 'Checking upgrade is not possible'); - const upgradeRequest = yield _this6.sendUpgradeRequest(); - return new Promise(resolve => { - upgradeRequest.on('upgrade', common.mustNotCall('Upgrade was received')).on('response', response => response.on('data', () => {}).on('end', () => resolve(response.statusCode))); + function expectConnectionDeclined() { + return _expectConnectionDeclined.apply(this, arguments); + } + return expectConnectionDeclined; + }() + }, { + key: "expectShutdown", + value: function expectShutdown() { + return this._shutdownPromise; + } + }, { + key: "nextStderrString", + value: function nextStderrString() { + var _this9 = this; + if (this._unprocessedStderrLines.length) return Promise.resolve(this._unprocessedStderrLines.shift()); + return new Promise(function (resolve) { + return _this9._stderrLineCallback = resolve; }); - })(); - } - expectShutdown() { - return this._shutdownPromise; - } - nextStderrString() { - if (this._unprocessedStderrLines.length) return Promise.resolve(this._unprocessedStderrLines.shift()); - return new Promise(resolve => this._stderrLineCallback = resolve); - } - write(message) { - this._process.stdin.write(message); - } - kill() { - this._process.kill(); - return this.expectShutdown(); - } - scriptPath() { - return this._scriptPath; - } - script() { - if (this._script === null) this._script = fs.readFileSync(this.scriptPath(), 'utf8'); - return this._script; - } -} + } + }, { + key: "write", + value: function write(message) { + this._process.stdin.write(message); + } + }, { + key: "kill", + value: function kill() { + this._process.kill(); + return this.expectShutdown(); + } + }, { + key: "scriptPath", + value: function scriptPath() { + return this._scriptPath; + } + }, { + key: "script", + value: function script() { + if (this._script === null) this._script = fs.readFileSync(this.scriptPath(), 'utf8'); + return this._script; + } + }], [{ + key: "startViaSignal", + value: function () { + var _startViaSignal = _asyncToGenerator(function* (scriptContents) { + var instance = new NodeInstance([], "".concat(scriptContents, "\nprocess._rawDebug('started');"), undefined); + var msg = 'Timed out waiting for process to start'; + while ((yield fires(instance.nextStderrString(), msg, TIMEOUT)) !== 'started') {} + process._debugProcess(instance._process.pid); + return instance; + }); + function startViaSignal(_x2) { + return _startViaSignal.apply(this, arguments); + } + return startViaSignal; + }() + }]); + return NodeInstance; +}(EventEmitter); function onResolvedOrRejected(promise, callback) { - return promise.then(result => { + return promise.then(function (result) { callback(); return result; - }, error => { + }, function (error) { callback(); throw error; }); } function timeoutPromise(error, timeoutMs) { - let clearCallback = null; - let done = false; - const promise = onResolvedOrRejected(new Promise((resolve, reject) => { - const timeout = setTimeout(() => reject(error), timeoutMs); - clearCallback = () => { + var clearCallback = null; + var done = false; + var promise = onResolvedOrRejected(new Promise(function (resolve, reject) { + var timeout = setTimeout(function () { + return reject(error); + }, timeoutMs); + clearCallback = function clearCallback() { if (done) return; clearTimeout(timeout); resolve(); }; - }), () => done = true); + }), function () { + return done = true; + }); promise.clear = clearCallback; return promise; } @@ -492,11 +630,13 @@ function timeoutPromise(error, timeoutMs) { // if that happens within the `timeoutMs` timespan, or rejects with `error` as // a reason otherwise. function fires(promise, error, timeoutMs) { - const timeout = timeoutPromise(error, timeoutMs); - return Promise.race([onResolvedOrRejected(promise, () => timeout.clear()), timeout]); + var timeout = timeoutPromise(error, timeoutMs); + return Promise.race([onResolvedOrRejected(promise, function () { + return timeout.clear(); + }), timeout]); } module.exports = { - NodeInstance + NodeInstance: NodeInstance }; function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { diff --git a/test/common/internet.js b/test/common/internet.js index 7df668275..99c132e27 100644 --- a/test/common/internet.js +++ b/test/common/internet.js @@ -20,7 +20,7 @@ var objectKeys = objectKeys || function (obj) { // Utilities for internet-related tests -const addresses = { +var addresses = { // A generic host that has registered common DNS records, // supports both IPv4 and IPv6, and provides basic HTTP/HTTPS services INET_HOST: 'nodejs.org', @@ -62,8 +62,8 @@ var _iterator = _createForOfIteratorHelper(objectKeys(addresses)), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { - const key = _step.value; - const envName = `NODE_TEST_${key}`; + var key = _step.value; + var envName = "NODE_TEST_".concat(key); if (process.env[envName]) { addresses[key] = process.env[envName]; } @@ -74,7 +74,7 @@ try { _iterator.f(); } module.exports = { - addresses + addresses: addresses }; function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { diff --git a/test/common/ongc.js b/test/common/ongc.js index 02f4c71da..3b2cd2a46 100644 --- a/test/common/ongc.js +++ b/test/common/ongc.js @@ -15,12 +15,12 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const common = require('../common'); -const assert = require('assert'); -const gcTrackerMap = new WeakMap(); -const gcTrackerTag = 'NODE_TEST_COMMON_GC_TRACKER'; +var common = require('../common'); +var assert = require('assert'); +var gcTrackerMap = new WeakMap(); +var gcTrackerTag = 'NODE_TEST_COMMON_GC_TRACKER'; function onGC(obj, gcListener) { - const async_hooks = + var async_hooks = /*require('async_hooks'); const onGcAsyncHook = async_hooks.createHook({ init: common.mustCallAtLeast(function(id, type) { diff --git a/test/common/shared-lib-util.js b/test/common/shared-lib-util.js index eabd47600..353da267a 100644 --- a/test/common/shared-lib-util.js +++ b/test/common/shared-lib-util.js @@ -15,11 +15,11 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const common = require('../common'); -const path = require('path'); -const kNodeShared = Boolean(process.config.variables.node_shared); -const kShlibSuffix = process.config.variables.shlib_suffix; -const kExecPath = path.dirname(process.execPath); +var common = require('../common'); +var path = require('path'); +var kNodeShared = Boolean(process.config.variables.node_shared); +var kShlibSuffix = process.config.variables.shlib_suffix; +var kExecPath = path.dirname(process.execPath); // If node executable is linked to shared lib, need to take care about the // shared lib path. @@ -42,9 +42,9 @@ function getSharedLibPath() { if (common.isWindows) { return path.join(kExecPath, 'node.dll'); } else if (common.isOSX) { - return path.join(kExecPath, `libnode.${kShlibSuffix}`); + return path.join(kExecPath, "libnode.".concat(kShlibSuffix)); } else { - return path.join(kExecPath, 'lib.target', `libnode.${kShlibSuffix}`); + return path.join(kExecPath, 'lib.target', "libnode.".concat(kShlibSuffix)); } } @@ -53,9 +53,9 @@ function getBinaryPath() { return kNodeShared ? getSharedLibPath() : process.execPath; } module.exports = { - addLibraryPath, - getBinaryPath, - getSharedLibPath + addLibraryPath: addLibraryPath, + getBinaryPath: getBinaryPath, + getSharedLibPath: getSharedLibPath }; function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { diff --git a/test/common/tls.js b/test/common/tls.js index 6f54c23b1..8f87816db 100644 --- a/test/common/tls.js +++ b/test/common/tls.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**/ require('@babel/polyfill'); var util = require('util'); @@ -16,138 +28,159 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const crypto = require('crypto'); -const net = require('net'); +var crypto = require('crypto'); +var net = require('net'); exports.ccs = Buffer.from('140303000101', 'hex'); -class TestTLSSocket extends net.Socket { - constructor(server_cert) { - super(); - this.server_cert = server_cert; - this.version = Buffer.from('0303', 'hex'); - this.handshake_list = []; +var TestTLSSocket = /*#__PURE__*/function (_net$Socket) { + _inherits(TestTLSSocket, _net$Socket); + var _super = _createSuper(TestTLSSocket); + function TestTLSSocket(server_cert) { + var _this; + _classCallCheck(this, TestTLSSocket); + _this = _super.call(this); + _this.server_cert = server_cert; + _this.version = Buffer.from('0303', 'hex'); + _this.handshake_list = []; // AES128-GCM-SHA256 - this.ciphers = Buffer.from('000002009c0', 'hex'); - this.pre_master_secret = Buffer.concat([this.version, crypto.randomBytes(46)]); - this.master_secret = null; - this.write_seq = 0; - this.client_random = crypto.randomBytes(32); - this.on('handshake', msg => { - this.handshake_list.push(msg); + _this.ciphers = Buffer.from('000002009c0', 'hex'); + _this.pre_master_secret = Buffer.concat([_this.version, crypto.randomBytes(46)]); + _this.master_secret = null; + _this.write_seq = 0; + _this.client_random = crypto.randomBytes(32); + _this.on('handshake', function (msg) { + _this.handshake_list.push(msg); }); - this.on('server_random', server_random => { - this.master_secret = PRF12('sha256', this.pre_master_secret, 'master secret', Buffer.concat([this.client_random, server_random]), 48); - const key_block = PRF12('sha256', this.master_secret, 'key expansion', Buffer.concat([server_random, this.client_random]), 40); - this.client_writeKey = key_block.slice(0, 16); - this.client_writeIV = key_block.slice(32, 36); + _this.on('server_random', function (server_random) { + _this.master_secret = PRF12('sha256', _this.pre_master_secret, 'master secret', Buffer.concat([_this.client_random, server_random]), 48); + var key_block = PRF12('sha256', _this.master_secret, 'key expansion', Buffer.concat([server_random, _this.client_random]), 40); + _this.client_writeKey = key_block.slice(0, 16); + _this.client_writeIV = key_block.slice(32, 36); }); + return _this; } - createClientHello() { - const compressions = Buffer.from('0100', 'hex'); // null - const msg = addHandshakeHeader(0x01, Buffer.concat([this.version, this.client_random, this.ciphers, compressions])); - this.emit('handshake', msg); - return addRecordHeader(0x16, msg); - } - createClientKeyExchange() { - const encrypted_pre_master_secret = crypto.publicEncrypt({ - key: this.server_cert, - padding: crypto.constants.RSA_PKCS1_PADDING - }, this.pre_master_secret); - const length = Buffer.alloc(2); - length.writeUIntBE(encrypted_pre_master_secret.length, 0, 2); - const msg = addHandshakeHeader(0x10, Buffer.concat([length, encrypted_pre_master_secret])); - this.emit('handshake', msg); - return addRecordHeader(0x16, msg); - } - createFinished() { - const shasum = crypto.createHash('sha256'); - shasum.update(Buffer.concat(this.handshake_list)); - const message_hash = shasum.digest(); - const r = PRF12('sha256', this.master_secret, 'client finished', message_hash, 12); - const msg = addHandshakeHeader(0x14, r); - this.emit('handshake', msg); - return addRecordHeader(0x16, msg); - } - createIllegalHandshake() { - const illegal_handshake = Buffer.alloc(5); - return addRecordHeader(0x16, illegal_handshake); - } - parseTLSFrame(buf) { - let offset = 0; - const record = buf.slice(offset, 5); - const type = record[0]; - const length = record.slice(3, 5).readUInt16BE(0); - offset += 5; - let remaining = buf.slice(offset, offset + length); - if (type === 0x16) { - do { - remaining = this.parseTLSHandshake(remaining); - } while (remaining.length > 0); + _createClass(TestTLSSocket, [{ + key: "createClientHello", + value: function createClientHello() { + var compressions = Buffer.from('0100', 'hex'); // null + var msg = addHandshakeHeader(0x01, Buffer.concat([this.version, this.client_random, this.ciphers, compressions])); + this.emit('handshake', msg); + return addRecordHeader(0x16, msg); } - offset += length; - return buf.slice(offset); - } - parseTLSHandshake(buf) { - let offset = 0; - const handshake_type = buf[offset]; - if (handshake_type === 0x02) { - const server_random = buf.slice(6, 6 + 32); - this.emit('server_random', server_random); + }, { + key: "createClientKeyExchange", + value: function createClientKeyExchange() { + var encrypted_pre_master_secret = crypto.publicEncrypt({ + key: this.server_cert, + padding: crypto.constants.RSA_PKCS1_PADDING + }, this.pre_master_secret); + var length = Buffer.alloc(2); + length.writeUIntBE(encrypted_pre_master_secret.length, 0, 2); + var msg = addHandshakeHeader(0x10, Buffer.concat([length, encrypted_pre_master_secret])); + this.emit('handshake', msg); + return addRecordHeader(0x16, msg); } - offset += 1; - const length = buf.readUIntBE(offset, 3); - offset += 3; - const handshake = buf.slice(0, offset + length); - this.emit('handshake', handshake); - offset += length; - const remaining = buf.slice(offset); - return remaining; - } - encrypt(plain) { - const type = plain.slice(0, 1); - const version = plain.slice(1, 3); - const nonce = crypto.randomBytes(8); - const iv = Buffer.concat([this.client_writeIV.slice(0, 4), nonce]); - const bob = crypto.createCipheriv('aes-128-gcm', this.client_writeKey, iv); - const write_seq = Buffer.alloc(8); - write_seq.writeUInt32BE(this.write_seq++, 4); - const aad = Buffer.concat([write_seq, plain.slice(0, 5)]); - bob.setAAD(aad); - const encrypted1 = bob.update(plain.slice(5)); - const encrypted = Buffer.concat([encrypted1, bob.final()]); - const tag = bob.getAuthTag(); - const length = Buffer.alloc(2); - length.writeUInt16BE(nonce.length + encrypted.length + tag.length, 0); - return Buffer.concat([type, version, length, nonce, encrypted, tag]); - } -} + }, { + key: "createFinished", + value: function createFinished() { + var shasum = crypto.createHash('sha256'); + shasum.update(Buffer.concat(this.handshake_list)); + var message_hash = shasum.digest(); + var r = PRF12('sha256', this.master_secret, 'client finished', message_hash, 12); + var msg = addHandshakeHeader(0x14, r); + this.emit('handshake', msg); + return addRecordHeader(0x16, msg); + } + }, { + key: "createIllegalHandshake", + value: function createIllegalHandshake() { + var illegal_handshake = Buffer.alloc(5); + return addRecordHeader(0x16, illegal_handshake); + } + }, { + key: "parseTLSFrame", + value: function parseTLSFrame(buf) { + var offset = 0; + var record = buf.slice(offset, 5); + var type = record[0]; + var length = record.slice(3, 5).readUInt16BE(0); + offset += 5; + var remaining = buf.slice(offset, offset + length); + if (type === 0x16) { + do { + remaining = this.parseTLSHandshake(remaining); + } while (remaining.length > 0); + } + offset += length; + return buf.slice(offset); + } + }, { + key: "parseTLSHandshake", + value: function parseTLSHandshake(buf) { + var offset = 0; + var handshake_type = buf[offset]; + if (handshake_type === 0x02) { + var server_random = buf.slice(6, 6 + 32); + this.emit('server_random', server_random); + } + offset += 1; + var length = buf.readUIntBE(offset, 3); + offset += 3; + var handshake = buf.slice(0, offset + length); + this.emit('handshake', handshake); + offset += length; + var remaining = buf.slice(offset); + return remaining; + } + }, { + key: "encrypt", + value: function encrypt(plain) { + var type = plain.slice(0, 1); + var version = plain.slice(1, 3); + var nonce = crypto.randomBytes(8); + var iv = Buffer.concat([this.client_writeIV.slice(0, 4), nonce]); + var bob = crypto.createCipheriv('aes-128-gcm', this.client_writeKey, iv); + var write_seq = Buffer.alloc(8); + write_seq.writeUInt32BE(this.write_seq++, 4); + var aad = Buffer.concat([write_seq, plain.slice(0, 5)]); + bob.setAAD(aad); + var encrypted1 = bob.update(plain.slice(5)); + var encrypted = Buffer.concat([encrypted1, bob.final()]); + var tag = bob.getAuthTag(); + var length = Buffer.alloc(2); + length.writeUInt16BE(nonce.length + encrypted.length + tag.length, 0); + return Buffer.concat([type, version, length, nonce, encrypted, tag]); + } + }]); + return TestTLSSocket; +}(net.Socket); function addRecordHeader(type, frame) { - const record_layer = Buffer.from('0003030000', 'hex'); + var record_layer = Buffer.from('0003030000', 'hex'); record_layer[0] = type; record_layer.writeUInt16BE(frame.length, 3); return Buffer.concat([record_layer, frame]); } function addHandshakeHeader(type, msg) { - const handshake_header = Buffer.alloc(4); + var handshake_header = Buffer.alloc(4); handshake_header[0] = type; handshake_header.writeUIntBE(msg.length, 1, 3); return Buffer.concat([handshake_header, msg]); } function PRF12(algo, secret, label, seed, size) { - const newSeed = Buffer.concat([Buffer.from(label, 'utf8'), seed]); + var newSeed = Buffer.concat([Buffer.from(label, 'utf8'), seed]); return P_hash(algo, secret, newSeed, size); } function P_hash(algo, secret, seed, size) { - const result = Buffer.alloc(size); - let hmac = crypto.createHmac(algo, secret); + var result = Buffer.alloc(size); + var hmac = crypto.createHmac(algo, secret); hmac.update(seed); - let a = hmac.digest(); - let j = 0; + var a = hmac.digest(); + var j = 0; while (j < size) { hmac = crypto.createHmac(algo, secret); hmac.update(a); hmac.update(seed); - const b = hmac.digest(); - let todo = b.length; + var b = hmac.digest(); + var todo = b.length; if (j + todo > size) { todo = size - j; } diff --git a/test/common/tmpdir.js b/test/common/tmpdir.js index 9c36a2378..200d624db 100644 --- a/test/common/tmpdir.js +++ b/test/common/tmpdir.js @@ -15,10 +15,10 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const fs = require('fs'); -const path = require('path'); +var fs = require('fs'); +var path = require('path'); function rimrafSync(p) { - let st; + var st; try { st = fs.lstatSync(p); } catch (e) { @@ -39,10 +39,10 @@ function rmdirSync(p, originalEr) { } catch (e) { if (e.code === 'ENOTDIR') throw originalEr; if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') { - const enc = process.platform === 'linux' ? 'buffer' : 'utf8'; - forEach(fs.readdirSync(p, enc), f => { + var enc = process.platform === 'linux' ? 'buffer' : 'utf8'; + forEach(fs.readdirSync(p, enc), function (f) { if (f instanceof Buffer) { - const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); + var buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); rimrafSync(buf); } else { rimrafSync(path.join(p, f)); @@ -52,22 +52,22 @@ function rmdirSync(p, originalEr) { } } } -const testRoot = process.env.NODE_TEST_DIR ? fs.realpathSync(process.env.NODE_TEST_DIR) : path.resolve(__dirname, '..'); +var testRoot = process.env.NODE_TEST_DIR ? fs.realpathSync(process.env.NODE_TEST_DIR) : path.resolve(__dirname, '..'); // Using a `.` prefixed name, which is the convention for "hidden" on POSIX, // gets tools to ignore it by default or by simple rules, especially eslint. -let tmpdirName = '.tmp'; +var tmpdirName = '.tmp'; if (process.env.TEST_THREAD_ID) { - tmpdirName += `.${process.env.TEST_THREAD_ID}`; + tmpdirName += ".".concat(process.env.TEST_THREAD_ID); } -const tmpPath = path.join(testRoot, tmpdirName); +var tmpPath = path.join(testRoot, tmpdirName); function refresh() { rimrafSync(this.path); fs.mkdirSync(this.path); } module.exports = { path: tmpPath, - refresh + refresh: refresh }; function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { diff --git a/test/common/wpt.js b/test/common/wpt.js index 9b90e8047..e71e5fdf5 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -15,29 +15,33 @@ var objectKeys = objectKeys || function (obj) { }; /**/ -const assert = require('assert'); +var assert = require('assert'); // https://github.com/w3c/testharness.js/blob/master/testharness.js module.exports = { - test: (fn, desc) => { + test: function test(fn, desc) { try { fn(); } catch (err) { - console.error(`In ${desc}:`); + console.error("In ".concat(desc, ":")); throw err; } }, assert_equals: assert.strictEqual, - assert_true: (value, message) => assert.strictEqual(value, true, message), - assert_false: (value, message) => assert.strictEqual(value, false, message), - assert_throws: (code, func, desc) => { + assert_true: function assert_true(value, message) { + return assert.strictEqual(value, true, message); + }, + assert_false: function assert_false(value, message) { + return assert.strictEqual(value, false, message); + }, + assert_throws: function assert_throws(code, func, desc) { assert.throws(func, function (err) { return typeof err === 'object' && 'name' in err && err.name.startsWith(code.name); }, desc); }, assert_array_equals: assert.deepStrictEqual, - assert_unreached(desc) { - assert.fail(`Reached unreachable code: ${desc}`); + assert_unreached: function assert_unreached(desc) { + assert.fail("Reached unreachable code: ".concat(desc)); } }; function forEach(xs, f) { diff --git a/test/parallel/test-readable-from.js b/test/parallel/test-readable-from.js index f1ead9c96..7cc50059b 100644 --- a/test/parallel/test-readable-from.js +++ b/test/parallel/test-readable-from.js @@ -10,15 +10,15 @@ function _OverloadYield(value, kind) { this.v = value, this.k = kind; } function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); } function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function _return(value) { var ret = this.s.return; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, throw: function _throw(value) { var thr = this.s.return; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); } /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const _require = require('../common'), +var _require = require('../common'), mustCall = _require.mustCall; -const once = require('events.once'); -const _require2 = require('../../'), +var once = require('events.once'); +var _require2 = require('../../'), Readable = _require2.Readable; -const _require3 = require('assert/'), +var _require3 = require('assert/'), strictEqual = _require3.strictEqual; function toReadableBasicSupport() { return _toReadableBasicSupport.apply(this, arguments); @@ -36,14 +36,14 @@ function _toReadableBasicSupport() { }); return _generate.apply(this, arguments); } - const stream = Readable.from(generate()); - const expected = ['a', 'b', 'c']; + var stream = Readable.from(generate()); + var expected = ['a', 'b', 'c']; var _iteratorAbruptCompletion = false; var _didIteratorError = false; var _iteratorError; try { for (var _iterator = _asyncIterator(stream), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) { - const chunk = _step.value; + var chunk = _step.value; { strictEqual(chunk, expected.shift()); } @@ -75,14 +75,14 @@ function _toReadableSyncIterator() { yield 'b'; yield 'c'; } - const stream = Readable.from(generate()); - const expected = ['a', 'b', 'c']; + var stream = Readable.from(generate()); + var expected = ['a', 'b', 'c']; var _iteratorAbruptCompletion2 = false; var _didIteratorError2 = false; var _iteratorError2; try { for (var _iterator2 = _asyncIterator(stream), _step2; _iteratorAbruptCompletion2 = !(_step2 = yield _iterator2.next()).done; _iteratorAbruptCompletion2 = false) { - const chunk = _step2.value; + var chunk = _step2.value; { strictEqual(chunk, expected.shift()); } @@ -109,15 +109,15 @@ function toReadablePromises() { } function _toReadablePromises() { _toReadablePromises = _asyncToGenerator(function* () { - const promises = [Promise.resolve('a'), Promise.resolve('b'), Promise.resolve('c')]; - const stream = Readable.from(promises); - const expected = ['a', 'b', 'c']; + var promises = [Promise.resolve('a'), Promise.resolve('b'), Promise.resolve('c')]; + var stream = Readable.from(promises); + var expected = ['a', 'b', 'c']; var _iteratorAbruptCompletion3 = false; var _didIteratorError3 = false; var _iteratorError3; try { for (var _iterator3 = _asyncIterator(stream), _step3; _iteratorAbruptCompletion3 = !(_step3 = yield _iterator3.next()).done; _iteratorAbruptCompletion3 = false) { - const chunk = _step3.value; + var chunk = _step3.value; { strictEqual(chunk, expected.shift()); } @@ -144,14 +144,14 @@ function toReadableString() { } function _toReadableString() { _toReadableString = _asyncToGenerator(function* () { - const stream = Readable.from('abc'); - const expected = ['a', 'b', 'c']; + var stream = Readable.from('abc'); + var expected = ['a', 'b', 'c']; var _iteratorAbruptCompletion4 = false; var _didIteratorError4 = false; var _iteratorError4; try { for (var _iterator4 = _asyncIterator(stream), _step4; _iteratorAbruptCompletion4 = !(_step4 = yield _iterator4.next()).done; _iteratorAbruptCompletion4 = false) { - const chunk = _step4.value; + var chunk = _step4.value; { strictEqual(chunk, expected.shift()); } @@ -189,10 +189,10 @@ function _toReadableOnData() { }); return _generate2.apply(this, arguments); } - const stream = Readable.from(generate()); - let iterations = 0; - const expected = ['a', 'b', 'c']; - stream.on('data', chunk => { + var stream = Readable.from(generate()); + var iterations = 0; + var expected = ['a', 'b', 'c']; + stream.on('data', function (chunk) { iterations++; strictEqual(chunk, expected.shift()); }); @@ -217,12 +217,12 @@ function _toReadableOnDataNonObject() { }); return _generate3.apply(this, arguments); } - const stream = Readable.from(generate(), { + var stream = Readable.from(generate(), { objectMode: false }); - let iterations = 0; - const expected = ['a', 'b', 'c']; - stream.on('data', chunk => { + var iterations = 0; + var expected = ['a', 'b', 'c']; + stream.on('data', function (chunk) { iterations++; strictEqual(chunk instanceof Buffer, true); strictEqual(chunk.toString(), expected.shift()); @@ -246,7 +246,7 @@ function _destroysTheStreamWhenThrowing() { }); return _generate4.apply(this, arguments); } - const stream = Readable.from(generate()); + var stream = Readable.from(generate()); stream.read(); try { yield once(stream, 'error'); @@ -272,7 +272,7 @@ function _asTransformStream() { var _iteratorError6; try { for (var _iterator6 = _asyncIterator(stream), _step6; _iteratorAbruptCompletion6 = !(_step6 = yield _awaitAsyncGenerator(_iterator6.next())).done; _iteratorAbruptCompletion6 = false) { - const chunk = _step6.value; + var chunk = _step6.value; { yield chunk.toUpperCase(); } @@ -294,23 +294,23 @@ function _asTransformStream() { }); return _generate5.apply(this, arguments); } - const source = new Readable({ + var source = new Readable({ objectMode: true, - read() { + read: function read() { this.push('a'); this.push('b'); this.push('c'); this.push(null); } }); - const stream = Readable.from(generate(source)); - const expected = ['A', 'B', 'C']; + var stream = Readable.from(generate(source)); + var expected = ['A', 'B', 'C']; var _iteratorAbruptCompletion5 = false; var _didIteratorError5 = false; var _iteratorError5; try { for (var _iterator5 = _asyncIterator(stream), _step5; _iteratorAbruptCompletion5 = !(_step5 = yield _iterator5.next()).done; _iteratorAbruptCompletion5 = false) { - const chunk = _step5.value; + var chunk = _step5.value; { strictEqual(chunk, expected.shift()); } @@ -341,4 +341,6 @@ Promise.all([toReadableBasicSupport(), toReadableSyncIterator(), toReadablePromi var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-readable-large-hwm.js b/test/parallel/test-readable-large-hwm.js index 93e2cd6ca..6ef9b502b 100644 --- a/test/parallel/test-readable-large-hwm.js +++ b/test/parallel/test-readable-large-hwm.js @@ -1,18 +1,18 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable; // Make sure that readable completes // even when reading larger buffer. -const bufferSize = 10 * 1024 * 1024; -let n = 0; -const r = new Readable({ - read() { +var bufferSize = 10 * 1024 * 1024; +var n = 0; +var r = new Readable({ + read: function read() { // Try to fill readable buffer piece by piece. r.push(bufferShim.alloc(bufferSize / 10)); if (n++ > 10) { @@ -20,9 +20,9 @@ const r = new Readable({ } } }); -r.on('readable', () => { +r.on('readable', function () { while (true) { - const ret = r.read(bufferSize); + var ret = r.read(bufferSize); if (ret === null) break; } }); @@ -35,4 +35,6 @@ r.on('end', common.mustCall()); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-readable-single-end.js b/test/parallel/test-readable-single-end.js index 5b076db0a..e73bb6a9a 100644 --- a/test/parallel/test-readable-single-end.js +++ b/test/parallel/test-readable-single-end.js @@ -1,18 +1,18 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable; // This test ensures that there will not be an additional empty 'readable' // event when stream has ended (only 1 event signalling about end) -const r = new Readable({ - read: () => {} +var r = new Readable({ + read: function read() {} }); r.push(null); r.on('readable', common.mustCall()); @@ -25,4 +25,6 @@ r.on('end', common.mustCall()); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-auto-destroy.js b/test/parallel/test-stream-auto-destroy.js index 3f8c454fa..020366304 100644 --- a/test/parallel/test-stream-auto-destroy.js +++ b/test/parallel/test-stream-auto-destroy.js @@ -1,72 +1,78 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const assert = require('assert/'); +var common = require('../common'); +var stream = require('../../'); +var assert = require('assert/'); { - const r = new stream.Readable({ + var r = new stream.Readable({ autoDestroy: true, - read() { + read: function read() { this.push('hello'); this.push('world'); this.push(null); }, - destroy: common.mustCall((err, cb) => cb()) + destroy: common.mustCall(function (err, cb) { + return cb(); + }) }); - let ended = false; + var ended = false; r.resume(); - r.on('end', common.mustCall(() => { + r.on('end', common.mustCall(function () { ended = true; })); - r.on('close', common.mustCall(() => { + r.on('close', common.mustCall(function () { assert(ended); })); } { - const w = new stream.Writable({ + var w = new stream.Writable({ autoDestroy: true, - write(data, enc, cb) { + write: function write(data, enc, cb) { cb(null); }, - destroy: common.mustCall((err, cb) => cb()) + destroy: common.mustCall(function (err, cb) { + return cb(); + }) }); - let finished = false; + var finished = false; w.write('hello'); w.write('world'); w.end(); - w.on('finish', common.mustCall(() => { + w.on('finish', common.mustCall(function () { finished = true; })); - w.on('close', common.mustCall(() => { + w.on('close', common.mustCall(function () { assert(finished); })); } { - const t = new stream.Transform({ + var t = new stream.Transform({ autoDestroy: true, - transform(data, enc, cb) { + transform: function transform(data, enc, cb) { cb(null, data); }, - destroy: common.mustCall((err, cb) => cb()) + destroy: common.mustCall(function (err, cb) { + return cb(); + }) }); - let ended = false; - let finished = false; + var _ended = false; + var _finished = false; t.write('hello'); t.write('world'); t.end(); t.resume(); - t.on('end', common.mustCall(() => { - ended = true; + t.on('end', common.mustCall(function () { + _ended = true; })); - t.on('finish', common.mustCall(() => { - finished = true; + t.on('finish', common.mustCall(function () { + _finished = true; })); - t.on('close', common.mustCall(() => { - assert(ended); - assert(finished); + t.on('close', common.mustCall(function () { + assert(_ended); + assert(_finished); })); } ; @@ -77,4 +83,6 @@ const assert = require('assert/'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-backpressure.js b/test/parallel/test-stream-backpressure.js index 7aca31b4e..8caaeaed1 100644 --- a/test/parallel/test-stream-backpressure.js +++ b/test/parallel/test-stream-backpressure.js @@ -1,28 +1,28 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -let pushes = 0; -const total = 65500 + 40 * 1024; -const rs = new stream.Readable({ +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var pushes = 0; +var total = 65500 + 40 * 1024; +var rs = new stream.Readable({ read: common.mustCall(function () { if (pushes++ === 10) { this.push(null); return; } - const length = this._readableState.length; + var length = this._readableState.length; // We are at most doing two full runs of _reads // before stopping, because Readable is greedy // to keep its buffer full assert(length <= total); this.push(bufferShim.alloc(65500)); - for (let i = 0; i < 40; i++) { + for (var i = 0; i < 40; i++) { this.push(bufferShim.alloc(1024)); } @@ -30,7 +30,7 @@ const rs = new stream.Readable({ // but a new call to _read is scheduled anyway. }, 11) }); -const ws = stream.Writable({ +var ws = stream.Writable({ write: common.mustCall(function (data, enc, cb) { setImmediate(cb); }, 41 * 10) @@ -44,4 +44,6 @@ rs.pipe(ws); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-big-packet.js b/test/parallel/test-stream-big-packet.js index efb49462b..56962d9c5 100644 --- a/test/parallel/test-stream-big-packet.js +++ b/test/parallel/test-stream-big-packet.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,24 +34,34 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -let passed = false; -class TestStream extends stream.Transform { - _transform(chunk, encoding, done) { - if (!passed) { - // Char 'a' only exists in the last write - passed = chunk.toString().includes('a'); - } - done(); +var assert = require('assert/'); +var stream = require('../../'); +var passed = false; +var TestStream = /*#__PURE__*/function (_stream$Transform) { + _inherits(TestStream, _stream$Transform); + var _super = _createSuper(TestStream); + function TestStream() { + _classCallCheck(this, TestStream); + return _super.apply(this, arguments); } -} -const s1 = new stream.PassThrough(); -const s2 = new stream.PassThrough(); -const s3 = new TestStream(); + _createClass(TestStream, [{ + key: "_transform", + value: function _transform(chunk, encoding, done) { + if (!passed) { + // Char 'a' only exists in the last write + passed = chunk.toString().includes('a'); + } + done(); + } + }]); + return TestStream; +}(stream.Transform); +var s1 = new stream.PassThrough(); +var s2 = new stream.PassThrough(); +var s3 = new TestStream(); s1.pipe(s3); // Don't let s2 auto close which may close s3 s2.pipe(s3, { @@ -47,7 +69,7 @@ s2.pipe(s3, { }); // We must write a buffer larger than highWaterMark -const big = bufferShim.alloc(s1.writableHighWaterMark + 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)); @@ -76,4 +98,6 @@ function indexOf(xs, x) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-big-push.js b/test/parallel/test-stream-big-push.js index 513bd2d8c..4f9c6875d 100644 --- a/test/parallel/test-stream-big-push.js +++ b/test/parallel/test-stream-big-push.js @@ -22,26 +22,26 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const str = 'asdfasdfasdfasdfasdf'; -const r = new stream.Readable({ +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var str = 'asdfasdfasdfasdfasdf'; +var r = new stream.Readable({ highWaterMark: 5, encoding: 'utf8' }); -let reads = 0; +var reads = 0; function _read() { if (reads === 0) { - setTimeout(() => { + setTimeout(function () { r.push(str); }, 1); reads++; } else if (reads === 1) { - const ret = r.push(str); - assert.strictEqual(ret, false); + var _ret = r.push(str); + assert.strictEqual(_ret, false); reads++; } else { r.push(null); @@ -52,14 +52,14 @@ r.on('end', common.mustCall()); // push some data in to start. // we've never gotten any read event at this point. -const ret = r.push(str); +var ret = r.push(str); // should be false. > hwm assert(!ret); -let chunk = r.read(); +var chunk = r.read(); assert.strictEqual(chunk, str); chunk = r.read(); assert.strictEqual(chunk, null); -r.once('readable', () => { +r.once('readable', function () { // this time, we'll get *all* the remaining data, because // it's been added synchronously, as the read WOULD take // us below the hwm, and so it triggered a _read() again, @@ -77,4 +77,6 @@ r.once('readable', () => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-buffer-list.js b/test/parallel/test-stream-buffer-list.js index 0806646da..c331392e7 100644 --- a/test/parallel/test-stream-buffer-list.js +++ b/test/parallel/test-stream-buffer-list.js @@ -1,28 +1,28 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const BufferList = require('../../lib/internal/streams/buffer_list'); +var assert = require('assert/'); +var BufferList = require('../../lib/internal/streams/buffer_list'); // Test empty buffer list. -const emptyList = new BufferList(); +var emptyList = new BufferList(); emptyList.shift(); assert.deepStrictEqual(emptyList, new BufferList()); assert.strictEqual(emptyList.join(','), ''); assert.deepStrictEqual(emptyList.concat(0), bufferShim.alloc(0)); -const buf = bufferShim.from('foo'); +var buf = bufferShim.from('foo'); // Test buffer list with one element. -const list = new BufferList(); +var list = new BufferList(); list.push(buf); -const copy = list.concat(3); +var copy = list.concat(3); assert.notStrictEqual(copy, buf); assert.deepStrictEqual(copy, buf); assert.strictEqual(list.join(','), 'foo'); -const shifted = list.shift(); +var shifted = list.shift(); assert.strictEqual(shifted, buf); assert.deepStrictEqual(list, new BufferList()); ; @@ -33,4 +33,6 @@ assert.deepStrictEqual(list, new BufferList()); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-decoder-objectmode.js b/test/parallel/test-stream-decoder-objectmode.js index f655bf022..790a7628a 100644 --- a/test/parallel/test-stream-decoder-objectmode.js +++ b/test/parallel/test-stream-decoder-objectmode.js @@ -1,14 +1,14 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const stream = require('../../'); -const assert = require('assert/'); -const readable = new stream.Readable({ - read: () => {}, +var stream = require('../../'); +var assert = require('assert/'); +var readable = new stream.Readable({ + read: function read() {}, encoding: 'utf16le', objectMode: true }); @@ -28,4 +28,6 @@ assert.strictEqual(readable.read(), null); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-destroy-event-order.js b/test/parallel/test-stream-destroy-event-order.js index 59d322e7f..bc5dfcc63 100644 --- a/test/parallel/test-stream-destroy-event-order.js +++ b/test/parallel/test-stream-destroy-event-order.js @@ -1,23 +1,23 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable; -const rs = new Readable({ - read() {} +var rs = new Readable({ + read: function read() {} }); -let closed = false; -let errored = false; -rs.on('close', common.mustCall(() => { +var closed = false; +var errored = false; +rs.on('close', common.mustCall(function () { closed = true; assert(errored); })); -rs.on('error', common.mustCall(err => { +rs.on('error', common.mustCall(function (err) { errored = true; assert(!closed); })); @@ -30,4 +30,6 @@ rs.destroy(new Error('kaboom')); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-duplex-destroy.js b/test/parallel/test-stream-duplex-destroy.js index c5cf86538..5a625fd25 100644 --- a/test/parallel/test-stream-duplex-destroy.js +++ b/test/parallel/test-stream-duplex-destroy.js @@ -1,19 +1,19 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Duplex = _require.Duplex; -const assert = require('assert/'); +var assert = require('assert/'); { - const duplex = new Duplex({ - write(chunk, enc, cb) { + var duplex = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {} + read: function read() {} }); duplex.resume(); duplex.on('end', common.mustNotCall()); @@ -23,158 +23,159 @@ const assert = require('assert/'); assert.strictEqual(duplex.destroyed, true); } { - const duplex = new Duplex({ - write(chunk, enc, cb) { + var _duplex = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {} + read: function read() {} }); - duplex.resume(); - const expected = new Error('kaboom'); - duplex.on('end', common.mustNotCall()); - duplex.on('finish', common.mustNotCall()); - duplex.on('error', common.mustCall(err => { + _duplex.resume(); + var expected = new Error('kaboom'); + _duplex.on('end', common.mustNotCall()); + _duplex.on('finish', common.mustNotCall()); + _duplex.on('error', common.mustCall(function (err) { assert.strictEqual(err, expected); })); - duplex.destroy(expected); - assert.strictEqual(duplex.destroyed, true); + _duplex.destroy(expected); + assert.strictEqual(_duplex.destroyed, true); } { - const duplex = new Duplex({ - write(chunk, enc, cb) { + var _duplex2 = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {} + read: function read() {} }); - duplex._destroy = common.mustCall(function (err, cb) { - assert.strictEqual(err, expected); + _duplex2._destroy = common.mustCall(function (err, cb) { + assert.strictEqual(err, _expected); cb(err); }); - const expected = new Error('kaboom'); - duplex.on('finish', common.mustNotCall('no finish event')); - duplex.on('error', common.mustCall(err => { - assert.strictEqual(err, expected); + var _expected = new Error('kaboom'); + _duplex2.on('finish', common.mustNotCall('no finish event')); + _duplex2.on('error', common.mustCall(function (err) { + assert.strictEqual(err, _expected); })); - duplex.destroy(expected); - assert.strictEqual(duplex.destroyed, true); + _duplex2.destroy(_expected); + assert.strictEqual(_duplex2.destroyed, true); } { - const expected = new Error('kaboom'); - const duplex = new Duplex({ - write(chunk, enc, cb) { + var _expected2 = new Error('kaboom'); + var _duplex3 = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {}, + read: function read() {}, destroy: common.mustCall(function (err, cb) { - assert.strictEqual(err, expected); + assert.strictEqual(err, _expected2); cb(); }) }); - duplex.resume(); - duplex.on('end', common.mustNotCall('no end event')); - duplex.on('finish', common.mustNotCall('no finish event')); + _duplex3.resume(); + _duplex3.on('end', common.mustNotCall('no end event')); + _duplex3.on('finish', common.mustNotCall('no finish event')); // error is swallowed by the custom _destroy - duplex.on('error', common.mustNotCall('no error event')); - duplex.on('close', common.mustCall()); - duplex.destroy(expected); - assert.strictEqual(duplex.destroyed, true); + _duplex3.on('error', common.mustNotCall('no error event')); + _duplex3.on('close', common.mustCall()); + _duplex3.destroy(_expected2); + assert.strictEqual(_duplex3.destroyed, true); } { - const duplex = new Duplex({ - write(chunk, enc, cb) { + var _duplex4 = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {} + read: function read() {} }); - duplex._destroy = common.mustCall(function (err, cb) { + _duplex4._destroy = common.mustCall(function (err, cb) { assert.strictEqual(err, null); cb(); }); - duplex.destroy(); - assert.strictEqual(duplex.destroyed, true); + _duplex4.destroy(); + assert.strictEqual(_duplex4.destroyed, true); } { - const duplex = new Duplex({ - write(chunk, enc, cb) { + var _duplex5 = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {} + read: function read() {} }); - duplex.resume(); - duplex._destroy = common.mustCall(function (err, cb) { + _duplex5.resume(); + _duplex5._destroy = common.mustCall(function (err, cb) { + var _this = this; assert.strictEqual(err, null); - process.nextTick(() => { - this.push(null); - this.end(); + process.nextTick(function () { + _this.push(null); + _this.end(); cb(); }); }); - const fail = common.mustNotCall('no finish or end event'); - duplex.on('finish', fail); - duplex.on('end', fail); - duplex.destroy(); - duplex.removeListener('end', fail); - duplex.removeListener('finish', fail); - duplex.on('end', common.mustCall()); - duplex.on('finish', common.mustCall()); - assert.strictEqual(duplex.destroyed, true); + var fail = common.mustNotCall('no finish or end event'); + _duplex5.on('finish', fail); + _duplex5.on('end', fail); + _duplex5.destroy(); + _duplex5.removeListener('end', fail); + _duplex5.removeListener('finish', fail); + _duplex5.on('end', common.mustCall()); + _duplex5.on('finish', common.mustCall()); + assert.strictEqual(_duplex5.destroyed, true); } { - const duplex = new Duplex({ - write(chunk, enc, cb) { + var _duplex6 = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {} + read: function read() {} }); - const expected = new Error('kaboom'); - duplex._destroy = common.mustCall(function (err, cb) { + var _expected3 = new Error('kaboom'); + _duplex6._destroy = common.mustCall(function (err, cb) { assert.strictEqual(err, null); - cb(expected); + cb(_expected3); }); - duplex.on('finish', common.mustNotCall('no finish event')); - duplex.on('end', common.mustNotCall('no end event')); - duplex.on('error', common.mustCall(err => { - assert.strictEqual(err, expected); + _duplex6.on('finish', common.mustNotCall('no finish event')); + _duplex6.on('end', common.mustNotCall('no end event')); + _duplex6.on('error', common.mustCall(function (err) { + assert.strictEqual(err, _expected3); })); - duplex.destroy(); - assert.strictEqual(duplex.destroyed, true); + _duplex6.destroy(); + assert.strictEqual(_duplex6.destroyed, true); } { - const duplex = new Duplex({ - write(chunk, enc, cb) { + var _duplex7 = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {}, + read: function read() {}, allowHalfOpen: true }); - duplex.resume(); - duplex.on('finish', common.mustNotCall()); - duplex.on('end', common.mustNotCall()); - duplex.destroy(); - assert.strictEqual(duplex.destroyed, true); + _duplex7.resume(); + _duplex7.on('finish', common.mustNotCall()); + _duplex7.on('end', common.mustNotCall()); + _duplex7.destroy(); + assert.strictEqual(_duplex7.destroyed, true); } { - const duplex = new Duplex({ - write(chunk, enc, cb) { + var _duplex8 = new Duplex({ + write: function write(chunk, enc, cb) { cb(); }, - read() {} + read: function read() {} }); - duplex.destroyed = true; - assert.strictEqual(duplex.destroyed, true); + _duplex8.destroyed = true; + assert.strictEqual(_duplex8.destroyed, true); // the internal destroy() mechanism should not be triggered - duplex.on('finish', common.mustNotCall()); - duplex.on('end', common.mustNotCall()); - duplex.destroy(); + _duplex8.on('finish', common.mustNotCall()); + _duplex8.on('end', common.mustNotCall()); + _duplex8.destroy(); } { - function MyDuplex() { + var MyDuplex = function MyDuplex() { assert.strictEqual(this.destroyed, false); this.destroyed = false; Duplex.call(this); - } + }; Object.setPrototypeOf(MyDuplex.prototype, Duplex.prototype); Object.setPrototypeOf(MyDuplex, Duplex); new MyDuplex(); @@ -187,4 +188,6 @@ const assert = require('assert/'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-duplex-end.js b/test/parallel/test-stream-duplex-end.js index 5f346836d..df8f63002 100644 --- a/test/parallel/test-stream-duplex-end.js +++ b/test/parallel/test-stream-duplex-end.js @@ -1,15 +1,15 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Duplex = require('../../').Duplex; +var common = require('../common'); +var assert = require('assert/'); +var Duplex = require('../../').Duplex; { - const stream = new Duplex({ - read() {} + var stream = new Duplex({ + read: function read() {} }); assert.strictEqual(stream.allowHalfOpen, true); stream.on('finish', common.mustNotCall()); @@ -18,27 +18,27 @@ const Duplex = require('../../').Duplex; stream.push(null); } { - const stream = new Duplex({ - read() {}, + var _stream = new Duplex({ + read: function read() {}, allowHalfOpen: false }); - assert.strictEqual(stream.allowHalfOpen, false); - stream.on('finish', common.mustCall()); - assert.strictEqual(stream.listenerCount('end'), 1); - stream.resume(); - stream.push(null); + assert.strictEqual(_stream.allowHalfOpen, false); + _stream.on('finish', common.mustCall()); + assert.strictEqual(_stream.listenerCount('end'), 1); + _stream.resume(); + _stream.push(null); } { - const stream = new Duplex({ - read() {}, + var _stream2 = new Duplex({ + read: function read() {}, allowHalfOpen: false }); - assert.strictEqual(stream.allowHalfOpen, false); - stream._writableState.ended = true; - stream.on('finish', common.mustNotCall()); - assert.strictEqual(stream.listenerCount('end'), 1); - stream.resume(); - stream.push(null); + assert.strictEqual(_stream2.allowHalfOpen, false); + _stream2._writableState.ended = true; + _stream2.on('finish', common.mustNotCall()); + assert.strictEqual(_stream2.listenerCount('end'), 1); + _stream2.resume(); + _stream2.push(null); } ; (function () { @@ -48,4 +48,6 @@ const Duplex = require('../../').Duplex; var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-duplex.js b/test/parallel/test-stream-duplex.js index 10a81d96b..1e7e600b3 100644 --- a/test/parallel/test-stream-duplex.js +++ b/test/parallel/test-stream-duplex.js @@ -21,13 +21,13 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const Duplex = require('../../').Duplex; -const stream = new Duplex({ +var assert = require('assert/'); +var Duplex = require('../../').Duplex; +var stream = new Duplex({ objectMode: true }); assert(Duplex() instanceof Duplex); @@ -35,14 +35,14 @@ assert(stream._readableState.objectMode); assert(stream._writableState.objectMode); assert(stream.allowHalfOpen); assert.strictEqual(stream.listenerCount('end'), 0); -let written; -let read; -stream._write = (obj, _, cb) => { +var written; +var read; +stream._write = function (obj, _, cb) { written = obj; cb(); }; -stream._read = () => {}; -stream.on('data', obj => { +stream._read = function () {}; +stream.on('data', function (obj) { read = obj; }); stream.push({ @@ -51,7 +51,7 @@ stream.push({ stream.end({ val: 2 }); -process.on('exit', () => { +process.on('exit', function () { assert.strictEqual(read.val, 1); assert.strictEqual(written.val, 2); }); @@ -63,4 +63,6 @@ process.on('exit', () => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-end-paused.js b/test/parallel/test-stream-end-paused.js index 92b819a68..bf10f8f17 100644 --- a/test/parallel/test-stream-end-paused.js +++ b/test/parallel/test-stream-end-paused.js @@ -22,16 +22,16 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); +var common = require('../common'); +var assert = require('assert/'); // Make sure we don't miss the end event for paused 0-length streams -const Readable = require('../../').Readable; -const stream = new Readable(); -let calledRead = false; +var Readable = require('../../').Readable; +var stream = new Readable(); +var calledRead = false; stream._read = function () { assert(!calledRead); calledRead = true; @@ -56,4 +56,6 @@ process.on('exit', function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-events-prepend.js b/test/parallel/test-stream-events-prepend.js index d641cde78..eec8fbe45 100644 --- a/test/parallel/test-stream-events-prepend.js +++ b/test/parallel/test-stream-events-prepend.js @@ -1,27 +1,58 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -class Writable extends stream.Writable { - constructor() { - super(); - this.prependListener = undefined; +var common = require('../common'); +var stream = require('../../'); +var Writable = /*#__PURE__*/function (_stream$Writable) { + _inherits(Writable, _stream$Writable); + var _super = _createSuper(Writable); + function Writable() { + var _this; + _classCallCheck(this, Writable); + _this = _super.call(this); + _this.prependListener = undefined; + return _this; } - _write(chunk, end, cb) { - cb(); + _createClass(Writable, [{ + key: "_write", + value: function _write(chunk, end, cb) { + cb(); + } + }]); + return Writable; +}(stream.Writable); +var Readable = /*#__PURE__*/function (_stream$Readable) { + _inherits(Readable, _stream$Readable); + var _super2 = _createSuper(Readable); + function Readable() { + _classCallCheck(this, Readable); + return _super2.apply(this, arguments); } -} -class Readable extends stream.Readable { - _read() { - this.push(null); - } -} -const w = new Writable(); + _createClass(Readable, [{ + key: "_read", + value: function _read() { + this.push(null); + } + }]); + return Readable; +}(stream.Readable); +var w = new Writable(); w.on('pipe', common.mustCall()); -const r = new Readable(); +var r = new Readable(); r.pipe(w); ; (function () { @@ -31,4 +62,6 @@ r.pipe(w); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-finished.js b/test/parallel/test-stream-finished.js index 02337207d..cb558fd16 100644 --- a/test/parallel/test-stream-finished.js +++ b/test/parallel/test-stream-finished.js @@ -3,54 +3,54 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Writable = _require.Writable, Readable = _require.Readable, Transform = _require.Transform, finished = _require.finished; -const assert = require('assert/'); -const fs = require('fs'); -const promisify = require('util-promisify'); +var assert = require('assert/'); +var fs = require('fs'); +var promisify = require('util-promisify'); { - const rs = new Readable({ - read() {} + var rs = new Readable({ + read: function read() {} }); - finished(rs, common.mustCall(err => { + finished(rs, common.mustCall(function (err) { assert(!err, 'no error'); })); rs.push(null); rs.resume(); } { - const ws = new Writable({ - write(data, enc, cb) { + var ws = new Writable({ + write: function write(data, enc, cb) { cb(); } }); - finished(ws, common.mustCall(err => { + finished(ws, common.mustCall(function (err) { assert(!err, 'no error'); })); ws.end(); } { - const tr = new Transform({ - transform(data, enc, cb) { + var tr = new Transform({ + transform: function transform(data, enc, cb) { cb(); } }); - let finish = false; - let ended = false; - tr.on('end', () => { + var finish = false; + var ended = false; + tr.on('end', function () { ended = true; }); - tr.on('finish', () => { + tr.on('finish', function () { finish = true; }); - finished(tr, common.mustCall(err => { + finished(tr, common.mustCall(function (err) { assert(!err, 'no error'); assert(finish); assert(ended); @@ -59,75 +59,74 @@ const promisify = require('util-promisify'); tr.resume(); } { - const rs = fs.createReadStream(__filename); - rs.resume(); - finished(rs, common.mustCall()); + var _rs = fs.createReadStream(__filename); + _rs.resume(); + finished(_rs, common.mustCall()); } { - const finishedPromise = promisify(finished); - function run() { - return _run.apply(this, arguments); - } - function _run() { - _run = _asyncToGenerator(function* () { - const rs = fs.createReadStream(__filename); - const done = common.mustCall(); - let ended = false; + var run = /*#__PURE__*/function () { + var _ref = _asyncToGenerator(function* () { + var rs = fs.createReadStream(__filename); + var done = common.mustCall(); + var ended = false; rs.resume(); - rs.on('end', () => { + rs.on('end', function () { ended = true; }); yield finishedPromise(rs); assert(ended); done(); }); - return _run.apply(this, arguments); - } + return function run() { + return _ref.apply(this, arguments); + }; + }(); + var finishedPromise = promisify(finished); run(); } { - const rs = fs.createReadStream('file-does-not-exist'); - finished(rs, common.mustCall(err => { + var _rs2 = fs.createReadStream('file-does-not-exist'); + finished(_rs2, common.mustCall(function (err) { assert.strictEqual(err.code, 'ENOENT'); })); } { - const rs = new Readable(); - finished(rs, common.mustCall(err => { + var _rs3 = new Readable(); + finished(_rs3, common.mustCall(function (err) { assert(!err, 'no error'); })); - rs.push(null); - rs.emit('close'); // should not trigger an error - rs.resume(); + _rs3.push(null); + _rs3.emit('close'); // should not trigger an error + _rs3.resume(); } { - const rs = new Readable(); - finished(rs, common.mustCall(err => { + var _rs4 = new Readable(); + finished(_rs4, common.mustCall(function (err) { assert(err, 'premature close error'); })); - rs.emit('close'); // should trigger error - rs.push(null); - rs.resume(); + _rs4.emit('close'); // should trigger error + _rs4.push(null); + _rs4.resume(); } // Test that calling returned function removes listeners { - const ws = new Writable({ - write(data, env, cb) { + var _ws = new Writable({ + write: function write(data, env, cb) { cb(); } }); - const removeListener = finished(ws, common.mustNotCall()); + var removeListener = finished(_ws, common.mustNotCall()); removeListener(); - ws.end(); + _ws.end(); } { - const rs = new Readable(); - const removeListeners = finished(rs, common.mustNotCall()); + var _rs5 = new Readable(); + var removeListeners = finished(_rs5, common.mustNotCall()); removeListeners(); - rs.emit('close'); - rs.push(null); - rs.resume(); + _rs5.emit('close'); + _rs5.push(null); + _rs5.resume(); } ; (function () { @@ -137,4 +136,6 @@ const promisify = require('util-promisify'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-ispaused.js b/test/parallel/test-stream-ispaused.js index b865c42f3..58592d544 100644 --- a/test/parallel/test-stream-ispaused.js +++ b/test/parallel/test-stream-ispaused.js @@ -22,12 +22,12 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const readable = new stream.Readable(); +var assert = require('assert/'); +var stream = require('../../'); +var readable = new stream.Readable(); // _read is a noop, here. readable._read = Function(); @@ -52,4 +52,6 @@ assert.ok(!readable.isPaused()); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-objectmode-undefined.js b/test/parallel/test-stream-objectmode-undefined.js index fe9c047a3..b31051cce 100644 --- a/test/parallel/test-stream-objectmode-undefined.js +++ b/test/parallel/test-stream-objectmode-undefined.js @@ -1,46 +1,46 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable, Writable = _require.Writable, Transform = _require.Transform; { - const stream = new Readable({ + var stream = new Readable({ objectMode: true, - read: common.mustCall(() => { + read: common.mustCall(function () { stream.push(undefined); stream.push(null); }) }); - stream.on('data', common.mustCall(chunk => { + stream.on('data', common.mustCall(function (chunk) { assert.strictEqual(chunk, undefined); })); } { - const stream = new Writable({ + var _stream = new Writable({ objectMode: true, - write: common.mustCall(chunk => { + write: common.mustCall(function (chunk) { assert.strictEqual(chunk, undefined); }) }); - stream.write(undefined); + _stream.write(undefined); } { - const stream = new Transform({ + var _stream2 = new Transform({ objectMode: true, - transform: common.mustCall(chunk => { - stream.push(chunk); + transform: common.mustCall(function (chunk) { + _stream2.push(chunk); }) }); - stream.on('data', common.mustCall(chunk => { + _stream2.on('data', common.mustCall(function (chunk) { assert.strictEqual(chunk, undefined); })); - stream.write(undefined); + _stream2.write(undefined); } ; (function () { @@ -50,4 +50,6 @@ const _require = require('../../'), var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-once-readable-pipe.js b/test/parallel/test-stream-once-readable-pipe.js index fa538f43c..4d73ee596 100644 --- a/test/parallel/test-stream-once-readable-pipe.js +++ b/test/parallel/test-stream-once-readable-pipe.js @@ -1,12 +1,12 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable, Writable = _require.Writable; @@ -14,16 +14,16 @@ const _require = require('../../'), // on Readable instance it will not disrupt the pipe. { - let receivedData = ''; - const w = new Writable({ - write: (chunk, env, callback) => { + var receivedData = ''; + var w = new Writable({ + write: function write(chunk, env, callback) { receivedData += chunk; callback(); } }); - const data = ['foo', 'bar', 'baz']; - const r = new Readable({ - read: () => {} + var data = ['foo', 'bar', 'baz']; + var r = new Readable({ + read: function read() {} }); r.once('readable', common.mustCall()); r.pipe(w); @@ -31,30 +31,30 @@ const _require = require('../../'), r.push(data[1]); r.push(data[2]); r.push(null); - w.on('finish', common.mustCall(() => { + w.on('finish', common.mustCall(function () { assert.strictEqual(receivedData, data.join('')); })); } { - let receivedData = ''; - const w = new Writable({ - write: (chunk, env, callback) => { - receivedData += chunk; + var _receivedData = ''; + var _w = new Writable({ + write: function write(chunk, env, callback) { + _receivedData += chunk; callback(); } }); - const data = ['foo', 'bar', 'baz']; - const r = new Readable({ - read: () => {} + var _data = ['foo', 'bar', 'baz']; + var _r = new Readable({ + read: function read() {} }); - r.pipe(w); - r.push(data[0]); - r.push(data[1]); - r.push(data[2]); - r.push(null); - r.once('readable', common.mustCall()); - w.on('finish', common.mustCall(() => { - assert.strictEqual(receivedData, data.join('')); + _r.pipe(_w); + _r.push(_data[0]); + _r.push(_data[1]); + _r.push(_data[2]); + _r.push(null); + _r.once('readable', common.mustCall()); + _w.on('finish', common.mustCall(function () { + assert.strictEqual(_receivedData, _data.join('')); })); } ; @@ -65,4 +65,6 @@ const _require = require('../../'), var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-after-end.js b/test/parallel/test-stream-pipe-after-end.js index bfa427ec6..7043e0a8d 100644 --- a/test/parallel/test-stream-pipe-after-end.js +++ b/test/parallel/test-stream-pipe-after-end.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,46 +34,62 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Readable = require('../../lib/_stream_readable'); -const Writable = require('../../lib/_stream_writable'); -class TestReadable extends Readable { - constructor(opt) { - super(opt); - this._ended = false; +var common = require('../common'); +var assert = require('assert/'); +var Readable = require('../../lib/_stream_readable'); +var Writable = require('../../lib/_stream_writable'); +var TestReadable = /*#__PURE__*/function (_Readable) { + _inherits(TestReadable, _Readable); + var _super = _createSuper(TestReadable); + function TestReadable(opt) { + var _this; + _classCallCheck(this, TestReadable); + _this = _super.call(this, opt); + _this._ended = false; + return _this; } - _read() { - if (this._ended) this.emit('error', new Error('_read called twice')); - this._ended = true; - this.push(null); + _createClass(TestReadable, [{ + key: "_read", + value: function _read() { + if (this._ended) this.emit('error', new Error('_read called twice')); + this._ended = true; + this.push(null); + } + }]); + return TestReadable; +}(Readable); +var TestWritable = /*#__PURE__*/function (_Writable) { + _inherits(TestWritable, _Writable); + var _super2 = _createSuper(TestWritable); + function TestWritable(opt) { + var _this2; + _classCallCheck(this, TestWritable); + _this2 = _super2.call(this, opt); + _this2._written = []; + return _this2; } -} -class TestWritable extends Writable { - constructor(opt) { - super(opt); - this._written = []; - } - _write(chunk, encoding, cb) { - this._written.push(chunk); - cb(); - } -} - -// this one should not emit 'end' until we read() from it later. -const ender = new TestReadable(); + _createClass(TestWritable, [{ + key: "_write", + value: function _write(chunk, encoding, cb) { + this._written.push(chunk); + cb(); + } + }]); + return TestWritable; +}(Writable); // this one should not emit 'end' until we read() from it later. +var ender = new TestReadable(); // what happens when you pipe() a Readable that's already ended? -const piper = new TestReadable(); +var piper = new TestReadable(); // pushes EOF null, and length=0, so this will trigger 'end' piper.read(); setTimeout(common.mustCall(function () { ender.on('end', common.mustCall()); - const c = ender.read(); + var c = ender.read(); assert.strictEqual(c, null); - const w = new TestWritable(); + var w = new TestWritable(); w.on('finish', common.mustCall()); piper.pipe(w); }), 1); @@ -73,4 +101,6 @@ setTimeout(common.mustCall(function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-await-drain-manual-resume.js b/test/parallel/test-stream-pipe-await-drain-manual-resume.js index 4c4159096..a5beec512 100644 --- a/test/parallel/test-stream-pipe-await-drain-manual-resume.js +++ b/test/parallel/test-stream-pipe-await-drain-manual-resume.js @@ -1,48 +1,48 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const assert = require('assert/'); +var common = require('../common'); +var stream = require('../../'); +var assert = require('assert/'); // A consumer stream with a very low highWaterMark, which starts in a state // where it buffers the chunk it receives rather than indicating that they // have been consumed. -const writable = new stream.Writable({ +var writable = new stream.Writable({ highWaterMark: 5 }); -let isCurrentlyBufferingWrites = true; -const queue = []; -writable._write = (chunk, encoding, cb) => { +var isCurrentlyBufferingWrites = true; +var queue = []; +writable._write = function (chunk, encoding, cb) { if (isCurrentlyBufferingWrites) queue.push({ - chunk, - cb + chunk: chunk, + cb: cb });else cb(); }; -const readable = new stream.Readable({ - read() {} +var readable = new stream.Readable({ + read: function read() {} }); readable.pipe(writable); -readable.once('pause', common.mustCall(() => { - assert.strictEqual(readable._readableState.awaitDrain, 1, 'Expected awaitDrain to equal 1 but instead got ' + `${readable._readableState.awaitDrain}`); +readable.once('pause', common.mustCall(function () { + assert.strictEqual(readable._readableState.awaitDrain, 1, 'Expected awaitDrain to equal 1 but instead got ' + "".concat(readable._readableState.awaitDrain)); // First pause, resume manually. The next write() to writable will still // return false, because chunks are still being buffered, so it will increase // the awaitDrain counter again. - process.nextTick(common.mustCall(() => { + process.nextTick(common.mustCall(function () { readable.resume(); })); - readable.once('pause', common.mustCall(() => { - assert.strictEqual(readable._readableState.awaitDrain, 1, '.resume() should not reset the counter but instead got ' + `${readable._readableState.awaitDrain}`); + readable.once('pause', common.mustCall(function () { + assert.strictEqual(readable._readableState.awaitDrain, 1, '.resume() should not reset the counter but instead got ' + "".concat(readable._readableState.awaitDrain)); // Second pause, handle all chunks from now on. Once all callbacks that // are currently queued up are handled, the awaitDrain drain counter should // fall back to 0 and all chunks that are pending on the readable side // should be flushed. isCurrentlyBufferingWrites = false; for (var _i = 0, _queue = queue; _i < _queue.length; _i++) { - const queued = _queue[_i]; + var queued = _queue[_i]; queued.cb(); } })); @@ -51,8 +51,8 @@ readable.push(bufferShim.alloc(100)); // Fill the writable HWM, first 'pause'. readable.push(bufferShim.alloc(100)); // Second 'pause'. readable.push(bufferShim.alloc(100)); // Should get through to the writable. readable.push(null); -writable.on('finish', common.mustCall(() => { - assert.strictEqual(readable._readableState.awaitDrain, 0, 'awaitDrain should equal 0 after all chunks are written but instead got' + `${readable._readableState.awaitDrain}`); +writable.on('finish', common.mustCall(function () { + assert.strictEqual(readable._readableState.awaitDrain, 0, 'awaitDrain should equal 0 after all chunks are written but instead got' + "".concat(readable._readableState.awaitDrain)); // Everything okay, all chunks were written. })); @@ -64,4 +64,6 @@ writable.on('finish', common.mustCall(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-await-drain-push-while-write.js b/test/parallel/test-stream-pipe-await-drain-push-while-write.js index 99fdbada4..4d845bad3 100644 --- a/test/parallel/test-stream-pipe-await-drain-push-while-write.js +++ b/test/parallel/test-stream-pipe-await-drain-push-while-write.js @@ -1,12 +1,12 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const assert = require('assert/'); -const writable = new stream.Writable({ +var common = require('../common'); +var stream = require('../../'); +var assert = require('assert/'); +var writable = new stream.Writable({ write: common.mustCall(function (chunk, encoding, cb) { assert.strictEqual(readable._readableState.awaitDrain, 0); if (chunk.length === 32 * 1024) { @@ -14,7 +14,7 @@ const writable = new stream.Writable({ readable.push(bufferShim.alloc(34 * 1024)); // above hwm // We should check if awaitDrain counter is increased in the next // tick, because awaitDrain is incremented after this method finished - process.nextTick(() => { + process.nextTick(function () { assert.strictEqual(readable._readableState.awaitDrain, 1); }); } @@ -23,8 +23,8 @@ const writable = new stream.Writable({ }); // A readable stream which produces two buffers. -const bufs = [bufferShim.alloc(32 * 1024), bufferShim.alloc(33 * 1024)]; // above hwm -const readable = new stream.Readable({ +var bufs = [bufferShim.alloc(32 * 1024), bufferShim.alloc(33 * 1024)]; // above hwm +var readable = new stream.Readable({ read: function read() { while (bufs.length > 0) { this.push(bufs.shift()); @@ -40,4 +40,6 @@ readable.pipe(writable); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-await-drain.js b/test/parallel/test-stream-pipe-await-drain.js index 3fb793cfd..ab825cfe3 100644 --- a/test/parallel/test-stream-pipe-await-drain.js +++ b/test/parallel/test-stream-pipe-await-drain.js @@ -1,31 +1,31 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const assert = require('assert/'); +var common = require('../common'); +var stream = require('../../'); +var assert = require('assert/'); // This is very similar to test-stream-pipe-cleanup-pause.js. -const reader = new stream.Readable(); -const writer1 = new stream.Writable(); -const writer2 = new stream.Writable(); -const writer3 = new stream.Writable(); +var reader = new stream.Readable(); +var writer1 = new stream.Writable(); +var writer2 = new stream.Writable(); +var writer3 = new stream.Writable(); // 560000 is chosen here because it is larger than the (default) highWaterMark // and will cause `.write()` to return false // See: https://github.com/nodejs/node/issues/5820 -const buffer = bufferShim.allocUnsafe(560000); -reader._read = () => {}; +var buffer = bufferShim.allocUnsafe(560000); +reader._read = function () {}; writer1._write = common.mustCall(function (chunk, encoding, cb) { this.emit('chunk-received'); cb(); }, 1); -writer1.once('chunk-received', () => { +writer1.once('chunk-received', function () { assert.strictEqual(reader._readableState.awaitDrain, 0, 'awaitDrain initial value should be 0, actual is ' + reader._readableState.awaitDrain); - setImmediate(() => { + setImmediate(function () { // This one should *not* get through to writer1 because writer2 is not // "done" processing. reader.push(buffer); @@ -33,13 +33,13 @@ writer1.once('chunk-received', () => { }); // A "slow" consumer: -writer2._write = common.mustCall((chunk, encoding, cb) => { +writer2._write = common.mustCall(function (chunk, encoding, cb) { assert.strictEqual(reader._readableState.awaitDrain, 1, 'awaitDrain should be 1 after first push, actual is ' + reader._readableState.awaitDrain); // Not calling cb here to "simulate" slow stream. // This should be called exactly once, since the first .write() call // will return false. }, 1); -writer3._write = common.mustCall((chunk, encoding, cb) => { +writer3._write = common.mustCall(function (chunk, encoding, cb) { assert.strictEqual(reader._readableState.awaitDrain, 2, 'awaitDrain should be 2 after second push, actual is ' + reader._readableState.awaitDrain); // Not calling cb here to "simulate" slow stream. // This should be called exactly once, since the first .write() call @@ -57,4 +57,6 @@ reader.push(buffer); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-cleanup-pause.js b/test/parallel/test-stream-pipe-cleanup-pause.js index 5f92a50a6..fb29c536a 100644 --- a/test/parallel/test-stream-pipe-cleanup-pause.js +++ b/test/parallel/test-stream-pipe-cleanup-pause.js @@ -1,19 +1,19 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const reader = new stream.Readable(); -const writer1 = new stream.Writable(); -const writer2 = new stream.Writable(); +var common = require('../common'); +var stream = require('../../'); +var reader = new stream.Readable(); +var writer1 = new stream.Writable(); +var writer2 = new stream.Writable(); // 560000 is chosen here because it is larger than the (default) highWaterMark // and will cause `.write()` to return false // See: https://github.com/nodejs/node/issues/2323 -const buffer = bufferShim.allocUnsafe(560000); -reader._read = () => {}; +var buffer = bufferShim.allocUnsafe(560000); +reader._read = function () {}; writer1._write = common.mustCall(function (chunk, encoding, cb) { this.emit('chunk-received'); cb(); @@ -42,4 +42,6 @@ reader.push(buffer); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-cleanup.js b/test/parallel/test-stream-pipe-cleanup.js index 26ee94e1a..3f9b2f92c 100644 --- a/test/parallel/test-stream-pipe-cleanup.js +++ b/test/parallel/test-stream-pipe-cleanup.js @@ -22,13 +22,13 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ // This test asserts that Stream.prototype.pipe does not leave listeners // hanging on the source or dest. require('../common'); -const stream = require('../../'); -const assert = require('assert/'); +var stream = require('../../'); +var assert = require('assert/'); (function () { if (/^v0\.8\./.test(process.version)) return; function Writable() { @@ -56,10 +56,10 @@ const assert = require('assert/'); } Object.setPrototypeOf(Duplex.prototype, Writable.prototype); Object.setPrototypeOf(Duplex, Writable); - let i = 0; - const limit = 100; - let w = new Writable(); - let r; + var i = 0; + var limit = 100; + var w = new Writable(); + var r; for (i = 0; i < limit; i++) { r = new Readable(); r.pipe(w); @@ -85,7 +85,7 @@ const assert = require('assert/'); assert.strictEqual(w.listeners('close').length, 0); r = new Readable(); w = new Writable(); - const d = new Duplex(); + var d = new Duplex(); r.pipe(d); // pipeline A d.pipe(w); // pipeline B assert.strictEqual(r.listeners('end').length, 2); // A.onend, A.cleanup @@ -123,4 +123,6 @@ const assert = require('assert/'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-error-handling.js b/test/parallel/test-stream-pipe-error-handling.js index ea35e1c6a..91275e86e 100644 --- a/test/parallel/test-stream-pipe-error-handling.js +++ b/test/parallel/test-stream-pipe-error-handling.js @@ -22,42 +22,45 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Stream = require('stream').Stream; +var common = require('../common'); +var assert = require('assert/'); +var Stream = require('stream').Stream; { - const source = new Stream(); - const dest = new Stream(); + var source = new Stream(); + var dest = new Stream(); source.pipe(dest); - let gotErr = null; + var gotErr = null; source.on('error', function (err) { gotErr = err; }); - const err = new Error('This stream turned into bacon.'); + var err = new Error('This stream turned into bacon.'); source.emit('error', err); assert.strictEqual(gotErr, err); } { - const source = new Stream(); - const dest = new Stream(); - source.pipe(dest); - const err = new Error('This stream turned into bacon.'); - let gotErr = null; + var _source = new Stream(); + var _dest = new Stream(); + _source.pipe(_dest); + var _err = new Error('This stream turned into bacon.'); + var _gotErr = null; try { - source.emit('error', err); + _source.emit('error', _err); } catch (e) { - gotErr = e; + _gotErr = e; } - assert.strictEqual(gotErr, err); + assert.strictEqual(_gotErr, _err); } { - const R = require('../../').Readable; - const W = require('../../').Writable; - const r = new R(); - const w = new W(); - let removed = false; + var myOnError = function myOnError() { + throw new Error('this should not happen'); + }; + var R = require('../../').Readable; + var W = require('../../').Writable; + var r = new R(); + var w = new W(); + var removed = false; r._read = common.mustCall(function () { setTimeout(common.mustCall(function () { assert(removed); @@ -70,28 +73,25 @@ const Stream = require('stream').Stream; r.pipe(w); w.removeListener('error', myOnError); removed = true; - function myOnError() { - throw new Error('this should not happen'); - } } { - const R = require('../../').Readable; - const W = require('../../').Writable; - const r = new R(); - const w = new W(); - let removed = false; - r._read = common.mustCall(function () { + var _R = require('../../').Readable; + var _W = require('../../').Writable; + var _r = new _R(); + var _w = new _W(); + var _removed = false; + _r._read = common.mustCall(function () { setTimeout(common.mustCall(function () { - assert(removed); - w.emit('error', new Error('fail')); + assert(_removed); + _w.emit('error', new Error('fail')); }), 1); }); - w.on('error', common.mustCall()); - w._write = () => {}; - r.pipe(w); + _w.on('error', common.mustCall()); + _w._write = function () {}; + _r.pipe(_w); // Removing some OTHER random listener should not do anything - w.removeListener('error', () => {}); - removed = true; + _w.removeListener('error', function () {}); + _removed = true; } ; (function () { @@ -101,4 +101,6 @@ const Stream = require('stream').Stream; var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-event.js b/test/parallel/test-stream-pipe-event.js index 8d90bba81..f1ecf00e3 100644 --- a/test/parallel/test-stream-pipe-event.js +++ b/test/parallel/test-stream-pipe-event.js @@ -22,11 +22,11 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const stream = require('../../'); -const assert = require('assert/'); +var stream = require('../../'); +var assert = require('assert/'); function Writable() { this.writable = true; require('stream').Stream.call(this); @@ -39,12 +39,12 @@ function Readable() { } Object.setPrototypeOf(Readable.prototype, require('stream').Stream.prototype); Object.setPrototypeOf(Readable, require('stream').Stream); -let passed = false; -const w = new Writable(); +var passed = false; +var w = new Writable(); w.on('pipe', function (src) { passed = true; }); -const r = new Readable(); +var r = new Readable(); r.pipe(w); assert.ok(passed); ; @@ -55,4 +55,6 @@ assert.ok(passed); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-flow-after-unpipe.js b/test/parallel/test-stream-pipe-flow-after-unpipe.js index 45953c0fc..b5bcbf90c 100644 --- a/test/parallel/test-stream-pipe-flow-after-unpipe.js +++ b/test/parallel/test-stream-pipe-flow-after-unpipe.js @@ -1,30 +1,34 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable, Writable = _require.Writable; // Tests that calling .unpipe() un-blocks a stream that is paused because // it is waiting on the writable side to finish a write(). -const rs = new Readable({ +var rs = new Readable({ highWaterMark: 1, // That this gets called at least 20 times is the real test here. - read: common.mustCallAtLeast(() => rs.push('foo'), 20) + read: common.mustCallAtLeast(function () { + return rs.push('foo'); + }, 20) }); -const ws = new Writable({ +var ws = new Writable({ highWaterMark: 1, - write: common.mustCall(() => { + write: common.mustCall(function () { // Ignore the callback, this write() simply never finishes. - setImmediate(() => rs.unpipe(ws)); + setImmediate(function () { + return rs.unpipe(ws); + }); }) }); -let chunks = 0; -rs.on('data', common.mustCallAtLeast(() => { +var chunks = 0; +rs.on('data', common.mustCallAtLeast(function () { chunks++; if (chunks >= 20) rs.pause(); // Finish this test. })); @@ -38,4 +42,6 @@ rs.pipe(ws); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-flow.js b/test/parallel/test-stream-pipe-flow.js index ebdd617f6..87990a0c2 100644 --- a/test/parallel/test-stream-pipe-flow.js +++ b/test/parallel/test-stream-pipe-flow.js @@ -1,57 +1,61 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable, Writable = _require.Writable, PassThrough = _require.PassThrough; { - let ticks = 17; - const rs = new Readable({ + var ticks = 17; + var rs = new Readable({ objectMode: true, - read: () => { - if (ticks-- > 0) return process.nextTick(() => rs.push({})); + read: function read() { + if (ticks-- > 0) return process.nextTick(function () { + return rs.push({}); + }); rs.push({}); rs.push(null); } }); - const ws = new Writable({ + var ws = new Writable({ highWaterMark: 0, objectMode: true, - write: (data, end, cb) => setImmediate(cb) + write: function write(data, end, cb) { + return setImmediate(cb); + } }); rs.on('end', common.mustCall()); ws.on('finish', common.mustCall()); rs.pipe(ws); } { - let missing = 8; - const rs = new Readable({ + var missing = 8; + var _rs = new Readable({ objectMode: true, - read: () => { - if (missing--) rs.push({});else rs.push(null); + read: function read() { + if (missing--) _rs.push({});else _rs.push(null); } }); - const pt = rs.pipe(new PassThrough({ + var pt = _rs.pipe(new PassThrough({ objectMode: true, highWaterMark: 2 })).pipe(new PassThrough({ objectMode: true, highWaterMark: 2 })); - pt.on('end', () => { + pt.on('end', function () { wrapper.push(null); }); - const wrapper = new Readable({ + var wrapper = new Readable({ objectMode: true, - read: () => { - process.nextTick(() => { - let data = pt.read(); + read: function read() { + process.nextTick(function () { + var data = pt.read(); if (data === null) { - pt.once('readable', () => { + pt.once('readable', function () { data = pt.read(); if (data !== null) wrapper.push(data); }); @@ -72,4 +76,6 @@ const _require = require('../../'), var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-manual-resume.js b/test/parallel/test-stream-pipe-manual-resume.js index 93b0d3db5..acf9fe518 100644 --- a/test/parallel/test-stream-pipe-manual-resume.js +++ b/test/parallel/test-stream-pipe-manual-resume.js @@ -1,36 +1,44 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); +var common = require('../common'); +var stream = require('../../'); function test(throwCodeInbetween) { // Check that a pipe does not stall if .read() is called unexpectedly // (i.e. the stream is not resumed by the pipe). - const n = 1000; - let counter = n; - const rs = stream.Readable({ + var n = 1000; + var counter = n; + var rs = stream.Readable({ objectMode: true, - read: common.mustCallAtLeast(() => { + read: common.mustCallAtLeast(function () { if (--counter >= 0) rs.push({ - counter + counter: counter });else rs.push(null); }, n) }); - const ws = stream.Writable({ + var ws = stream.Writable({ objectMode: true, - write: common.mustCall((data, enc, cb) => { + write: common.mustCall(function (data, enc, cb) { setImmediate(cb); }, n) }); - setImmediate(() => throwCodeInbetween(rs, ws)); + setImmediate(function () { + return throwCodeInbetween(rs, ws); + }); rs.pipe(ws); } -test(rs => rs.read()); -test(rs => rs.resume()); -test(() => 0); +test(function (rs) { + return rs.read(); +}); +test(function (rs) { + return rs.resume(); +}); +test(function () { + return 0; +}); ; (function () { var t = require('tap'); @@ -39,4 +47,6 @@ test(() => 0); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-multiple-pipes.js b/test/parallel/test-stream-pipe-multiple-pipes.js index 79766accd..0e2b42559 100644 --- a/test/parallel/test-stream-pipe-multiple-pipes.js +++ b/test/parallel/test-stream-pipe-multiple-pipes.js @@ -1,18 +1,18 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const assert = require('assert/'); -const readable = new stream.Readable({ - read: () => {} +var common = require('../common'); +var stream = require('../../'); +var assert = require('assert/'); +var readable = new stream.Readable({ + read: function read() {} }); -const writables = []; -for (let i = 0; i < 5; i++) { - const target = new stream.Writable({ - write: common.mustCall((chunk, encoding, callback) => { +var writables = []; +var _loop = function _loop() { + var target = new stream.Writable({ + write: common.mustCall(function (chunk, encoding, callback) { target.output.push(chunk); callback(); }, 1) @@ -21,15 +21,18 @@ for (let i = 0; i < 5; i++) { target.on('pipe', common.mustCall()); readable.pipe(target); writables.push(target); +}; +for (var i = 0; i < 5; i++) { + _loop(); } -const input = bufferShim.from([1, 2, 3, 4, 5]); +var input = bufferShim.from([1, 2, 3, 4, 5]); readable.push(input); // The pipe() calls will postpone emission of the 'resume' event using nextTick, // so no data will be available to the writable streams until then. -process.nextTick(common.mustCall(() => { +process.nextTick(common.mustCall(function () { for (var _i = 0, _writables = writables; _i < _writables.length; _i++) { - const target = _writables[_i]; + var target = _writables[_i]; assert.deepStrictEqual(target.output, [input]); target.on('unpipe', common.mustCall()); readable.unpipe(target); @@ -39,9 +42,9 @@ process.nextTick(common.mustCall(() => { readable.resume(); // Make sure the 'end' event gets emitted. })); -readable.on('end', common.mustCall(() => { +readable.on('end', common.mustCall(function () { for (var _i2 = 0, _writables2 = writables; _i2 < _writables2.length; _i2++) { - const target = _writables2[_i2]; + var target = _writables2[_i2]; assert.deepStrictEqual(target.output, [input]); } })); @@ -53,4 +56,6 @@ readable.on('end', common.mustCall(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-same-destination-twice.js b/test/parallel/test-stream-pipe-same-destination-twice.js index 9f7b0afb6..e3b10d3f0 100644 --- a/test/parallel/test-stream-pipe-same-destination-twice.js +++ b/test/parallel/test-stream-pipe-same-destination-twice.js @@ -1,22 +1,22 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); +var common = require('../common'); // Regression test for https://github.com/nodejs/node/issues/12718. // Tests that piping a source stream twice to the same destination stream // works, and that a subsequent unpipe() call only removes the pipe *once*. -const assert = require('assert/'); -const _require = require('../../'), +var assert = require('assert/'); +var _require = require('../../'), PassThrough = _require.PassThrough, Writable = _require.Writable; { - const passThrough = new PassThrough(); - const dest = new Writable({ - write: common.mustCall((chunk, encoding, cb) => { - assert.strictEqual(`${chunk}`, 'foobar'); + var passThrough = new PassThrough(); + var dest = new Writable({ + write: common.mustCall(function (chunk, encoding, cb) { + assert.strictEqual("".concat(chunk), 'foobar'); cb(); }) }); @@ -34,37 +34,37 @@ const _require = require('../../'), passThrough.pipe(dest); } { - const passThrough = new PassThrough(); - const dest = new Writable({ - write: common.mustCall((chunk, encoding, cb) => { - assert.strictEqual(`${chunk}`, 'foobar'); + var _passThrough = new PassThrough(); + var _dest = new Writable({ + write: common.mustCall(function (chunk, encoding, cb) { + assert.strictEqual("".concat(chunk), 'foobar'); cb(); }, 2) }); - passThrough.pipe(dest); - passThrough.pipe(dest); - assert.strictEqual(passThrough._events.data.length, 2); - assert.strictEqual(passThrough._readableState.pipesCount, 2); - assert.strictEqual(passThrough._readableState.pipes[0], dest); - assert.strictEqual(passThrough._readableState.pipes[1], dest); - passThrough.write('foobar'); + _passThrough.pipe(_dest); + _passThrough.pipe(_dest); + assert.strictEqual(_passThrough._events.data.length, 2); + assert.strictEqual(_passThrough._readableState.pipesCount, 2); + assert.strictEqual(_passThrough._readableState.pipes[0], _dest); + assert.strictEqual(_passThrough._readableState.pipes[1], _dest); + _passThrough.write('foobar'); } { - const passThrough = new PassThrough(); - const dest = new Writable({ + var _passThrough2 = new PassThrough(); + var _dest2 = new Writable({ write: common.mustNotCall() }); - passThrough.pipe(dest); - passThrough.pipe(dest); - assert.strictEqual(passThrough._events.data.length, 2); - assert.strictEqual(passThrough._readableState.pipesCount, 2); - assert.strictEqual(passThrough._readableState.pipes[0], dest); - assert.strictEqual(passThrough._readableState.pipes[1], dest); - passThrough.unpipe(dest); - passThrough.unpipe(dest); - assert.strictEqual(passThrough._events.data, undefined); - assert.strictEqual(passThrough._readableState.pipesCount, 0); - passThrough.write('foobar'); + _passThrough2.pipe(_dest2); + _passThrough2.pipe(_dest2); + assert.strictEqual(_passThrough2._events.data.length, 2); + assert.strictEqual(_passThrough2._readableState.pipesCount, 2); + assert.strictEqual(_passThrough2._readableState.pipes[0], _dest2); + assert.strictEqual(_passThrough2._readableState.pipes[1], _dest2); + _passThrough2.unpipe(_dest2); + _passThrough2.unpipe(_dest2); + assert.strictEqual(_passThrough2._events.data, undefined); + assert.strictEqual(_passThrough2._readableState.pipesCount, 0); + _passThrough2.write('foobar'); } ; (function () { @@ -74,4 +74,6 @@ const _require = require('../../'), var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-unpipe-streams.js b/test/parallel/test-stream-pipe-unpipe-streams.js index cbdf022ee..d4175cdc9 100644 --- a/test/parallel/test-stream-pipe-unpipe-streams.js +++ b/test/parallel/test-stream-pipe-unpipe-streams.js @@ -1,21 +1,21 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable, Writable = _require.Writable; -const source = Readable({ - read: () => {} +var source = Readable({ + read: function read() {} }); -const dest1 = Writable({ - write: () => {} +var dest1 = Writable({ + write: function write() {} }); -const dest2 = Writable({ - write: () => {} +var dest2 = Writable({ + write: function write() {} }); source.pipe(dest1); source.pipe(dest2); @@ -35,43 +35,43 @@ source.unpipe(dest2); source.unpipe(dest1); assert.strictEqual(source._readableState.pipes, null); { + var checkDestCleanup = function checkDestCleanup(dest) { + var currentDestId = ++destCount; + _source.pipe(dest); + var unpipeChecker = common.mustCall(function () { + assert.deepStrictEqual(dest.listeners('unpipe'), [unpipeChecker], "destination{".concat(currentDestId, "} should have a 'unpipe' event ") + 'listener which is `unpipeChecker`'); + dest.removeListener('unpipe', unpipeChecker); + destCheckEventNames.forEach(function (eventName) { + assert.strictEqual(dest.listenerCount(eventName), 0, "destination{".concat(currentDestId, "}'s '").concat(eventName, "' event ") + 'listeners not removed'); + }); + if (--destCount === 0) checkSrcCleanup(); + }); + dest.on('unpipe', unpipeChecker); + }; // test `cleanup()` if we unpipe all streams. - const source = Readable({ - read: () => {} + var _source = Readable({ + read: function read() {} }); - const dest1 = Writable({ - write: () => {} + var _dest = Writable({ + write: function write() {} }); - const dest2 = Writable({ - write: () => {} + var _dest2 = Writable({ + write: function write() {} }); - let destCount = 0; - const srcCheckEventNames = ['end', 'data']; - const destCheckEventNames = ['close', 'finish', 'drain', 'error', 'unpipe']; - const checkSrcCleanup = common.mustCall(() => { - assert.strictEqual(source._readableState.pipes, null); - assert.strictEqual(source._readableState.pipesCount, 0); - assert.strictEqual(source._readableState.flowing, false); - srcCheckEventNames.forEach(eventName => { - assert.strictEqual(source.listenerCount(eventName), 0, `source's '${eventName}' event listeners not removed`); + var destCount = 0; + var srcCheckEventNames = ['end', 'data']; + var destCheckEventNames = ['close', 'finish', 'drain', 'error', 'unpipe']; + var checkSrcCleanup = common.mustCall(function () { + assert.strictEqual(_source._readableState.pipes, null); + assert.strictEqual(_source._readableState.pipesCount, 0); + assert.strictEqual(_source._readableState.flowing, false); + srcCheckEventNames.forEach(function (eventName) { + assert.strictEqual(_source.listenerCount(eventName), 0, "source's '".concat(eventName, "' event listeners not removed")); }); }); - function checkDestCleanup(dest) { - const currentDestId = ++destCount; - source.pipe(dest); - const unpipeChecker = common.mustCall(() => { - assert.deepStrictEqual(dest.listeners('unpipe'), [unpipeChecker], `destination{${currentDestId}} should have a 'unpipe' event ` + 'listener which is `unpipeChecker`'); - dest.removeListener('unpipe', unpipeChecker); - destCheckEventNames.forEach(eventName => { - assert.strictEqual(dest.listenerCount(eventName), 0, `destination{${currentDestId}}'s '${eventName}' event ` + 'listeners not removed'); - }); - if (--destCount === 0) checkSrcCleanup(); - }); - dest.on('unpipe', unpipeChecker); - } - checkDestCleanup(dest1); - checkDestCleanup(dest2); - source.unpipe(); + checkDestCleanup(_dest); + checkDestCleanup(_dest2); + _source.unpipe(); } ; (function () { @@ -81,4 +81,6 @@ assert.strictEqual(source._readableState.pipes, null); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipe-without-listenerCount.js b/test/parallel/test-stream-pipe-without-listenerCount.js index 26046b9db..f06d68e76 100644 --- a/test/parallel/test-stream-pipe-without-listenerCount.js +++ b/test/parallel/test-stream-pipe-without-listenerCount.js @@ -1,13 +1,13 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const r = new stream.Stream(); +var common = require('../common'); +var stream = require('../../'); +var r = new stream.Stream(); r.listenerCount = undefined; -const w = new stream.Stream(); +var w = new stream.Stream(); w.listenerCount = undefined; w.on('pipe', function () { r.emit('error', new Error('Readable Error')); @@ -24,4 +24,6 @@ r.pipe(w); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipeline-queued-end-in-destroy.js b/test/parallel/test-stream-pipeline-queued-end-in-destroy.js index b5cf3e38b..2e87bbdb7 100644 --- a/test/parallel/test-stream-pipeline-queued-end-in-destroy.js +++ b/test/parallel/test-stream-pipeline-queued-end-in-destroy.js @@ -1,11 +1,11 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable, Duplex = _require.Duplex, pipeline = _require.pipeline; @@ -15,15 +15,15 @@ const _require = require('../../'), // get processed before the destruction of the stream (i.e. the 'close' event). // Refs: https://github.com/nodejs/node/issues/24456 -const readable = new Readable({ - read: common.mustCall(() => {}) +var readable = new Readable({ + read: common.mustCall(function () {}) }); -const duplex = new Duplex({ - write(chunk, enc, cb) { +var duplex = new Duplex({ + write: function write(chunk, enc, cb) { // Simulate messages queueing up. }, - read() {}, - destroy(err, cb) { + read: function read() {}, + destroy: function destroy(err, cb) { // Call end() from inside the destroy() method, like HTTP/2 streams // do at the time of writing. this.end(); @@ -31,14 +31,14 @@ const duplex = new Duplex({ } }); duplex.on('finished', common.mustNotCall()); -pipeline(readable, duplex, common.mustCall(err => { +pipeline(readable, duplex, common.mustCall(function (err) { assert.strictEqual(err.code, 'ERR_STREAM_PREMATURE_CLOSE'); })); // Write one chunk of data, and destroy the stream later. // That should trigger the pipeline destruction. readable.push('foo'); -setImmediate(() => { +setImmediate(function () { readable.destroy(); }); ; @@ -49,4 +49,6 @@ setImmediate(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index 4462d0200..85558843c 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -3,132 +3,138 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Stream = _require.Stream, Writable = _require.Writable, Readable = _require.Readable, Transform = _require.Transform, pipeline = _require.pipeline; -const assert = require('assert/'); -const http = require('http'); -const promisify = require('util-promisify'); +var assert = require('assert/'); +var http = require('http'); +var promisify = require('util-promisify'); { - let finished = false; - const processed = []; - const expected = [bufferShim.from('a'), bufferShim.from('b'), bufferShim.from('c')]; - const read = new Readable({ - read() {} - }); - const write = new Writable({ - write(data, enc, cb) { + var finished = false; + var processed = []; + var expected = [bufferShim.from('a'), bufferShim.from('b'), bufferShim.from('c')]; + var read = new Readable({ + read: function read() {} + }); + var write = new Writable({ + write: function write(data, enc, cb) { processed.push(data); cb(); } }); - write.on('finish', () => { + write.on('finish', function () { finished = true; }); - for (let i = 0; i < expected.length; i++) { + for (var i = 0; i < expected.length; i++) { read.push(expected[i]); } read.push(null); - pipeline(read, write, common.mustCall(err => { + pipeline(read, write, common.mustCall(function (err) { assert.ok(!err, 'no error'); assert.ok(finished); assert.deepStrictEqual(processed, expected); })); } { - const read = new Readable({ - read() {} + var _read = new Readable({ + read: function read() {} }); - assert.throws(() => { - pipeline(read, () => {}); + assert.throws(function () { + pipeline(_read, function () {}); }, /ERR_MISSING_ARGS/); - assert.throws(() => { - pipeline(() => {}); + assert.throws(function () { + pipeline(function () {}); }, /ERR_MISSING_ARGS/); - assert.throws(() => { + assert.throws(function () { pipeline(); }, /ERR_MISSING_ARGS/); } { - const read = new Readable({ - read() {} + var _read2 = new Readable({ + read: function read() {} }); - const write = new Writable({ - write(data, enc, cb) { + var _write = new Writable({ + write: function write(data, enc, cb) { cb(); } }); - read.push('data'); - setImmediate(() => read.destroy()); - pipeline(read, write, common.mustCall(err => { + _read2.push('data'); + setImmediate(function () { + return _read2.destroy(); + }); + pipeline(_read2, _write, common.mustCall(function (err) { assert.ok(err, 'should have an error'); })); } { - const read = new Readable({ - read() {} + var _read3 = new Readable({ + read: function read() {} }); - const write = new Writable({ - write(data, enc, cb) { + var _write2 = new Writable({ + write: function write(data, enc, cb) { cb(); } }); - read.push('data'); - setImmediate(() => read.destroy(new Error('kaboom'))); - const dst = pipeline(read, write, common.mustCall(err => { + _read3.push('data'); + setImmediate(function () { + return _read3.destroy(new Error('kaboom')); + }); + var dst = pipeline(_read3, _write2, common.mustCall(function (err) { assert.strictEqual(err.message, 'kaboom'); })); - assert.strictEqual(dst, write); + assert.strictEqual(dst, _write2); } { - const read = new Readable({ - read() {} + var _read4 = new Readable({ + read: function read() {} }); - const transform = new Transform({ - transform(data, enc, cb) { + var transform = new Transform({ + transform: function transform(data, enc, cb) { process.nextTick(cb, new Error('kaboom')); } }); - const write = new Writable({ - write(data, enc, cb) { + var _write3 = new Writable({ + write: function write(data, enc, cb) { cb(); } }); - read.on('close', common.mustCall()); + _read4.on('close', common.mustCall()); transform.on('close', common.mustCall()); - write.on('close', common.mustCall()); - const dst = pipeline(read, transform, write, common.mustCall(err => { + _write3.on('close', common.mustCall()); + var _dst = pipeline(_read4, transform, _write3, common.mustCall(function (err) { assert.strictEqual(err.message, 'kaboom'); })); - assert.strictEqual(dst, write); - read.push('hello'); + assert.strictEqual(_dst, _write3); + _read4.push('hello'); } { - const server = http.createServer((req, res) => { - const rs = new Readable({ - read() { + var server = http.createServer(function (req, res) { + var rs = new Readable({ + read: function read() { rs.push('hello'); rs.push(null); } }); - pipeline(rs, res, () => {}); + pipeline(rs, res, function () {}); }); - server.listen(0, () => { - const req = http.request({ + server.listen(0, function () { + var req = http.request({ port: server.address().port }); req.end(); - req.on('response', res => { - const buf = []; - res.on('data', data => buf.push(data)); - res.on('end', common.mustCall(() => { + req.on('response', function (res) { + var buf = []; + res.on('data', function (data) { + return buf.push(data); + }); + res.on('end', common.mustCall(function () { assert.deepStrictEqual(Buffer.concat(buf), bufferShim.from('hello')); server.close(); })); @@ -136,95 +142,95 @@ const promisify = require('util-promisify'); }); } { - const server = http.createServer((req, res) => { - let sent = false; - const rs = new Readable({ - read() { + var _server = http.createServer(function (req, res) { + var sent = false; + var rs = new Readable({ + read: function read() { if (sent) { return; } sent = true; rs.push('hello'); }, - destroy: common.mustCall((err, cb) => { + destroy: common.mustCall(function (err, cb) { // prevents fd leaks by destroying http pipelines cb(); }) }); - pipeline(rs, res, () => {}); + pipeline(rs, res, function () {}); }); - server.listen(0, () => { - const req = http.request({ - port: server.address().port + _server.listen(0, function () { + var req = http.request({ + port: _server.address().port }); req.end(); - req.on('response', res => { - setImmediate(() => { + req.on('response', function (res) { + setImmediate(function () { res.destroy(); - server.close(); + _server.close(); }); }); }); } { - const server = http.createServer((req, res) => { - let sent = 0; - const rs = new Readable({ - read() { + var _server2 = http.createServer(function (req, res) { + var sent = 0; + var rs = new Readable({ + read: function read() { if (sent++ > 10) { return; } rs.push('hello'); }, - destroy: common.mustCall((err, cb) => { + destroy: common.mustCall(function (err, cb) { cb(); }) }); - pipeline(rs, res, () => {}); + pipeline(rs, res, function () {}); }); - let cnt = 10; - const badSink = new Writable({ - write(data, enc, cb) { + var cnt = 10; + var badSink = new Writable({ + write: function write(data, enc, cb) { cnt--; if (cnt === 0) process.nextTick(cb, new Error('kaboom'));else cb(); } }); - server.listen(0, () => { - const req = http.request({ - port: server.address().port + _server2.listen(0, function () { + var req = http.request({ + port: _server2.address().port }); req.end(); - req.on('response', res => { - pipeline(res, badSink, common.mustCall(err => { + req.on('response', function (res) { + pipeline(res, badSink, common.mustCall(function (err) { assert.strictEqual(err.message, 'kaboom'); - server.close(); + _server2.close(); })); }); }); } { - const server = http.createServer((req, res) => { + var _server3 = http.createServer(function (req, res) { pipeline(req, res, common.mustCall()); }); - server.listen(0, () => { - const req = http.request({ - port: server.address().port + _server3.listen(0, function () { + var req = http.request({ + port: _server3.address().port }); - let sent = 0; - const rs = new Readable({ - read() { + var sent = 0; + var rs = new Readable({ + read: function read() { if (sent++ > 10) { return; } rs.push('hello'); } }); - pipeline(rs, req, common.mustCall(() => { - server.close(); + pipeline(rs, req, common.mustCall(function () { + _server3.close(); })); - req.on('response', res => { - let cnt = 10; - res.on('data', () => { + req.on('response', function (res) { + var cnt = 10; + res.on('data', function () { cnt--; if (cnt === 0) rs.destroy(); }); @@ -232,160 +238,159 @@ const promisify = require('util-promisify'); }); } { - const makeTransform = () => { - const tr = new Transform({ - transform(data, enc, cb) { + var makeTransform = function makeTransform() { + var tr = new Transform({ + transform: function transform(data, enc, cb) { cb(null, data); } }); tr.on('close', common.mustCall()); return tr; }; - const rs = new Readable({ - read() { + var rs = new Readable({ + read: function read() { rs.push('hello'); } }); - let cnt = 10; - const ws = new Writable({ - write(data, enc, cb) { - cnt--; - if (cnt === 0) return process.nextTick(cb, new Error('kaboom')); + var _cnt = 10; + var ws = new Writable({ + write: function write(data, enc, cb) { + _cnt--; + if (_cnt === 0) return process.nextTick(cb, new Error('kaboom')); cb(); } }); rs.on('close', common.mustCall()); ws.on('close', common.mustCall()); - pipeline(rs, makeTransform(), makeTransform(), makeTransform(), makeTransform(), makeTransform(), makeTransform(), ws, common.mustCall(err => { + pipeline(rs, makeTransform(), makeTransform(), makeTransform(), makeTransform(), makeTransform(), makeTransform(), ws, common.mustCall(function (err) { assert.strictEqual(err.message, 'kaboom'); })); } { - const oldStream = new Stream(); - oldStream.pause = oldStream.resume = () => {}; - oldStream.write = data => { + var oldStream = new Stream(); + oldStream.pause = oldStream.resume = function () {}; + oldStream.write = function (data) { oldStream.emit('data', data); return true; }; - oldStream.end = () => { + oldStream.end = function () { oldStream.emit('end'); }; - const expected = [bufferShim.from('hello'), bufferShim.from('world')]; - const rs = new Readable({ - read() { - for (let i = 0; i < expected.length; i++) { - rs.push(expected[i]); + var _expected = [bufferShim.from('hello'), bufferShim.from('world')]; + var _rs = new Readable({ + read: function read() { + for (var _i = 0; _i < _expected.length; _i++) { + _rs.push(_expected[_i]); } - rs.push(null); + _rs.push(null); } }); - const ws = new Writable({ - write(data, enc, cb) { - assert.deepStrictEqual(data, expected.shift()); + var _ws = new Writable({ + write: function write(data, enc, cb) { + assert.deepStrictEqual(data, _expected.shift()); cb(); } }); - let finished = false; - ws.on('finish', () => { - finished = true; + var _finished = false; + _ws.on('finish', function () { + _finished = true; }); - pipeline(rs, oldStream, ws, common.mustCall(err => { + pipeline(_rs, oldStream, _ws, common.mustCall(function (err) { assert(!err, 'no error'); - assert(finished, 'last stream finished'); + assert(_finished, 'last stream finished'); })); } { - const oldStream = new Stream(); - oldStream.pause = oldStream.resume = () => {}; - oldStream.write = data => { - oldStream.emit('data', data); + var _oldStream = new Stream(); + _oldStream.pause = _oldStream.resume = function () {}; + _oldStream.write = function (data) { + _oldStream.emit('data', data); return true; }; - oldStream.end = () => { - oldStream.emit('end'); + _oldStream.end = function () { + _oldStream.emit('end'); }; - const destroyableOldStream = new Stream(); - destroyableOldStream.pause = destroyableOldStream.resume = () => {}; - destroyableOldStream.destroy = common.mustCall(() => { + var destroyableOldStream = new Stream(); + destroyableOldStream.pause = destroyableOldStream.resume = function () {}; + destroyableOldStream.destroy = common.mustCall(function () { destroyableOldStream.emit('close'); }); - destroyableOldStream.write = data => { + destroyableOldStream.write = function (data) { destroyableOldStream.emit('data', data); return true; }; - destroyableOldStream.end = () => { + destroyableOldStream.end = function () { destroyableOldStream.emit('end'); }; - const rs = new Readable({ - read() { - rs.destroy(new Error('stop')); + var _rs2 = new Readable({ + read: function read() { + _rs2.destroy(new Error('stop')); } }); - const ws = new Writable({ - write(data, enc, cb) { + var _ws2 = new Writable({ + write: function write(data, enc, cb) { cb(); } }); - let finished = false; - ws.on('finish', () => { - finished = true; + var _finished2 = false; + _ws2.on('finish', function () { + _finished2 = true; }); - pipeline(rs, oldStream, destroyableOldStream, ws, common.mustCall(err => { + pipeline(_rs2, _oldStream, destroyableOldStream, _ws2, common.mustCall(function (err) { assert.deepStrictEqual(err, new Error('stop')); - assert(!finished, 'should not finish'); + assert(!_finished2, 'should not finish'); })); } { - const pipelinePromise = promisify(pipeline); - function run() { - return _run.apply(this, arguments); - } - function _run() { - _run = _asyncToGenerator(function* () { - const read = new Readable({ - read() {} + var run = /*#__PURE__*/function () { + var _ref = _asyncToGenerator(function* () { + var read = new Readable({ + read: function read() {} }); - const write = new Writable({ - write(data, enc, cb) { + var write = new Writable({ + write: function write(data, enc, cb) { cb(); } }); read.push('data'); read.push(null); - let finished = false; - write.on('finish', () => { + var finished = false; + write.on('finish', function () { finished = true; }); yield pipelinePromise(read, write); assert(finished); }); - return _run.apply(this, arguments); - } + return function run() { + return _ref.apply(this, arguments); + }; + }(); + var pipelinePromise = promisify(pipeline); run(); } { - const read = new Readable({ - read() {} + var _read5 = new Readable({ + read: function read() {} }); - const transform = new Transform({ - transform(data, enc, cb) { + var _transform = new Transform({ + transform: function transform(data, enc, cb) { process.nextTick(cb, new Error('kaboom')); } }); - const write = new Writable({ - write(data, enc, cb) { + var _write4 = new Writable({ + write: function write(data, enc, cb) { cb(); } }); - read.on('close', common.mustCall()); - transform.on('close', common.mustCall()); - write.on('close', common.mustCall()); - process.on('uncaughtException', common.mustCall(err => { + _read5.on('close', common.mustCall()); + _transform.on('close', common.mustCall()); + _write4.on('close', common.mustCall()); + process.on('uncaughtException', common.mustCall(function (err) { assert.strictEqual(err.message, 'kaboom'); })); - const dst = pipeline(read, transform, write); - assert.strictEqual(dst, write); - read.push('hello'); + var _dst2 = pipeline(_read5, _transform, _write4); + assert.strictEqual(_dst2, _write4); + _read5.push('hello'); } ; (function () { @@ -395,4 +400,6 @@ const promisify = require('util-promisify'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-push-order.js b/test/parallel/test-stream-push-order.js index c2e080f92..76766cba6 100644 --- a/test/parallel/test-stream-push-order.js +++ b/test/parallel/test-stream-push-order.js @@ -22,22 +22,22 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const Readable = require('../../').Readable; -const assert = require('assert/'); -const s = new Readable({ +var Readable = require('../../').Readable; +var assert = require('assert/'); +var s = new Readable({ highWaterMark: 20, encoding: 'ascii' }); -const list = ['1', '2', '3', '4', '5', '6']; +var list = ['1', '2', '3', '4', '5', '6']; s._read = function (n) { - const one = list.shift(); + var one = list.shift(); if (!one) { s.push(null); } else { - const two = list.shift(); + var two = list.shift(); s.push(one); s.push(two); } @@ -58,4 +58,6 @@ process.on('exit', function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-push-strings.js b/test/parallel/test-stream-push-strings.js index 2cfdfff53..a98b06ed4 100644 --- a/test/parallel/test-stream-push-strings.js +++ b/test/parallel/test-stream-push-strings.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,42 +34,52 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const Readable = require('../../').Readable; -class MyStream extends Readable { - constructor(options) { - super(options); - this._chunks = 3; +var assert = require('assert/'); +var Readable = require('../../').Readable; +var MyStream = /*#__PURE__*/function (_Readable) { + _inherits(MyStream, _Readable); + var _super = _createSuper(MyStream); + function MyStream(options) { + var _this; + _classCallCheck(this, MyStream); + _this = _super.call(this, options); + _this._chunks = 3; + return _this; } - _read(n) { - switch (this._chunks--) { - case 0: - return this.push(null); - case 1: - return setTimeout(() => { - this.push('last chunk'); - }, 100); - case 2: - return this.push('second to last chunk'); - case 3: - return process.nextTick(() => { - this.push('first chunk'); - }); - default: - throw new Error('?'); + _createClass(MyStream, [{ + key: "_read", + value: function _read(n) { + var _this2 = this; + switch (this._chunks--) { + case 0: + return this.push(null); + case 1: + return setTimeout(function () { + _this2.push('last chunk'); + }, 100); + case 2: + return this.push('second to last chunk'); + case 3: + return process.nextTick(function () { + _this2.push('first chunk'); + }); + default: + throw new Error('?'); + } } - } -} -const ms = new MyStream(); -const results = []; + }]); + return MyStream; +}(Readable); +var ms = new MyStream(); +var results = []; ms.on('readable', function () { - let chunk; + var chunk; while (null !== (chunk = ms.read())) results.push(String(chunk)); }); -const expect = ['first chunksecond to last chunk', 'last chunk']; +var expect = ['first chunksecond to last chunk', 'last chunk']; process.on('exit', function () { assert.strictEqual(ms._chunks, -1); assert.deepStrictEqual(results, expect); @@ -71,4 +93,6 @@ process.on('exit', function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-async-iterators.js b/test/parallel/test-stream-readable-async-iterators.js index 120311884..1394f7185 100644 --- a/test/parallel/test-stream-readable-async-iterators.js +++ b/test/parallel/test-stream-readable-async-iterators.js @@ -5,41 +5,41 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); } function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function _return(value) { var ret = this.s.return; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, throw: function _throw(value) { var thr = this.s.return; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); } /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable, PassThrough = _require.PassThrough, pipeline = _require.pipeline; -const assert = require('assert/'); +var assert = require('assert/'); function tests() { return _tests.apply(this, arguments); } // to avoid missing some tests if a promise does not resolve function _tests() { _tests = _asyncToGenerator(function* () { { - const AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); - const rs = new Readable({}); + var AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); + var rs = new Readable({}); assert.strictEqual(Object.getPrototypeOf(Object.getPrototypeOf(rs[Symbol.asyncIterator]())), AsyncIteratorPrototype); } { - const readable = new Readable({ + var readable = new Readable({ objectMode: true, - read() {} + read: function read() {} }); readable.push(0); readable.push(1); readable.push(null); - const iter = readable[Symbol.asyncIterator](); + var iter = readable[Symbol.asyncIterator](); assert.strictEqual((yield iter.next()).value, 0); var _iteratorAbruptCompletion = false; var _didIteratorError = false; var _iteratorError; try { for (var _iterator = _asyncIterator(iter), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) { - const d = _step.value; + var d = _step.value; { assert.strictEqual(d, 1); } @@ -61,99 +61,107 @@ function _tests() { } { console.log('read without for..await'); - const max = 5; - const readable = new Readable({ + var max = 5; + var _readable = new Readable({ objectMode: true, - read() {} + read: function read() {} }); - const iter = readable[Symbol.asyncIterator](); - assert.strictEqual(iter.stream, readable); - const values = []; - for (let i = 0; i < max; i++) { - values.push(iter.next()); + var _iter = _readable[Symbol.asyncIterator](); + assert.strictEqual(_iter.stream, _readable); + var values = []; + for (var i = 0; i < max; i++) { + values.push(_iter.next()); } - Promise.all(values).then(common.mustCall(values => { - values.forEach(common.mustCall((item, i) => assert.strictEqual(item.value, 'hello-' + i), 5)); + Promise.all(values).then(common.mustCall(function (values) { + values.forEach(common.mustCall(function (item, i) { + return assert.strictEqual(item.value, 'hello-' + i); + }, 5)); })); - readable.push('hello-0'); - readable.push('hello-1'); - readable.push('hello-2'); - readable.push('hello-3'); - readable.push('hello-4'); - readable.push(null); - const last = yield iter.next(); + _readable.push('hello-0'); + _readable.push('hello-1'); + _readable.push('hello-2'); + _readable.push('hello-3'); + _readable.push('hello-4'); + _readable.push(null); + var last = yield _iter.next(); assert.strictEqual(last.done, true); } { console.log('read without for..await deferred'); - const readable = new Readable({ + var _readable2 = new Readable({ objectMode: true, - read() {} + read: function read() {} }); - const iter = readable[Symbol.asyncIterator](); - assert.strictEqual(iter.stream, readable); - let values = []; - for (let i = 0; i < 3; i++) { - values.push(iter.next()); + var _iter2 = _readable2[Symbol.asyncIterator](); + assert.strictEqual(_iter2.stream, _readable2); + var _values = []; + for (var _i = 0; _i < 3; _i++) { + _values.push(_iter2.next()); } - readable.push('hello-0'); - readable.push('hello-1'); - readable.push('hello-2'); - let k = 0; - const results1 = yield Promise.all(values); - results1.forEach(common.mustCall(item => assert.strictEqual(item.value, 'hello-' + k++), 3)); - values = []; - for (let i = 0; i < 2; i++) { - values.push(iter.next()); + _readable2.push('hello-0'); + _readable2.push('hello-1'); + _readable2.push('hello-2'); + var k = 0; + var results1 = yield Promise.all(_values); + results1.forEach(common.mustCall(function (item) { + return assert.strictEqual(item.value, 'hello-' + k++); + }, 3)); + _values = []; + for (var _i2 = 0; _i2 < 2; _i2++) { + _values.push(_iter2.next()); } - readable.push('hello-3'); - readable.push('hello-4'); - readable.push(null); - const results2 = yield Promise.all(values); - results2.forEach(common.mustCall(item => assert.strictEqual(item.value, 'hello-' + k++), 2)); - const last = yield iter.next(); - assert.strictEqual(last.done, true); + _readable2.push('hello-3'); + _readable2.push('hello-4'); + _readable2.push(null); + var results2 = yield Promise.all(_values); + results2.forEach(common.mustCall(function (item) { + return assert.strictEqual(item.value, 'hello-' + k++); + }, 2)); + var _last = yield _iter2.next(); + assert.strictEqual(_last.done, true); } { console.log('read without for..await with errors'); - const max = 3; - const readable = new Readable({ + var _max = 3; + var _readable3 = new Readable({ objectMode: true, - read() {} + read: function read() {} }); - const iter = readable[Symbol.asyncIterator](); - assert.strictEqual(iter.stream, readable); - const values = []; - const errors = []; - let i; - for (i = 0; i < max; i++) { - values.push(iter.next()); + var _iter3 = _readable3[Symbol.asyncIterator](); + assert.strictEqual(_iter3.stream, _readable3); + var _values2 = []; + var errors = []; + var _i3; + for (_i3 = 0; _i3 < _max; _i3++) { + _values2.push(_iter3.next()); } - for (i = 0; i < 2; i++) { - errors.push(iter.next()); + for (_i3 = 0; _i3 < 2; _i3++) { + errors.push(_iter3.next()); } - readable.push('hello-0'); - readable.push('hello-1'); - readable.push('hello-2'); - const resolved = yield Promise.all(values); - resolved.forEach(common.mustCall((item, i) => assert.strictEqual(item.value, 'hello-' + i), max)); - errors.forEach(promise => { - promise.catch(common.mustCall(err => { + _readable3.push('hello-0'); + _readable3.push('hello-1'); + _readable3.push('hello-2'); + var resolved = yield Promise.all(_values2); + resolved.forEach(common.mustCall(function (item, i) { + return assert.strictEqual(item.value, 'hello-' + i); + }, _max)); + errors.forEach(function (promise) { + promise.catch(common.mustCall(function (err) { assert.strictEqual(err.message, 'kaboom'); })); }); - readable.destroy(new Error('kaboom')); + _readable3.destroy(new Error('kaboom')); } { console.log('call next() after error'); - const readable = new Readable({ - read() {} + var _readable4 = new Readable({ + read: function read() {} }); - const iterator = readable[Symbol.asyncIterator](); - const err = new Error('kaboom'); - readable.destroy(new Error('kaboom')); + var iterator = _readable4[Symbol.asyncIterator](); + var err = new Error('kaboom'); + _readable4.destroy(new Error('kaboom')); yield function (f, e) { - let success = false; + var success = false; f().then(function () { success = true; throw new Error('should not succeed'); @@ -167,14 +175,14 @@ function _tests() { } { console.log('read object mode'); - const max = 42; - let readed = 0; - let received = 0; - const readable = new Readable({ + var _max2 = 42; + var readed = 0; + var received = 0; + var _readable5 = new Readable({ objectMode: true, - read() { + read: function read() { this.push('hello'); - if (++readed === max) { + if (++readed === _max2) { this.push(null); } } @@ -183,11 +191,11 @@ function _tests() { var _didIteratorError2 = false; var _iteratorError2; try { - for (var _iterator2 = _asyncIterator(readable), _step2; _iteratorAbruptCompletion2 = !(_step2 = yield _iterator2.next()).done; _iteratorAbruptCompletion2 = false) { - const k = _step2.value; + for (var _iterator2 = _asyncIterator(_readable5), _step2; _iteratorAbruptCompletion2 = !(_step2 = yield _iterator2.next()).done; _iteratorAbruptCompletion2 = false) { + var _k = _step2.value; { received++; - assert.strictEqual(k, 'hello'); + assert.strictEqual(_k, 'hello'); } } } catch (err) { @@ -208,21 +216,21 @@ function _tests() { } { console.log('destroy sync'); - const readable = new Readable({ + var _readable6 = new Readable({ objectMode: true, - read() { + read: function read() { this.destroy(new Error('kaboom from read')); } }); - let err; + var _err; try { // eslint-disable-next-line no-unused-vars var _iteratorAbruptCompletion3 = false; var _didIteratorError3 = false; var _iteratorError3; try { - for (var _iterator3 = _asyncIterator(readable), _step3; _iteratorAbruptCompletion3 = !(_step3 = yield _iterator3.next()).done; _iteratorAbruptCompletion3 = false) { - const k = _step3.value; + for (var _iterator3 = _asyncIterator(_readable6), _step3; _iteratorAbruptCompletion3 = !(_step3 = yield _iterator3.next()).done; _iteratorAbruptCompletion3 = false) { + var _k2 = _step3.value; } } catch (err) { _didIteratorError3 = true; @@ -239,36 +247,37 @@ function _tests() { } } } catch (e) { - err = e; + _err = e; } - assert.strictEqual(err.message, 'kaboom from read'); + assert.strictEqual(_err.message, 'kaboom from read'); } { console.log('destroy async'); - const readable = new Readable({ + var _readable7 = new Readable({ objectMode: true, - read() { + read: function read() { + var _this = this; if (!this.pushed) { this.push('hello'); this.pushed = true; - setImmediate(() => { - this.destroy(new Error('kaboom')); + setImmediate(function () { + _this.destroy(new Error('kaboom')); }); } } }); - let received = 0; - let err = null; + var _received = 0; + var _err2 = null; try { // eslint-disable-next-line no-unused-vars var _iteratorAbruptCompletion4 = false; var _didIteratorError4 = false; var _iteratorError4; try { - for (var _iterator4 = _asyncIterator(readable), _step4; _iteratorAbruptCompletion4 = !(_step4 = yield _iterator4.next()).done; _iteratorAbruptCompletion4 = false) { - const k = _step4.value; + for (var _iterator4 = _asyncIterator(_readable7), _step4; _iteratorAbruptCompletion4 = !(_step4 = yield _iterator4.next()).done; _iteratorAbruptCompletion4 = false) { + var _k3 = _step4.value; { - received++; + _received++; } } } catch (err) { @@ -286,29 +295,29 @@ function _tests() { } } } catch (e) { - err = e; + _err2 = e; } - assert.strictEqual(err.message, 'kaboom'); - assert.strictEqual(received, 1); + assert.strictEqual(_err2.message, 'kaboom'); + assert.strictEqual(_received, 1); } { console.log('destroyed by throw'); - const readable = new Readable({ + var _readable8 = new Readable({ objectMode: true, - read() { + read: function read() { this.push('hello'); } }); - let err = null; + var _err3 = null; try { var _iteratorAbruptCompletion5 = false; var _didIteratorError5 = false; var _iteratorError5; try { - for (var _iterator5 = _asyncIterator(readable), _step5; _iteratorAbruptCompletion5 = !(_step5 = yield _iterator5.next()).done; _iteratorAbruptCompletion5 = false) { - const k = _step5.value; + for (var _iterator5 = _asyncIterator(_readable8), _step5; _iteratorAbruptCompletion5 = !(_step5 = yield _iterator5.next()).done; _iteratorAbruptCompletion5 = false) { + var _k4 = _step5.value; { - assert.strictEqual(k, 'hello'); + assert.strictEqual(_k4, 'hello'); throw new Error('kaboom'); } } @@ -327,32 +336,32 @@ function _tests() { } } } catch (e) { - err = e; + _err3 = e; } - assert.strictEqual(err.message, 'kaboom'); - assert.strictEqual(readable.destroyed, true); + assert.strictEqual(_err3.message, 'kaboom'); + assert.strictEqual(_readable8.destroyed, true); } { console.log('destroyed sync after push'); - const readable = new Readable({ + var _readable9 = new Readable({ objectMode: true, - read() { + read: function read() { this.push('hello'); this.destroy(new Error('kaboom')); } }); - let received = 0; - let err = null; + var _received2 = 0; + var _err4 = null; try { var _iteratorAbruptCompletion6 = false; var _didIteratorError6 = false; var _iteratorError6; try { - for (var _iterator6 = _asyncIterator(readable), _step6; _iteratorAbruptCompletion6 = !(_step6 = yield _iterator6.next()).done; _iteratorAbruptCompletion6 = false) { - const k = _step6.value; + for (var _iterator6 = _asyncIterator(_readable9), _step6; _iteratorAbruptCompletion6 = !(_step6 = yield _iterator6.next()).done; _iteratorAbruptCompletion6 = false) { + var _k5 = _step6.value; { - assert.strictEqual(k, 'hello'); - received++; + assert.strictEqual(_k5, 'hello'); + _received2++; } } } catch (err) { @@ -370,23 +379,24 @@ function _tests() { } } } catch (e) { - err = e; + _err4 = e; } - assert.strictEqual(err.message, 'kaboom'); - assert.strictEqual(received, 1); + assert.strictEqual(_err4.message, 'kaboom'); + assert.strictEqual(_received2, 1); } { console.log('push async'); - const max = 42; - let readed = 0; - let received = 0; - const readable = new Readable({ + var _max3 = 42; + var _readed = 0; + var _received3 = 0; + var _readable10 = new Readable({ objectMode: true, - read() { - setImmediate(() => { - this.push('hello'); - if (++readed === max) { - this.push(null); + read: function read() { + var _this2 = this; + setImmediate(function () { + _this2.push('hello'); + if (++_readed === _max3) { + _this2.push(null); } }); } @@ -395,11 +405,11 @@ function _tests() { var _didIteratorError7 = false; var _iteratorError7; try { - for (var _iterator7 = _asyncIterator(readable), _step7; _iteratorAbruptCompletion7 = !(_step7 = yield _iterator7.next()).done; _iteratorAbruptCompletion7 = false) { - const k = _step7.value; + for (var _iterator7 = _asyncIterator(_readable10), _step7; _iteratorAbruptCompletion7 = !(_step7 = yield _iterator7.next()).done; _iteratorAbruptCompletion7 = false) { + var _k6 = _step7.value; { - received++; - assert.strictEqual(k, 'hello'); + _received3++; + assert.strictEqual(_k6, 'hello'); } } } catch (err) { @@ -416,37 +426,38 @@ function _tests() { } } } - assert.strictEqual(readed, received); + assert.strictEqual(_readed, _received3); } { console.log('push binary async'); - const max = 42; - let readed = 0; - const readable = new Readable({ - read() { - setImmediate(() => { - this.push('hello'); - if (++readed === max) { - this.push(null); + var _max4 = 42; + var _readed2 = 0; + var _readable11 = new Readable({ + read: function read() { + var _this3 = this; + setImmediate(function () { + _this3.push('hello'); + if (++_readed2 === _max4) { + _this3.push(null); } }); } }); - let expected = ''; - readable.setEncoding('utf8'); - readable.pause(); - readable.on('data', chunk => { + var expected = ''; + _readable11.setEncoding('utf8'); + _readable11.pause(); + _readable11.on('data', function (chunk) { expected += chunk; }); - let data = ''; + var data = ''; var _iteratorAbruptCompletion8 = false; var _didIteratorError8 = false; var _iteratorError8; try { - for (var _iterator8 = _asyncIterator(readable), _step8; _iteratorAbruptCompletion8 = !(_step8 = yield _iterator8.next()).done; _iteratorAbruptCompletion8 = false) { - const k = _step8.value; + for (var _iterator8 = _asyncIterator(_readable11), _step8; _iteratorAbruptCompletion8 = !(_step8 = yield _iterator8.next()).done; _iteratorAbruptCompletion8 = false) { + var _k7 = _step8.value; { - data += k; + data += _k7; } } } catch (err) { @@ -467,40 +478,40 @@ function _tests() { } { console.log('.next() on destroyed stream'); - const readable = new Readable({ - read() { + var _readable12 = new Readable({ + read: function read() { // no-op } }); - readable.destroy(); - const _yield$readable$Symbo = yield readable[Symbol.asyncIterator]().next(), - done = _yield$readable$Symbo.done; + _readable12.destroy(); + var _yield$_readable12$Sy = yield _readable12[Symbol.asyncIterator]().next(), + done = _yield$_readable12$Sy.done; assert.strictEqual(done, true); } { console.log('.next() on pipelined stream'); - const readable = new Readable({ - read() { + var _readable13 = new Readable({ + read: function read() { // no-op } }); - const passthrough = new PassThrough(); - const err = new Error('kaboom'); - pipeline(readable, passthrough, common.mustCall(e => { - assert.strictEqual(e, err); + var passthrough = new PassThrough(); + var _err5 = new Error('kaboom'); + pipeline(_readable13, passthrough, common.mustCall(function (e) { + assert.strictEqual(e, _err5); })); - readable.destroy(err); + _readable13.destroy(_err5); try { - yield readable[Symbol.asyncIterator]().next(); + yield _readable13[Symbol.asyncIterator]().next(); } catch (e) { - assert.strictEqual(e, err); + assert.strictEqual(e, _err5); } } { console.log('iterating on an ended stream completes'); - const r = new Readable({ + var r = new Readable({ objectMode: true, - read() { + read: function read() { this.push('asdf'); this.push('hehe'); this.push(null); @@ -512,7 +523,7 @@ function _tests() { var _iteratorError9; try { for (var _iterator9 = _asyncIterator(r), _step9; _iteratorAbruptCompletion9 = !(_step9 = yield _iterator9.next()).done; _iteratorAbruptCompletion9 = false) { - const a = _step9.value; + var a = _step9.value; } // eslint-disable-next-line no-unused-vars } catch (err) { @@ -534,7 +545,7 @@ function _tests() { var _iteratorError10; try { for (var _iterator10 = _asyncIterator(r), _step10; _iteratorAbruptCompletion10 = !(_step10 = yield _iterator10.next()).done; _iteratorAbruptCompletion10 = false) { - const b = _step10.value; + var b = _step10.value; } } catch (err) { _didIteratorError10 = true; @@ -553,9 +564,9 @@ function _tests() { } { console.log('destroy mid-stream does not error'); - const r = new Readable({ + var _r = new Readable({ objectMode: true, - read() { + read: function read() { this.push('asdf'); this.push('hehe'); } @@ -566,10 +577,10 @@ function _tests() { var _didIteratorError11 = false; var _iteratorError11; try { - for (var _iterator11 = _asyncIterator(r), _step11; _iteratorAbruptCompletion11 = !(_step11 = yield _iterator11.next()).done; _iteratorAbruptCompletion11 = false) { - const a = _step11.value; + for (var _iterator11 = _asyncIterator(_r), _step11; _iteratorAbruptCompletion11 = !(_step11 = yield _iterator11.next()).done; _iteratorAbruptCompletion11 = false) { + var _a = _step11.value; { - r.destroy(null); + _r.destroy(null); } } } catch (err) { @@ -589,69 +600,69 @@ function _tests() { } { console.log('all next promises must be resolved on end'); - const r = new Readable({ + var _r2 = new Readable({ objectMode: true, - read() {} + read: function read() {} }); - const b = r[Symbol.asyncIterator](); - const c = b.next(); - const d = b.next(); - r.push(null); + var _b = _r2[Symbol.asyncIterator](); + var c = _b.next(); + var _d = _b.next(); + _r2.push(null); assert.deepStrictEqual(yield c, { done: true, value: undefined }); - assert.deepStrictEqual(yield d, { + assert.deepStrictEqual(yield _d, { done: true, value: undefined }); } { console.log('all next promises must be resolved on destroy'); - const r = new Readable({ + var _r3 = new Readable({ objectMode: true, - read() {} + read: function read() {} }); - const b = r[Symbol.asyncIterator](); - const c = b.next(); - const d = b.next(); - r.destroy(); - assert.deepStrictEqual(yield c, { + var _b2 = _r3[Symbol.asyncIterator](); + var _c = _b2.next(); + var _d2 = _b2.next(); + _r3.destroy(); + assert.deepStrictEqual(yield _c, { done: true, value: undefined }); - assert.deepStrictEqual(yield d, { + assert.deepStrictEqual(yield _d2, { done: true, value: undefined }); } { console.log('all next promises must be resolved on destroy with error'); - const r = new Readable({ + var _r4 = new Readable({ objectMode: true, - read() {} + read: function read() {} }); - const b = r[Symbol.asyncIterator](); - const c = b.next(); - const d = b.next(); - const err = new Error('kaboom'); - r.destroy(err); + var _b3 = _r4[Symbol.asyncIterator](); + var _c2 = _b3.next(); + var _d3 = _b3.next(); + var _err6 = new Error('kaboom'); + _r4.destroy(_err6); yield Promise.all([_asyncToGenerator(function* () { - let e; + var e; try { - yield c; + yield _c2; } catch (_e) { e = _e; } - assert.strictEqual(e, err); + assert.strictEqual(e, _err6); })(), _asyncToGenerator(function* () { - let e; + var e; try { - yield d; + yield _d3; } catch (_e) { e = _e; } - assert.strictEqual(e, err); + assert.strictEqual(e, _err6); })()]); } }); @@ -666,4 +677,6 @@ tests().then(common.mustCall(), common.mustNotCall(console.log)); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-constructor-set-methods.js b/test/parallel/test-stream-readable-constructor-set-methods.js index d8db75626..6f7ea6f24 100644 --- a/test/parallel/test-stream-readable-constructor-set-methods.js +++ b/test/parallel/test-stream-readable-constructor-set-methods.js @@ -1,14 +1,14 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const Readable = require('../../').Readable; -const _read = common.mustCall(function _read(n) { +var common = require('../common'); +var Readable = require('../../').Readable; +var _read = common.mustCall(function _read(n) { this.push(null); }); -const r = new Readable({ +var r = new Readable({ read: _read }); r.resume(); @@ -20,4 +20,6 @@ r.resume(); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-destroy.js b/test/parallel/test-stream-readable-destroy.js index ea7400f75..79192adfb 100644 --- a/test/parallel/test-stream-readable-destroy.js +++ b/test/parallel/test-stream-readable-destroy.js @@ -1,16 +1,16 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable; -const assert = require('assert/'); +var assert = require('assert/'); { - const read = new Readable({ - read() {} + var read = new Readable({ + read: function read() {} }); read.resume(); read.on('close', common.mustCall()); @@ -18,141 +18,142 @@ const assert = require('assert/'); assert.strictEqual(read.destroyed, true); } { - const read = new Readable({ - read() {} + var _read = new Readable({ + read: function read() {} }); - read.resume(); - const expected = new Error('kaboom'); - read.on('end', common.mustNotCall('no end event')); - read.on('close', common.mustCall()); - read.on('error', common.mustCall(err => { + _read.resume(); + var expected = new Error('kaboom'); + _read.on('end', common.mustNotCall('no end event')); + _read.on('close', common.mustCall()); + _read.on('error', common.mustCall(function (err) { assert.strictEqual(err, expected); })); - read.destroy(expected); - assert.strictEqual(read.destroyed, true); + _read.destroy(expected); + assert.strictEqual(_read.destroyed, true); } { - const read = new Readable({ - read() {} + var _read2 = new Readable({ + read: function read() {} }); - read._destroy = common.mustCall(function (err, cb) { - assert.strictEqual(err, expected); + _read2._destroy = common.mustCall(function (err, cb) { + assert.strictEqual(err, _expected); cb(err); }); - const expected = new Error('kaboom'); - read.on('end', common.mustNotCall('no end event')); - read.on('close', common.mustCall()); - read.on('error', common.mustCall(err => { - assert.strictEqual(err, expected); + var _expected = new Error('kaboom'); + _read2.on('end', common.mustNotCall('no end event')); + _read2.on('close', common.mustCall()); + _read2.on('error', common.mustCall(function (err) { + assert.strictEqual(err, _expected); })); - read.destroy(expected); - assert.strictEqual(read.destroyed, true); + _read2.destroy(_expected); + assert.strictEqual(_read2.destroyed, true); } { - const read = new Readable({ - read() {}, + var _read3 = new Readable({ + read: function read() {}, destroy: common.mustCall(function (err, cb) { - assert.strictEqual(err, expected); + assert.strictEqual(err, _expected2); cb(); }) }); - const expected = new Error('kaboom'); - read.on('end', common.mustNotCall('no end event')); + var _expected2 = new Error('kaboom'); + _read3.on('end', common.mustNotCall('no end event')); // error is swallowed by the custom _destroy - read.on('error', common.mustNotCall('no error event')); - read.on('close', common.mustCall()); - read.destroy(expected); - assert.strictEqual(read.destroyed, true); + _read3.on('error', common.mustNotCall('no error event')); + _read3.on('close', common.mustCall()); + _read3.destroy(_expected2); + assert.strictEqual(_read3.destroyed, true); } { - const read = new Readable({ - read() {} + var _read4 = new Readable({ + read: function read() {} }); - read._destroy = common.mustCall(function (err, cb) { + _read4._destroy = common.mustCall(function (err, cb) { assert.strictEqual(err, null); cb(); }); - read.destroy(); - assert.strictEqual(read.destroyed, true); + _read4.destroy(); + assert.strictEqual(_read4.destroyed, true); } { - const read = new Readable({ - read() {} + var _read5 = new Readable({ + read: function read() {} }); - read.resume(); - read._destroy = common.mustCall(function (err, cb) { + _read5.resume(); + _read5._destroy = common.mustCall(function (err, cb) { + var _this = this; assert.strictEqual(err, null); - process.nextTick(() => { - this.push(null); + process.nextTick(function () { + _this.push(null); cb(); }); }); - const fail = common.mustNotCall('no end event'); - read.on('end', fail); - read.on('close', common.mustCall()); - read.destroy(); - read.removeListener('end', fail); - read.on('end', common.mustCall()); - assert.strictEqual(read.destroyed, true); + var fail = common.mustNotCall('no end event'); + _read5.on('end', fail); + _read5.on('close', common.mustCall()); + _read5.destroy(); + _read5.removeListener('end', fail); + _read5.on('end', common.mustCall()); + assert.strictEqual(_read5.destroyed, true); } { - const read = new Readable({ - read() {} + var _read6 = new Readable({ + read: function read() {} }); - const expected = new Error('kaboom'); - read._destroy = common.mustCall(function (err, cb) { + var _expected3 = new Error('kaboom'); + _read6._destroy = common.mustCall(function (err, cb) { assert.strictEqual(err, null); - cb(expected); + cb(_expected3); }); - read.on('end', common.mustNotCall('no end event')); - read.on('error', common.mustCall(err => { - assert.strictEqual(err, expected); + _read6.on('end', common.mustNotCall('no end event')); + _read6.on('error', common.mustCall(function (err) { + assert.strictEqual(err, _expected3); })); - read.destroy(); - assert.strictEqual(read.destroyed, true); + _read6.destroy(); + assert.strictEqual(_read6.destroyed, true); } { - const read = new Readable({ - read() {} + var _read7 = new Readable({ + read: function read() {} }); - read.resume(); - read.destroyed = true; - assert.strictEqual(read.destroyed, true); + _read7.resume(); + _read7.destroyed = true; + assert.strictEqual(_read7.destroyed, true); // the internal destroy() mechanism should not be triggered - read.on('end', common.mustNotCall()); - read.destroy(); + _read7.on('end', common.mustNotCall()); + _read7.destroy(); } { - function MyReadable() { + var MyReadable = function MyReadable() { assert.strictEqual(this.destroyed, false); this.destroyed = false; Readable.call(this); - } + }; Object.setPrototypeOf(MyReadable.prototype, Readable.prototype); Object.setPrototypeOf(MyReadable, Readable); new MyReadable(); } { // destroy and destroy callback - const read = new Readable({ - read() {} + var _read8 = new Readable({ + read: function read() {} }); - read.resume(); - const expected = new Error('kaboom'); - read.on('close', common.mustCall()); - read.destroy(expected, common.mustCall(function (err) { - assert.strictEqual(err, expected); + _read8.resume(); + var _expected4 = new Error('kaboom'); + _read8.on('close', common.mustCall()); + _read8.destroy(_expected4, common.mustCall(function (err) { + assert.strictEqual(err, _expected4); })); } { - const read = new Readable({ - read() {} + var _read9 = new Readable({ + read: function read() {} }); - read.destroy(); - read.push('hi'); - read.on('data', common.mustNotCall()); + _read9.destroy(); + _read9.push('hi'); + _read9.on('data', common.mustNotCall()); } ; (function () { @@ -162,4 +163,6 @@ const assert = require('assert/'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-emittedReadable.js b/test/parallel/test-stream-readable-emittedReadable.js index 89be15c4e..2feda840b 100644 --- a/test/parallel/test-stream-readable-emittedReadable.js +++ b/test/parallel/test-stream-readable-emittedReadable.js @@ -1,19 +1,19 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Readable = require('../../').Readable; -const readable = new Readable({ - read: () => {} +var common = require('../common'); +var assert = require('assert/'); +var Readable = require('../../').Readable; +var readable = new Readable({ + read: function read() {} }); // Initialized to false. assert.strictEqual(readable._readableState.emittedReadable, false); -const expected = [bufferShim.from('foobar'), bufferShim.from('quo'), null]; -readable.on('readable', common.mustCall(() => { +var expected = [bufferShim.from('foobar'), bufferShim.from('quo'), null]; +readable.on('readable', common.mustCall(function () { // emittedReadable should be true when the readable event is emitted assert.strictEqual(readable._readableState.emittedReadable, true); assert.deepStrictEqual(readable.read(), expected.shift()); @@ -26,24 +26,24 @@ readable.on('readable', common.mustCall(() => { assert.strictEqual(readable._readableState.emittedReadable, false); // These trigger a single 'readable', as things are batched up -process.nextTick(common.mustCall(() => { +process.nextTick(common.mustCall(function () { readable.push('foo'); })); -process.nextTick(common.mustCall(() => { +process.nextTick(common.mustCall(function () { readable.push('bar'); })); // these triggers two readable events -setImmediate(common.mustCall(() => { +setImmediate(common.mustCall(function () { readable.push('quo'); - process.nextTick(common.mustCall(() => { + process.nextTick(common.mustCall(function () { readable.push(null); })); })); -const noRead = new Readable({ - read: () => {} +var noRead = new Readable({ + read: function read() {} }); -noRead.on('readable', common.mustCall(() => { +noRead.on('readable', common.mustCall(function () { // emittedReadable should be true when the readable event is emitted assert.strictEqual(noRead._readableState.emittedReadable, true); noRead.read(0); @@ -52,10 +52,10 @@ noRead.on('readable', common.mustCall(() => { })); noRead.push('foo'); noRead.push(null); -const flowing = new Readable({ - read: () => {} +var flowing = new Readable({ + read: function read() {} }); -flowing.on('data', common.mustCall(() => { +flowing.on('data', common.mustCall(function () { // When in flowing mode, emittedReadable is always false. assert.strictEqual(flowing._readableState.emittedReadable, false); flowing.read(); @@ -64,7 +64,7 @@ flowing.on('data', common.mustCall(() => { flowing.push('foooo'); flowing.push('bar'); flowing.push('quo'); -process.nextTick(common.mustCall(() => { +process.nextTick(common.mustCall(function () { flowing.push(null); })); ; @@ -75,4 +75,6 @@ process.nextTick(common.mustCall(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-event.js b/test/parallel/test-stream-readable-event.js index ae576a047..8f45349bd 100644 --- a/test/parallel/test-stream-readable-event.js +++ b/test/parallel/test-stream-readable-event.js @@ -22,15 +22,15 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Readable = require('../../').Readable; +var common = require('../common'); +var assert = require('assert/'); +var Readable = require('../../').Readable; { // First test, not reading when the readable is added. // make sure that on('readable', ...) triggers a readable event. - const r = new Readable({ + var r = new Readable({ highWaterMark: 3 }); r._read = common.mustNotCall(); @@ -47,71 +47,74 @@ const Readable = require('../../').Readable; // second test, make sure that readable is re-emitted if there's // already a length, while it IS reading. - const r = new Readable({ + var _r = new Readable({ highWaterMark: 3 }); - r._read = common.mustCall(); + _r._read = common.mustCall(); // This triggers a 'readable' event, which is lost. - r.push(bufferShim.from('bl')); + _r.push(bufferShim.from('bl')); setTimeout(function () { // assert we're testing what we think we are - assert(r._readableState.reading); - r.on('readable', common.mustCall()); + assert(_r._readableState.reading); + _r.on('readable', common.mustCall()); }, 1); } { // Third test, not reading when the stream has not passed // the highWaterMark but *has* reached EOF. - const r = new Readable({ + var _r2 = new Readable({ highWaterMark: 30 }); - r._read = common.mustNotCall(); + _r2._read = common.mustNotCall(); // This triggers a 'readable' event, which is lost. - r.push(bufferShim.from('blerg')); - r.push(null); + _r2.push(bufferShim.from('blerg')); + _r2.push(null); setTimeout(function () { // assert we're testing what we think we are - assert(!r._readableState.reading); - r.on('readable', common.mustCall()); + assert(!_r2._readableState.reading); + _r2.on('readable', common.mustCall()); }, 1); } { // pushing a empty string in non-objectMode should // trigger next `read()`. - const underlyingData = ['', 'x', 'y', '', 'z']; - const expected = underlyingData.filter(data => data); - const result = []; - const r = new Readable({ + var underlyingData = ['', 'x', 'y', '', 'z']; + var expected = underlyingData.filter(function (data) { + return data; + }); + var result = []; + var _r3 = new Readable({ encoding: 'utf8' }); - r._read = function () { - process.nextTick(() => { + _r3._read = function () { + var _this = this; + process.nextTick(function () { if (!underlyingData.length) { - this.push(null); + _this.push(null); } else { - this.push(underlyingData.shift()); + _this.push(underlyingData.shift()); } }); }; - r.on('readable', () => { - const data = r.read(); + _r3.on('readable', function () { + var data = _r3.read(); if (data !== null) result.push(data); }); - r.on('end', common.mustCall(() => { + _r3.on('end', common.mustCall(function () { assert.deepStrictEqual(result, expected); })); } { // #20923 - const r = new Readable(); - r._read = function () { + var _r4 = new Readable(); + _r4._read = function () { // actually doing thing here }; - r.on('data', function () {}); - r.removeAllListeners(); - assert.strictEqual(r.eventNames().length, 0); + _r4.on('data', function () {}); + _r4.removeAllListeners(); + assert.strictEqual(_r4.eventNames().length, 0); } ; (function () { @@ -121,4 +124,6 @@ const Readable = require('../../').Readable; var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-flow-recursion.js b/test/parallel/test-stream-readable-flow-recursion.js index 572e872a5..f781e5ab3 100644 --- a/test/parallel/test-stream-readable-flow-recursion.js +++ b/test/parallel/test-stream-readable-flow-recursion.js @@ -22,41 +22,41 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); +var assert = require('assert/'); // this test verifies that passing a huge number to read(size) // will push up the highWaterMark, and cause the stream to read // more data continuously, but without triggering a nextTick // warning or RangeError. -const Readable = require('../../').Readable; +var Readable = require('../../').Readable; // throw an error if we trigger a nextTick warning. process.throwDeprecation = true; -const stream = new Readable({ +var stream = new Readable({ highWaterMark: 2 }); -let reads = 0; -let total = 5000; +var reads = 0; +var total = 5000; stream._read = function (size) { reads++; size = Math.min(size, total); total -= size; if (size === 0) stream.push(null);else stream.push(bufferShim.allocUnsafe(size)); }; -let depth = 0; +var depth = 0; function flow(stream, size, callback) { depth += 1; - const chunk = stream.read(size); + var chunk = stream.read(size); if (!chunk) stream.once('readable', flow.bind(null, stream, size, callback));else callback(chunk); depth -= 1; - console.log(`flow(${depth}): exit`); + console.log("flow(".concat(depth, "): exit")); } flow(stream, 5000, function () { - console.log(`complete (${depth})`); + console.log("complete (".concat(depth, ")")); }); process.on('exit', function (code) { assert.strictEqual(reads, 2); @@ -76,4 +76,6 @@ process.on('exit', function (code) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-hwm-0-async.js b/test/parallel/test-stream-readable-hwm-0-async.js index e81724808..225dd4fd8 100644 --- a/test/parallel/test-stream-readable-hwm-0-async.js +++ b/test/parallel/test-stream-readable-hwm-0-async.js @@ -1,22 +1,22 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); +var common = require('../common'); // This test ensures that Readable stream will continue to call _read // for streams with highWaterMark === 0 once the stream returns data // by calling push() asynchronously. -const _require = require('../../'), +var _require = require('../../'), Readable = _require.Readable; -let count = 5; -const r = new Readable({ +var count = 5; +var r = new Readable({ // Called 6 times: First 5 return data, last one signals end of stream. - read: common.mustCall(() => { - process.nextTick(common.mustCall(() => { + read: common.mustCall(function () { + process.nextTick(common.mustCall(function () { if (count--) r.push('a');else r.push(null); })); }, 6), @@ -32,4 +32,6 @@ r.on('data', common.mustCall(5)); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-hwm-0-no-flow-data.js b/test/parallel/test-stream-readable-hwm-0-no-flow-data.js index 234eba7e5..f275f574d 100644 --- a/test/parallel/test-stream-readable-hwm-0-no-flow-data.js +++ b/test/parallel/test-stream-readable-hwm-0-no-flow-data.js @@ -1,10 +1,10 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); +var common = require('../common'); // Ensure that subscribing the 'data' event will not make the stream flow. // The 'data' event will require calling read() by hand. @@ -12,17 +12,17 @@ const common = require('../common'); // The test is written for the (somewhat rare) highWaterMark: 0 streams to // specifically catch any regressions that might occur with these streams. -const assert = require('assert/'); -const _require = require('../../'), +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable; -const streamData = ['a', null]; +var streamData = ['a', null]; // Track the calls so we can assert their order later. -const calls = []; -const r = new Readable({ - read: common.mustCall(() => { +var calls = []; +var r = new Readable({ + read: common.mustCall(function () { calls.push('_read:' + streamData[0]); - process.nextTick(() => { + process.nextTick(function () { calls.push('push:' + streamData[0]); r.push(streamData.shift()); }); @@ -33,14 +33,14 @@ const r = new Readable({ objectMode: true }); assert.strictEqual(r.readableFlowing, null); -r.on('readable', common.mustCall(() => { +r.on('readable', common.mustCall(function () { calls.push('readable'); }, 2)); assert.strictEqual(r.readableFlowing, false); -r.on('data', common.mustCall(data => { +r.on('data', common.mustCall(function (data) { calls.push('data:' + data); }, 1)); -r.on('end', common.mustCall(() => { +r.on('end', common.mustCall(function () { calls.push('end'); })); assert.strictEqual(r.readableFlowing, false); @@ -51,7 +51,7 @@ assert.strictEqual(r.readableFlowing, false); // // We use setImmediate here to give the stream enough time to emit all the // events it's about to emit. -setImmediate(() => { +setImmediate(function () { // Only the _read, push, readable calls have happened. No data must be // emitted yet. assert.deepStrictEqual(calls, ['_read:a', 'push:a', 'readable']); @@ -70,7 +70,7 @@ setImmediate(() => { // Using setImmediate again to give the stream enough time to emit all the // events it wants to emit. assert.strictEqual(r.read(), null); - setImmediate(() => { + setImmediate(function () { // There's a new 'readable' event after the data has been pushed. // The 'end' event will be emitted only after a 'read()'. // @@ -85,7 +85,7 @@ setImmediate(() => { // ('end' event happening on the next tick after read()) so any changes // to it are noted and acknowledged in the future. assert.deepStrictEqual(calls, ['_read:a', 'push:a', 'readable', 'data:a', '_read:null', 'push:null', 'readable']); - process.nextTick(() => { + process.nextTick(function () { assert.deepStrictEqual(calls, ['_read:a', 'push:a', 'readable', 'data:a', '_read:null', 'push:null', 'readable', 'end']); }); }); @@ -98,4 +98,6 @@ setImmediate(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-hwm-0.js b/test/parallel/test-stream-readable-hwm-0.js index 4e232e783..24bc3d4e3 100644 --- a/test/parallel/test-stream-readable-hwm-0.js +++ b/test/parallel/test-stream-readable-hwm-0.js @@ -1,32 +1,32 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); +var common = require('../common'); // This test ensures that Readable stream will call _read() for streams // with highWaterMark === 0 upon .read(0) instead of just trying to // emit 'readable' event. -const assert = require('assert/'); -const _require = require('../../'), +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable; -const r = new Readable({ +var r = new Readable({ // must be called only once upon setting 'readable' listener read: common.mustCall(), highWaterMark: 0 }); -let pushedNull = false; +var pushedNull = false; // this will trigger read(0) but must only be called after push(null) // because the we haven't pushed any data -r.on('readable', common.mustCall(() => { +r.on('readable', common.mustCall(function () { assert.strictEqual(r.read(), null); assert.strictEqual(pushedNull, true); })); r.on('end', common.mustCall()); -process.nextTick(() => { +process.nextTick(function () { assert.strictEqual(r.read(), null); pushedNull = true; r.push(null); @@ -39,4 +39,6 @@ process.nextTick(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-infinite-read.js b/test/parallel/test-stream-readable-infinite-read.js index bbe85ddb1..ada2b70c2 100644 --- a/test/parallel/test-stream-readable-infinite-read.js +++ b/test/parallel/test-stream-readable-infinite-read.js @@ -1,27 +1,27 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable; -const buf = bufferShim.alloc(8192); -const readable = new Readable({ +var buf = bufferShim.alloc(8192); +var readable = new Readable({ read: common.mustCall(function () { this.push(buf); }, 31) }); -let i = 0; +var i = 0; readable.on('readable', common.mustCall(function () { if (i++ === 10) { // We will just terminate now. process.removeAllListeners('readable'); return; } - const data = readable.read(); + var data = readable.read(); // TODO(mcollina): there is something odd in the highWaterMark logic // investigate. if (i === 1) { @@ -38,4 +38,6 @@ readable.on('readable', common.mustCall(function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-invalid-chunk.js b/test/parallel/test-stream-readable-invalid-chunk.js index 92f5f9784..bc90e3df6 100644 --- a/test/parallel/test-stream-readable-invalid-chunk.js +++ b/test/parallel/test-stream-readable-invalid-chunk.js @@ -1,13 +1,13 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const readable = new stream.Readable({ - read: () => {} +var common = require('../common'); +var stream = require('../../'); +var readable = new stream.Readable({ + read: function read() {} }); function checkError(fn) { common.expectsError(fn, { @@ -15,9 +15,15 @@ function checkError(fn) { type: TypeError }); } -checkError(() => readable.push([])); -checkError(() => readable.push({})); -checkError(() => readable.push(0)); +checkError(function () { + return readable.push([]); +}); +checkError(function () { + return readable.push({}); +}); +checkError(function () { + return readable.push(0); +}); ; (function () { var t = require('tap'); @@ -26,4 +32,6 @@ checkError(() => readable.push(0)); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-needReadable.js b/test/parallel/test-stream-readable-needReadable.js index 0c5f710e6..f505402d5 100644 --- a/test/parallel/test-stream-readable-needReadable.js +++ b/test/parallel/test-stream-readable-needReadable.js @@ -1,18 +1,18 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Readable = require('../../').Readable; -const readable = new Readable({ - read: () => {} +var common = require('../common'); +var assert = require('assert/'); +var Readable = require('../../').Readable; +var readable = new Readable({ + read: function read() {} }); // Initialized to false. assert.strictEqual(readable._readableState.needReadable, false); -readable.on('readable', common.mustCall(() => { +readable.on('readable', common.mustCall(function () { // When the readable event fires, needReadable is reset. assert.strictEqual(readable._readableState.needReadable, false); readable.read(); @@ -22,14 +22,14 @@ readable.on('readable', common.mustCall(() => { assert.strictEqual(readable._readableState.needReadable, true); readable.push('foo'); readable.push(null); -readable.on('end', common.mustCall(() => { +readable.on('end', common.mustCall(function () { // No need to emit readable anymore when the stream ends. assert.strictEqual(readable._readableState.needReadable, false); })); -const asyncReadable = new Readable({ - read: () => {} +var asyncReadable = new Readable({ + read: function read() {} }); -asyncReadable.on('readable', common.mustCall(() => { +asyncReadable.on('readable', common.mustCall(function () { if (asyncReadable.read() !== null) { // After each read(), the buffer is empty. // If the stream doesn't end now, @@ -37,25 +37,25 @@ asyncReadable.on('readable', common.mustCall(() => { assert.strictEqual(asyncReadable._readableState.needReadable, true); } }, 2)); -process.nextTick(common.mustCall(() => { +process.nextTick(common.mustCall(function () { asyncReadable.push('foooo'); })); -process.nextTick(common.mustCall(() => { +process.nextTick(common.mustCall(function () { asyncReadable.push('bar'); })); -setImmediate(common.mustCall(() => { +setImmediate(common.mustCall(function () { asyncReadable.push(null); assert.strictEqual(asyncReadable._readableState.needReadable, false); })); -const flowing = new Readable({ - read: () => {} +var flowing = new Readable({ + read: function read() {} }); // Notice this must be above the on('data') call. flowing.push('foooo'); flowing.push('bar'); flowing.push('quo'); -process.nextTick(common.mustCall(() => { +process.nextTick(common.mustCall(function () { flowing.push(null); })); @@ -64,10 +64,10 @@ process.nextTick(common.mustCall(() => { flowing.on('data', common.mustCall(function (data) { assert.strictEqual(flowing._readableState.needReadable, false); }, 3)); -const slowProducer = new Readable({ - read: () => {} +var slowProducer = new Readable({ + read: function read() {} }); -slowProducer.on('readable', common.mustCall(() => { +slowProducer.on('readable', common.mustCall(function () { if (slowProducer.read(8) === null) { // The buffer doesn't have enough data, and the stream is not need, // we need to notify the reader when data arrives. @@ -76,13 +76,13 @@ slowProducer.on('readable', common.mustCall(() => { assert.strictEqual(slowProducer._readableState.needReadable, false); } }, 4)); -process.nextTick(common.mustCall(() => { +process.nextTick(common.mustCall(function () { slowProducer.push('foo'); - process.nextTick(common.mustCall(() => { + process.nextTick(common.mustCall(function () { slowProducer.push('foo'); - process.nextTick(common.mustCall(() => { + process.nextTick(common.mustCall(function () { slowProducer.push('foo'); - process.nextTick(common.mustCall(() => { + process.nextTick(common.mustCall(function () { slowProducer.push(null); })); })); @@ -96,4 +96,6 @@ process.nextTick(common.mustCall(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-no-unneeded-readable.js b/test/parallel/test-stream-readable-no-unneeded-readable.js index c3b7d3acc..db1b14abc 100644 --- a/test/parallel/test-stream-readable-no-unneeded-readable.js +++ b/test/parallel/test-stream-readable-no-unneeded-readable.js @@ -1,16 +1,16 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable, PassThrough = _require.PassThrough; function test(r) { - const wrapper = new Readable({ - read: () => { - let data = r.read(); + var wrapper = new Readable({ + read: function read() { + var data = r.read(); if (data) { wrapper.push(data); return; @@ -32,27 +32,29 @@ function test(r) { wrapper.once('end', common.mustCall()); } { - const source = new Readable({ - read: () => {} + var source = new Readable({ + read: function read() {} }); source.push('foo'); source.push('bar'); source.push(null); - const pt = source.pipe(new PassThrough()); + var pt = source.pipe(new PassThrough()); test(pt); } { // This is the underlying cause of the above test case. - const pushChunks = ['foo', 'bar']; - const r = new Readable({ - read: () => { - const chunk = pushChunks.shift(); + var pushChunks = ['foo', 'bar']; + var r = new Readable({ + read: function read() { + var chunk = pushChunks.shift(); if (chunk) { // synchronous call r.push(chunk); } else { // asynchronous call - process.nextTick(() => r.push(null)); + process.nextTick(function () { + return r.push(null); + }); } } }); @@ -66,4 +68,6 @@ function test(r) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-object-multi-push-async.js b/test/parallel/test-stream-readable-object-multi-push-async.js index b83f3c090..850867254 100644 --- a/test/parallel/test-stream-readable-object-multi-push-async.js +++ b/test/parallel/test-stream-readable-object-multi-push-async.js @@ -1,161 +1,170 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable; -const MAX = 42; -const BATCH = 10; +var MAX = 42; +var BATCH = 10; { - const readable = new Readable({ + var fetchData = function fetchData(cb) { + if (i > MAX) { + setTimeout(cb, 10, null, []); + } else { + var array = []; + var max = i + BATCH; + for (; i < max; i++) { + array.push(i); + } + setTimeout(cb, 10, null, array); + } + }; + var readable = new Readable({ objectMode: true, read: common.mustCall(function () { + var _this = this; console.log('>> READ'); - fetchData((err, data) => { + fetchData(function (err, data) { if (err) { - this.destroy(err); + _this.destroy(err); return; } if (data.length === 0) { console.log('pushing null'); - this.push(null); + _this.push(null); return; } console.log('pushing'); - data.forEach(d => this.push(d)); + data.forEach(function (d) { + return _this.push(d); + }); }); }, Math.floor(MAX / BATCH) + 2) }); - let i = 0; - function fetchData(cb) { - if (i > MAX) { - setTimeout(cb, 10, null, []); - } else { - const array = []; - const max = i + BATCH; - for (; i < max; i++) { - array.push(i); - } - setTimeout(cb, 10, null, array); - } - } - readable.on('readable', () => { - let data; + var i = 0; + readable.on('readable', function () { + var data; console.log('readable emitted'); while (data = readable.read()) { console.log(data); } }); - readable.on('end', common.mustCall(() => { + readable.on('end', common.mustCall(function () { assert.strictEqual(i, (Math.floor(MAX / BATCH) + 1) * BATCH); })); } { - const readable = new Readable({ + var _fetchData = function _fetchData(cb) { + if (_i > MAX) { + setTimeout(cb, 10, null, []); + } else { + var array = []; + var max = _i + BATCH; + for (; _i < max; _i++) { + array.push(_i); + } + setTimeout(cb, 10, null, array); + } + }; + var _readable = new Readable({ objectMode: true, read: common.mustCall(function () { + var _this2 = this; console.log('>> READ'); - fetchData((err, data) => { + _fetchData(function (err, data) { if (err) { - this.destroy(err); + _this2.destroy(err); return; } if (data.length === 0) { console.log('pushing null'); - this.push(null); + _this2.push(null); return; } console.log('pushing'); - data.forEach(d => this.push(d)); + data.forEach(function (d) { + return _this2.push(d); + }); }); }, Math.floor(MAX / BATCH) + 2) }); - let i = 0; - function fetchData(cb) { - if (i > MAX) { - setTimeout(cb, 10, null, []); - } else { - const array = []; - const max = i + BATCH; - for (; i < max; i++) { - array.push(i); - } - setTimeout(cb, 10, null, array); - } - } - readable.on('data', data => { + var _i = 0; + _readable.on('data', function (data) { console.log('data emitted', data); }); - readable.on('end', common.mustCall(() => { - assert.strictEqual(i, (Math.floor(MAX / BATCH) + 1) * BATCH); + _readable.on('end', common.mustCall(function () { + assert.strictEqual(_i, (Math.floor(MAX / BATCH) + 1) * BATCH); })); } { - const readable = new Readable({ + var _fetchData2 = function _fetchData2(cb) { + var array = []; + var max = _i2 + BATCH; + for (; _i2 < max; _i2++) { + array.push(_i2); + } + setTimeout(cb, 10, null, array); + }; + var _readable2 = new Readable({ objectMode: true, read: common.mustCall(function () { + var _this3 = this; console.log('>> READ'); - fetchData((err, data) => { + _fetchData2(function (err, data) { if (err) { - this.destroy(err); + _this3.destroy(err); return; } console.log('pushing'); - data.forEach(d => this.push(d)); + data.forEach(function (d) { + return _this3.push(d); + }); if (data[BATCH - 1] >= MAX) { console.log('pushing null'); - this.push(null); + _this3.push(null); } }); }, Math.floor(MAX / BATCH) + 1) }); - let i = 0; - function fetchData(cb) { - const array = []; - const max = i + BATCH; - for (; i < max; i++) { - array.push(i); - } - setTimeout(cb, 10, null, array); - } - readable.on('data', data => { + var _i2 = 0; + _readable2.on('data', function (data) { console.log('data emitted', data); }); - readable.on('end', common.mustCall(() => { - assert.strictEqual(i, (Math.floor(MAX / BATCH) + 1) * BATCH); + _readable2.on('end', common.mustCall(function () { + assert.strictEqual(_i2, (Math.floor(MAX / BATCH) + 1) * BATCH); })); } { - const readable = new Readable({ + var _readable3 = new Readable({ objectMode: true, read: common.mustNotCall() }); - readable.on('data', common.mustNotCall()); - readable.push(null); - let nextTickPassed = false; - process.nextTick(() => { + _readable3.on('data', common.mustNotCall()); + _readable3.push(null); + var nextTickPassed = false; + process.nextTick(function () { nextTickPassed = true; }); - readable.on('end', common.mustCall(() => { + _readable3.on('end', common.mustCall(function () { assert.strictEqual(nextTickPassed, true); })); } { - const readable = new Readable({ + var _readable4 = new Readable({ objectMode: true, read: common.mustCall() }); - readable.on('data', data => { + _readable4.on('data', function (data) { console.log('data emitted', data); }); - readable.on('end', common.mustCall()); - setImmediate(() => { - readable.push('aaa'); - readable.push(null); + _readable4.on('end', common.mustCall()); + setImmediate(function () { + _readable4.push('aaa'); + _readable4.push(null); }); } ; @@ -166,4 +175,6 @@ const BATCH = 10; var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-pause-and-resume.js b/test/parallel/test-stream-readable-pause-and-resume.js index 966ffec90..a0a10ca23 100644 --- a/test/parallel/test-stream-readable-pause-and-resume.js +++ b/test/parallel/test-stream-readable-pause-and-resume.js @@ -1,18 +1,20 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const _require = require('../../'), +var _require = require('../../'), Readable = _require.Readable; -const common = require('../common'); -let ticks = 18; -let expectedData = 19; -const rs = new Readable({ +var common = require('../common'); +var ticks = 18; +var expectedData = 19; +var rs = new Readable({ objectMode: true, - read: () => { - if (ticks-- > 0) return process.nextTick(() => rs.push({})); + read: function read() { + if (ticks-- > 0) return process.nextTick(function () { + return rs.push({}); + }); rs.push({}); rs.push(null); } @@ -22,7 +24,7 @@ readAndPause(); function readAndPause() { // Does a on(data) -> pause -> wait -> resume -> on(data) ... loop. // Expects on(data) to never fire if the stream is paused. - const ondata = common.mustCall(data => { + var ondata = common.mustCall(function (data) { rs.pause(); expectedData--; if (expectedData <= 0) return; @@ -43,4 +45,6 @@ function readAndPause() { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-readable-then-resume.js b/test/parallel/test-stream-readable-readable-then-resume.js index 11e9f19fc..ff5536983 100644 --- a/test/parallel/test-stream-readable-readable-then-resume.js +++ b/test/parallel/test-stream-readable-readable-then-resume.js @@ -1,11 +1,11 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable; // This test verifies that a stream could be resumed after @@ -14,7 +14,7 @@ const _require = require('../../'), check(new Readable({ objectMode: true, highWaterMark: 1, - read() { + read: function read() { if (!this.first) { this.push('hello'); this.first = true; @@ -24,7 +24,7 @@ check(new Readable({ } })); function check(s) { - const readableListener = common.mustNotCall(); + var readableListener = common.mustNotCall(); s.on('readable', readableListener); s.on('end', common.mustCall()); s.removeListener('readable', readableListener); @@ -38,4 +38,6 @@ function check(s) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-reading-readingMore.js b/test/parallel/test-stream-readable-reading-readingMore.js index 914d9616d..066386c89 100644 --- a/test/parallel/test-stream-readable-reading-readingMore.js +++ b/test/parallel/test-stream-readable-reading-readingMore.js @@ -1,21 +1,27 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Readable = require('../../').Readable; +var common = require('../common'); +var assert = require('assert/'); +var Readable = require('../../').Readable; { - const readable = new Readable({ - read(size) {} + var onStreamEnd = function onStreamEnd() { + // End of stream; state.reading is false + // And so should be readingMore. + assert.strictEqual(state.readingMore, false); + assert.strictEqual(state.reading, false); + }; + var readable = new Readable({ + read: function read(size) {} }); - const state = readable._readableState; + var state = readable._readableState; // Starting off with false initially. assert.strictEqual(state.reading, false); assert.strictEqual(state.readingMore, false); - readable.on('data', common.mustCall(data => { + readable.on('data', common.mustCall(function (data) { // while in a flowing state with a 'readable' listener // we should not be reading more if (readable.readableFlowing) assert.strictEqual(state.readingMore, true); @@ -23,21 +29,15 @@ const Readable = require('../../').Readable; // reading as long as we've not ended assert.strictEqual(state.reading, !state.ended); }, 2)); - function onStreamEnd() { - // End of stream; state.reading is false - // And so should be readingMore. - assert.strictEqual(state.readingMore, false); - assert.strictEqual(state.reading, false); - } - const expectedReadingMore = [true, false]; - readable.on('readable', common.mustCall(() => { + var expectedReadingMore = [true, false]; + readable.on('readable', common.mustCall(function () { // there is only one readingMore scheduled from on('data'), // after which everything is governed by the .read() call assert.strictEqual(state.readingMore, expectedReadingMore.shift()); // if the stream has ended, we shouldn't be reading assert.strictEqual(state.ended, !state.reading); - const data = readable.read(); + var data = readable.read(); if (data === null) // reached end of stream process.nextTick(common.mustCall(onStreamEnd, 1)); @@ -57,94 +57,94 @@ const Readable = require('../../').Readable; readable.push(null); } { - const readable = new Readable({ - read(size) {} + var _onStreamEnd = function _onStreamEnd() { + // End of stream; state.reading is false + // And so should be readingMore. + assert.strictEqual(_state.readingMore, false); + assert.strictEqual(_state.reading, false); + }; + var _readable = new Readable({ + read: function read(size) {} }); - const state = readable._readableState; + var _state = _readable._readableState; // Starting off with false initially. - assert.strictEqual(state.reading, false); - assert.strictEqual(state.readingMore, false); - readable.on('data', common.mustCall(data => { + assert.strictEqual(_state.reading, false); + assert.strictEqual(_state.readingMore, false); + _readable.on('data', common.mustCall(function (data) { // while in a flowing state without a 'readable' listener // we should be reading more - if (readable.readableFlowing) assert.strictEqual(state.readingMore, true); + if (_readable.readableFlowing) assert.strictEqual(_state.readingMore, true); // reading as long as we've not ended - assert.strictEqual(state.reading, !state.ended); + assert.strictEqual(_state.reading, !_state.ended); }, 2)); - function onStreamEnd() { - // End of stream; state.reading is false - // And so should be readingMore. - assert.strictEqual(state.readingMore, false); - assert.strictEqual(state.reading, false); - } - readable.on('end', common.mustCall(onStreamEnd)); - readable.push('pushed'); + _readable.on('end', common.mustCall(_onStreamEnd)); + _readable.push('pushed'); // stop emitting 'data' events - assert.strictEqual(state.flowing, true); - readable.pause(); + assert.strictEqual(_state.flowing, true); + _readable.pause(); // paused - assert.strictEqual(state.reading, false); - assert.strictEqual(state.flowing, false); - readable.resume(); - assert.strictEqual(state.reading, false); - assert.strictEqual(state.flowing, true); + assert.strictEqual(_state.reading, false); + assert.strictEqual(_state.flowing, false); + _readable.resume(); + assert.strictEqual(_state.reading, false); + assert.strictEqual(_state.flowing, true); // add chunk to front - readable.unshift('unshifted'); + _readable.unshift('unshifted'); // end - readable.push(null); + _readable.push(null); } { - const readable = new Readable({ - read(size) {} + var _onStreamEnd2 = function _onStreamEnd2() { + // End of stream; state.reading is false + // And so should be readingMore. + assert.strictEqual(_state2.readingMore, false); + assert.strictEqual(_state2.reading, false); + }; + var _readable2 = new Readable({ + read: function read(size) {} }); - const state = readable._readableState; + var _state2 = _readable2._readableState; // Starting off with false initially. - assert.strictEqual(state.reading, false); - assert.strictEqual(state.readingMore, false); - const onReadable = common.mustNotCall; - readable.on('readable', onReadable); - readable.on('data', common.mustCall(data => { + assert.strictEqual(_state2.reading, false); + assert.strictEqual(_state2.readingMore, false); + var onReadable = common.mustNotCall; + _readable2.on('readable', onReadable); + _readable2.on('data', common.mustCall(function (data) { // reading as long as we've not ended - assert.strictEqual(state.reading, !state.ended); + assert.strictEqual(_state2.reading, !_state2.ended); }, 2)); - readable.removeListener('readable', onReadable); - function onStreamEnd() { - // End of stream; state.reading is false - // And so should be readingMore. - assert.strictEqual(state.readingMore, false); - assert.strictEqual(state.reading, false); - } - readable.on('end', common.mustCall(onStreamEnd)); - readable.push('pushed'); + _readable2.removeListener('readable', onReadable); + _readable2.on('end', common.mustCall(_onStreamEnd2)); + _readable2.push('pushed'); // we are still not flowing, we will be resuming in the next tick - assert.strictEqual(state.flowing, false); + assert.strictEqual(_state2.flowing, false); // wait for nextTick, so the readableListener flag resets process.nextTick(function () { - readable.resume(); + _readable2.resume(); // stop emitting 'data' events - assert.strictEqual(state.flowing, true); - readable.pause(); + assert.strictEqual(_state2.flowing, true); + _readable2.pause(); // paused - assert.strictEqual(state.flowing, false); - readable.resume(); - assert.strictEqual(state.flowing, true); + assert.strictEqual(_state2.flowing, false); + _readable2.resume(); + assert.strictEqual(_state2.flowing, true); // add chunk to front - readable.unshift('unshifted'); + _readable2.unshift('unshifted'); // end - readable.push(null); + _readable2.push(null); }); } ; @@ -155,4 +155,6 @@ const Readable = require('../../').Readable; var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-resume-hwm.js b/test/parallel/test-stream-readable-resume-hwm.js index d948c6810..b97283f9a 100644 --- a/test/parallel/test-stream-readable-resume-hwm.js +++ b/test/parallel/test-stream-readable-resume-hwm.js @@ -1,28 +1,30 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable; // readable.resume() should not lead to a ._read() call being scheduled // when we exceed the high water mark already. -const readable = new Readable({ +var readable = new Readable({ read: common.mustNotCall(), highWaterMark: 100 }); // Fill up the internal buffer so that we definitely exceed the HWM: -for (let i = 0; i < 10; i++) readable.push('a'.repeat(200)); +for (var i = 0; i < 10; i++) readable.push('a'.repeat(200)); // Call resume, and pause after one chunk. // The .pause() is just so that we don’t empty the buffer fully, which would // be a valid reason to call ._read(). readable.resume(); -readable.once('data', common.mustCall(() => readable.pause())); +readable.once('data', common.mustCall(function () { + return readable.pause(); +})); ; (function () { var t = require('tap'); @@ -31,4 +33,6 @@ readable.once('data', common.mustCall(() => readable.pause())); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-resumeScheduled.js b/test/parallel/test-stream-readable-resumeScheduled.js index debcb481d..7944bdbfd 100644 --- a/test/parallel/test-stream-readable-resumeScheduled.js +++ b/test/parallel/test-stream-readable-resumeScheduled.js @@ -1,22 +1,22 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); +var common = require('../common'); // Testing Readable Stream resumeScheduled state -const assert = require('assert/'); -const _require = require('../../'), +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable, Writable = _require.Writable; { // pipe() test case - const r = new Readable({ - read() {} + var r = new Readable({ + read: function read() {} }); - const w = new Writable(); + var w = new Writable(); // resumeScheduled should start = `false`. assert.strictEqual(r._readableState.resumeScheduled, false); @@ -24,47 +24,47 @@ const _require = require('../../'), // calling pipe() should change the state value = true. r.pipe(w); assert.strictEqual(r._readableState.resumeScheduled, true); - process.nextTick(common.mustCall(() => { + process.nextTick(common.mustCall(function () { assert.strictEqual(r._readableState.resumeScheduled, false); })); } { // 'data' listener test case - const r = new Readable({ - read() {} + var _r = new Readable({ + read: function read() {} }); // resumeScheduled should start = `false`. - assert.strictEqual(r._readableState.resumeScheduled, false); - r.push(bufferShim.from([1, 2, 3])); + assert.strictEqual(_r._readableState.resumeScheduled, false); + _r.push(bufferShim.from([1, 2, 3])); // adding 'data' listener should change the state value - r.on('data', common.mustCall(() => { - assert.strictEqual(r._readableState.resumeScheduled, false); + _r.on('data', common.mustCall(function () { + assert.strictEqual(_r._readableState.resumeScheduled, false); })); - assert.strictEqual(r._readableState.resumeScheduled, true); - process.nextTick(common.mustCall(() => { - assert.strictEqual(r._readableState.resumeScheduled, false); + assert.strictEqual(_r._readableState.resumeScheduled, true); + process.nextTick(common.mustCall(function () { + assert.strictEqual(_r._readableState.resumeScheduled, false); })); } { // resume() test case - const r = new Readable({ - read() {} + var _r2 = new Readable({ + read: function read() {} }); // resumeScheduled should start = `false`. - assert.strictEqual(r._readableState.resumeScheduled, false); + assert.strictEqual(_r2._readableState.resumeScheduled, false); // Calling resume() should change the state value. - r.resume(); - assert.strictEqual(r._readableState.resumeScheduled, true); - r.on('resume', common.mustCall(() => { + _r2.resume(); + assert.strictEqual(_r2._readableState.resumeScheduled, true); + _r2.on('resume', common.mustCall(function () { // The state value should be `false` again - assert.strictEqual(r._readableState.resumeScheduled, false); + assert.strictEqual(_r2._readableState.resumeScheduled, false); })); - process.nextTick(common.mustCall(() => { - assert.strictEqual(r._readableState.resumeScheduled, false); + process.nextTick(common.mustCall(function () { + assert.strictEqual(_r2._readableState.resumeScheduled, false); })); } ; @@ -75,4 +75,6 @@ const _require = require('../../'), var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-setEncoding-existing-buffers.js b/test/parallel/test-stream-readable-setEncoding-existing-buffers.js index ff045c1f6..5701b8baf 100644 --- a/test/parallel/test-stream-readable-setEncoding-existing-buffers.js +++ b/test/parallel/test-stream-readable-setEncoding-existing-buffers.js @@ -1,58 +1,64 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const _require = require('../../'), +var _require = require('../../'), Readable = _require.Readable; -const assert = require('assert/'); +var assert = require('assert/'); { // Call .setEncoding() while there are bytes already in the buffer. - const r = new Readable({ - read() {} + var r = new Readable({ + read: function read() {} }); r.push(bufferShim.from('a')); r.push(bufferShim.from('b')); r.setEncoding('utf8'); - const chunks = []; - r.on('data', chunk => chunks.push(chunk)); - process.nextTick(() => { + var chunks = []; + r.on('data', function (chunk) { + return chunks.push(chunk); + }); + process.nextTick(function () { assert.deepStrictEqual(chunks, ['ab']); }); } { // Call .setEncoding() while the buffer contains a complete, // but chunked character. - const r = new Readable({ - read() {} + var _r = new Readable({ + read: function read() {} }); - r.push(bufferShim.from([0xf0])); - r.push(bufferShim.from([0x9f])); - r.push(bufferShim.from([0x8e])); - r.push(bufferShim.from([0x89])); - r.setEncoding('utf8'); - const chunks = []; - r.on('data', chunk => chunks.push(chunk)); - process.nextTick(() => { - assert.deepStrictEqual(chunks, ['🎉']); + _r.push(bufferShim.from([0xf0])); + _r.push(bufferShim.from([0x9f])); + _r.push(bufferShim.from([0x8e])); + _r.push(bufferShim.from([0x89])); + _r.setEncoding('utf8'); + var _chunks = []; + _r.on('data', function (chunk) { + return _chunks.push(chunk); + }); + process.nextTick(function () { + assert.deepStrictEqual(_chunks, ['🎉']); }); } { // Call .setEncoding() while the buffer contains an incomplete character, // and finish the character later. - const r = new Readable({ - read() {} + var _r2 = new Readable({ + read: function read() {} }); - r.push(bufferShim.from([0xf0])); - r.push(bufferShim.from([0x9f])); - r.setEncoding('utf8'); - r.push(bufferShim.from([0x8e])); - r.push(bufferShim.from([0x89])); - const chunks = []; - r.on('data', chunk => chunks.push(chunk)); - process.nextTick(() => { - assert.deepStrictEqual(chunks, ['🎉']); + _r2.push(bufferShim.from([0xf0])); + _r2.push(bufferShim.from([0x9f])); + _r2.setEncoding('utf8'); + _r2.push(bufferShim.from([0x8e])); + _r2.push(bufferShim.from([0x89])); + var _chunks2 = []; + _r2.on('data', function (chunk) { + return _chunks2.push(chunk); + }); + process.nextTick(function () { + assert.deepStrictEqual(_chunks2, ['🎉']); }); } ; @@ -63,4 +69,6 @@ const assert = require('assert/'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-setEncoding-null.js b/test/parallel/test-stream-readable-setEncoding-null.js index 88a547c74..91da12a27 100644 --- a/test/parallel/test-stream-readable-setEncoding-null.js +++ b/test/parallel/test-stream-readable-setEncoding-null.js @@ -1,15 +1,15 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable; { - const readable = new Readable({ + var readable = new Readable({ encoding: 'hex' }); assert.strictEqual(readable._readableState.encoding, 'hex'); @@ -24,4 +24,6 @@ const _require = require('../../'), var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readable-with-unimplemented-_read.js b/test/parallel/test-stream-readable-with-unimplemented-_read.js index 62755fdc8..ff678e061 100644 --- a/test/parallel/test-stream-readable-with-unimplemented-_read.js +++ b/test/parallel/test-stream-readable-with-unimplemented-_read.js @@ -1,12 +1,12 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Readable = _require.Readable; -const readable = new Readable(); +var readable = new Readable(); readable.on('error', common.expectsError({ code: 'ERR_METHOD_NOT_IMPLEMENTED', type: Error, @@ -21,4 +21,6 @@ readable.read(); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-readableListening-state.js b/test/parallel/test-stream-readableListening-state.js index 48c384fcf..e0379d6a0 100644 --- a/test/parallel/test-stream-readableListening-state.js +++ b/test/parallel/test-stream-readableListening-state.js @@ -1,30 +1,30 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const r = new stream.Readable({ - read: () => {} +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var r = new stream.Readable({ + read: function read() {} }); // readableListening state should start in `false`. assert.strictEqual(r._readableState.readableListening, false); -r.on('readable', common.mustCall(() => { +r.on('readable', common.mustCall(function () { // Inside the readable event this state should be true. assert.strictEqual(r._readableState.readableListening, true); })); r.push(bufferShim.from('Testing readableListening state')); -const r2 = new stream.Readable({ - read: () => {} +var r2 = new stream.Readable({ + read: function read() {} }); // readableListening state should start in `false`. assert.strictEqual(r2._readableState.readableListening, false); -r2.on('data', common.mustCall(chunk => { +r2.on('data', common.mustCall(function (chunk) { // readableListening should be false because we don't have // a `readable` listener assert.strictEqual(r2._readableState.readableListening, false); @@ -38,4 +38,6 @@ r2.push(bufferShim.from('Testing readableListening state')); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-callback-twice.js b/test/parallel/test-stream-transform-callback-twice.js index c72b96a67..7b1ac2826 100644 --- a/test/parallel/test-stream-transform-callback-twice.js +++ b/test/parallel/test-stream-transform-callback-twice.js @@ -1,13 +1,13 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Transform = _require.Transform; -const stream = new Transform({ - transform(chunk, enc, cb) { +var stream = new Transform({ + transform: function transform(chunk, enc, cb) { cb(); cb(); } @@ -26,4 +26,6 @@ stream.write('foo'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-constructor-set-methods.js b/test/parallel/test-stream-transform-constructor-set-methods.js index 0774ec3f6..65bd2f67a 100644 --- a/test/parallel/test-stream-transform-constructor-set-methods.js +++ b/test/parallel/test-stream-transform-constructor-set-methods.js @@ -1,30 +1,30 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('assert/'), +var common = require('../common'); +var _require = require('assert/'), strictEqual = _require.strictEqual; -const _require2 = require('../../'), +var _require2 = require('../../'), Transform = _require2.Transform; -const t = new Transform(); +var t = new Transform(); t.on('error', common.expectsError({ type: Error, code: 'ERR_METHOD_NOT_IMPLEMENTED', message: 'The _transform() method is not implemented' })); t.end(bufferShim.from('blerg')); -const _transform = common.mustCall((chunk, _, next) => { +var _transform = common.mustCall(function (chunk, _, next) { next(); }); -const _final = common.mustCall(next => { +var _final = common.mustCall(function (next) { next(); }); -const _flush = common.mustCall(next => { +var _flush = common.mustCall(function (next) { next(); }); -const t2 = new Transform({ +var t2 = new Transform({ transform: _transform, flush: _flush, final: _final @@ -42,4 +42,6 @@ t2.resume(); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-destroy.js b/test/parallel/test-stream-transform-destroy.js index c96bde31a..5bf3e8fa6 100644 --- a/test/parallel/test-stream-transform-destroy.js +++ b/test/parallel/test-stream-transform-destroy.js @@ -1,16 +1,16 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Transform = _require.Transform; -const assert = require('assert/'); +var assert = require('assert/'); { - const transform = new Transform({ - transform(chunk, enc, cb) {} + var transform = new Transform({ + transform: function transform(chunk, enc, cb) {} }); transform.resume(); transform.on('end', common.mustNotCall()); @@ -19,102 +19,103 @@ const assert = require('assert/'); transform.destroy(); } { - const transform = new Transform({ - transform(chunk, enc, cb) {} + var _transform = new Transform({ + transform: function transform(chunk, enc, cb) {} }); - transform.resume(); - const expected = new Error('kaboom'); - transform.on('end', common.mustNotCall()); - transform.on('finish', common.mustNotCall()); - transform.on('close', common.mustCall()); - transform.on('error', common.mustCall(err => { + _transform.resume(); + var expected = new Error('kaboom'); + _transform.on('end', common.mustNotCall()); + _transform.on('finish', common.mustNotCall()); + _transform.on('close', common.mustCall()); + _transform.on('error', common.mustCall(function (err) { assert.strictEqual(err, expected); })); - transform.destroy(expected); + _transform.destroy(expected); } { - const transform = new Transform({ - transform(chunk, enc, cb) {} + var _transform2 = new Transform({ + transform: function transform(chunk, enc, cb) {} }); - transform._destroy = common.mustCall(function (err, cb) { - assert.strictEqual(err, expected); + _transform2._destroy = common.mustCall(function (err, cb) { + assert.strictEqual(err, _expected); cb(err); }, 1); - const expected = new Error('kaboom'); - transform.on('finish', common.mustNotCall('no finish event')); - transform.on('close', common.mustCall()); - transform.on('error', common.mustCall(err => { - assert.strictEqual(err, expected); + var _expected = new Error('kaboom'); + _transform2.on('finish', common.mustNotCall('no finish event')); + _transform2.on('close', common.mustCall()); + _transform2.on('error', common.mustCall(function (err) { + assert.strictEqual(err, _expected); })); - transform.destroy(expected); + _transform2.destroy(_expected); } { - const expected = new Error('kaboom'); - const transform = new Transform({ - transform(chunk, enc, cb) {}, + var _expected2 = new Error('kaboom'); + var _transform3 = new Transform({ + transform: function transform(chunk, enc, cb) {}, destroy: common.mustCall(function (err, cb) { - assert.strictEqual(err, expected); + assert.strictEqual(err, _expected2); cb(); }, 1) }); - transform.resume(); - transform.on('end', common.mustNotCall('no end event')); - transform.on('close', common.mustCall()); - transform.on('finish', common.mustNotCall('no finish event')); + _transform3.resume(); + _transform3.on('end', common.mustNotCall('no end event')); + _transform3.on('close', common.mustCall()); + _transform3.on('finish', common.mustNotCall('no finish event')); // error is swallowed by the custom _destroy - transform.on('error', common.mustNotCall('no error event')); - transform.destroy(expected); + _transform3.on('error', common.mustNotCall('no error event')); + _transform3.destroy(_expected2); } { - const transform = new Transform({ - transform(chunk, enc, cb) {} + var _transform4 = new Transform({ + transform: function transform(chunk, enc, cb) {} }); - transform._destroy = common.mustCall(function (err, cb) { + _transform4._destroy = common.mustCall(function (err, cb) { assert.strictEqual(err, null); cb(); }, 1); - transform.destroy(); + _transform4.destroy(); } { - const transform = new Transform({ - transform(chunk, enc, cb) {} + var _transform5 = new Transform({ + transform: function transform(chunk, enc, cb) {} }); - transform.resume(); - transform._destroy = common.mustCall(function (err, cb) { + _transform5.resume(); + _transform5._destroy = common.mustCall(function (err, cb) { + var _this = this; assert.strictEqual(err, null); - process.nextTick(() => { - this.push(null); - this.end(); + process.nextTick(function () { + _this.push(null); + _this.end(); cb(); }); }, 1); - const fail = common.mustNotCall('no event'); - transform.on('finish', fail); - transform.on('end', fail); - transform.on('close', common.mustCall()); - transform.destroy(); - transform.removeListener('end', fail); - transform.removeListener('finish', fail); - transform.on('end', common.mustCall()); - transform.on('finish', common.mustCall()); + var fail = common.mustNotCall('no event'); + _transform5.on('finish', fail); + _transform5.on('end', fail); + _transform5.on('close', common.mustCall()); + _transform5.destroy(); + _transform5.removeListener('end', fail); + _transform5.removeListener('finish', fail); + _transform5.on('end', common.mustCall()); + _transform5.on('finish', common.mustCall()); } { - const transform = new Transform({ - transform(chunk, enc, cb) {} + var _transform6 = new Transform({ + transform: function transform(chunk, enc, cb) {} }); - const expected = new Error('kaboom'); - transform._destroy = common.mustCall(function (err, cb) { + var _expected3 = new Error('kaboom'); + _transform6._destroy = common.mustCall(function (err, cb) { assert.strictEqual(err, null); - cb(expected); + cb(_expected3); }, 1); - transform.on('close', common.mustCall()); - transform.on('finish', common.mustNotCall('no finish event')); - transform.on('end', common.mustNotCall('no end event')); - transform.on('error', common.mustCall(err => { - assert.strictEqual(err, expected); + _transform6.on('close', common.mustCall()); + _transform6.on('finish', common.mustNotCall('no finish event')); + _transform6.on('end', common.mustNotCall('no end event')); + _transform6.on('error', common.mustCall(function (err) { + assert.strictEqual(err, _expected3); })); - transform.destroy(); + _transform6.destroy(); } ; (function () { @@ -124,4 +125,6 @@ const assert = require('assert/'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-final-sync.js b/test/parallel/test-stream-transform-final-sync.js index 898077e8d..c8061ccbf 100644 --- a/test/parallel/test-stream-transform-final-sync.js +++ b/test/parallel/test-stream-transform-final-sync.js @@ -1,12 +1,12 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -let state = 0; +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var state = 0; /* What you do @@ -59,7 +59,7 @@ The order things are called 16. endListener */ -const t = new stream.Transform({ +var t = new stream.Transform({ objectMode: true, transform: common.mustCall(function (chunk, _, next) { // transformCallback part 1 @@ -119,4 +119,6 @@ t.end(7, common.mustCall(function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-final.js b/test/parallel/test-stream-transform-final.js index 45252b269..1c90e9adf 100644 --- a/test/parallel/test-stream-transform-final.js +++ b/test/parallel/test-stream-transform-final.js @@ -1,12 +1,12 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -let state = 0; +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var state = 0; /* What you do @@ -59,7 +59,7 @@ The order things are called 16. endListener */ -const t = new stream.Transform({ +var t = new stream.Transform({ objectMode: true, transform: common.mustCall(function (chunk, _, next) { // transformCallback part 1 @@ -121,4 +121,6 @@ t.end(7, common.mustCall(function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-flush-data.js b/test/parallel/test-stream-transform-flush-data.js index 267c64009..8630a5df0 100644 --- a/test/parallel/test-stream-transform-flush-data.js +++ b/test/parallel/test-stream-transform-flush-data.js @@ -1,25 +1,25 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const Transform = require('../../').Transform; -const expected = 'asdf'; +var assert = require('assert/'); +var Transform = require('../../').Transform; +var expected = 'asdf'; function _transform(d, e, n) { n(); } function _flush(n) { n(null, expected); } -const t = new Transform({ +var t = new Transform({ transform: _transform, flush: _flush }); t.end(bufferShim.from('blerg')); -t.on('data', data => { +t.on('data', function (data) { assert.strictEqual(data.toString(), expected); }); ; @@ -30,4 +30,6 @@ t.on('data', data => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-objectmode-falsey-value.js b/test/parallel/test-stream-transform-objectmode-falsey-value.js index 068db4b2f..d3ebb07b4 100644 --- a/test/parallel/test-stream-transform-objectmode-falsey-value.js +++ b/test/parallel/test-stream-transform-objectmode-falsey-value.js @@ -22,29 +22,29 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const PassThrough = stream.PassThrough; -const src = new PassThrough({ +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var PassThrough = stream.PassThrough; +var src = new PassThrough({ objectMode: true }); -const tx = new PassThrough({ +var tx = new PassThrough({ objectMode: true }); -const dest = new PassThrough({ +var dest = new PassThrough({ objectMode: true }); -const expect = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; -const results = []; +var expect = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +var results = []; dest.on('data', common.mustCall(function (x) { results.push(x); }, expect.length)); src.pipe(tx).pipe(dest); -let i = -1; -const int = setInterval(common.mustCall(function () { +var i = -1; +var int = setInterval(common.mustCall(function () { if (results.length === expect.length) { src.end(); clearInterval(int); @@ -61,4 +61,6 @@ const int = setInterval(common.mustCall(function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-split-highwatermark.js b/test/parallel/test-stream-transform-split-highwatermark.js index 3f940117b..5501f0cc1 100644 --- a/test/parallel/test-stream-transform-split-highwatermark.js +++ b/test/parallel/test-stream-transform-split-highwatermark.js @@ -1,17 +1,17 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Transform = _require.Transform, Readable = _require.Readable, Writable = _require.Writable; -const DEFAULT = 16 * 1024; +var DEFAULT = 16 * 1024; function testTransform(expectedReadableHwm, expectedWritableHwm, options) { - const t = new Transform(options); + var t = new Transform(options); assert.strictEqual(t._readableState.highWaterMark, expectedReadableHwm); assert.strictEqual(t._writableState.highWaterMark, expectedWritableHwm); } @@ -67,7 +67,7 @@ testTransform(0, 0, { }); // test undefined, null -[undefined, null].forEach(v => { +[undefined, null].forEach(function (v) { testTransform(DEFAULT, DEFAULT, { readableHighWaterMark: v }); @@ -86,7 +86,7 @@ testTransform(0, 0, { // test NaN { - common.expectsError(() => { + common.expectsError(function () { new Transform({ readableHighWaterMark: NaN }); @@ -95,7 +95,7 @@ testTransform(0, 0, { code: 'ERR_INVALID_OPT_VALUE', message: 'The value "NaN" is invalid for option "readableHighWaterMark"' }); - common.expectsError(() => { + common.expectsError(function () { new Transform({ writableHighWaterMark: NaN }); @@ -108,11 +108,11 @@ testTransform(0, 0, { // test non Duplex streams ignore the options { - const r = new Readable({ + var r = new Readable({ readableHighWaterMark: 666 }); assert.strictEqual(r._readableState.highWaterMark, DEFAULT); - const w = new Writable({ + var w = new Writable({ writableHighWaterMark: 777 }); assert.strictEqual(w._writableState.highWaterMark, DEFAULT); @@ -125,4 +125,6 @@ testTransform(0, 0, { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-transform-split-objectmode.js b/test/parallel/test-stream-transform-split-objectmode.js index 828ba2b51..4236630be 100644 --- a/test/parallel/test-stream-transform-split-objectmode.js +++ b/test/parallel/test-stream-transform-split-objectmode.js @@ -22,12 +22,12 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const Transform = require('../../').Transform; -const parser = new Transform({ +var assert = require('assert/'); +var Transform = require('../../').Transform; +var parser = new Transform({ readableObjectMode: true }); assert(parser._readableState.objectMode); @@ -41,7 +41,7 @@ parser._transform = function (chunk, enc, callback) { val: chunk[0] }); }; -let parsed; +var parsed; parser.on('data', function (obj) { parsed = obj; }); @@ -49,7 +49,7 @@ parser.end(bufferShim.from([42])); process.on('exit', function () { assert.strictEqual(parsed.val, 42); }); -const serializer = new Transform({ +var serializer = new Transform({ writableObjectMode: true }); assert(!serializer._readableState.objectMode); @@ -61,7 +61,7 @@ assert.strictEqual(parser.writableHighWaterMark, parser._writableState.highWater serializer._transform = function (obj, _, callback) { callback(null, bufferShim.from([obj.val])); }; -let serialized; +var serialized; serializer.on('data', function (chunk) { serialized = chunk; }); @@ -79,4 +79,6 @@ process.on('exit', function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-uint8array.js b/test/parallel/test-stream-uint8array.js index 27787cea1..df7cf8d74 100644 --- a/test/parallel/test-stream-uint8array.js +++ b/test/parallel/test-stream-uint8array.js @@ -1,22 +1,28 @@ "use strict"; +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable, Writable = _require.Writable; -const ABC = new Uint8Array([0x41, 0x42, 0x43]); -const DEF = new Uint8Array([0x44, 0x45, 0x46]); -const GHI = new Uint8Array([0x47, 0x48, 0x49]); +var ABC = new Uint8Array([0x41, 0x42, 0x43]); +var DEF = new Uint8Array([0x44, 0x45, 0x46]); +var GHI = new Uint8Array([0x47, 0x48, 0x49]); { // Simple Writable test. - let n = 0; - const writable = new Writable({ - write: common.mustCall((chunk, encoding, cb) => { + var n = 0; + var writable = new Writable({ + write: common.mustCall(function (chunk, encoding, cb) { assert(chunk instanceof Buffer); if (n++ === 0) { assert.strictEqual(String(chunk), 'ABC'); @@ -32,9 +38,9 @@ const GHI = new Uint8Array([0x47, 0x48, 0x49]); { // Writable test, pass in Uint8Array in object mode. - const writable = new Writable({ + var _writable = new Writable({ objectMode: true, - write: common.mustCall((chunk, encoding, cb) => { + write: common.mustCall(function (chunk, encoding, cb) { assert(!(chunk instanceof Buffer)); assert(chunk instanceof Uint8Array); assert.strictEqual(chunk, ABC); @@ -42,50 +48,50 @@ const GHI = new Uint8Array([0x47, 0x48, 0x49]); cb(); }) }); - writable.end(ABC); + _writable.end(ABC); } { // Writable test, multiple writes carried out via writev. - let callback; - const writable = new Writable({ - write: common.mustCall((chunk, encoding, cb) => { + var callback; + var _writable2 = new Writable({ + write: common.mustCall(function (chunk, encoding, cb) { assert(chunk instanceof Buffer); assert.strictEqual(encoding, 'buffer'); assert.strictEqual(String(chunk), 'ABC'); callback = cb; }), - writev: common.mustCall((chunks, cb) => { + writev: common.mustCall(function (chunks, cb) { assert.strictEqual(chunks.length, 2); assert.strictEqual(chunks[0].encoding, 'buffer'); assert.strictEqual(chunks[1].encoding, 'buffer'); assert.strictEqual(chunks[0].chunk + chunks[1].chunk, 'DEFGHI'); }) }); - writable.write(ABC); - writable.write(DEF); - writable.end(GHI); + _writable2.write(ABC); + _writable2.write(DEF); + _writable2.end(GHI); callback(); } { // Simple Readable test. - const readable = new Readable({ - read() {} + var readable = new Readable({ + read: function read() {} }); readable.push(DEF); readable.unshift(ABC); - const buf = readable.read(); + var buf = readable.read(); assert(buf instanceof Buffer); - assert.deepStrictEqual([...buf], [...ABC, ...DEF]); + assert.deepStrictEqual(_toConsumableArray(buf), [].concat(_toConsumableArray(ABC), _toConsumableArray(DEF))); } { // Readable test, setEncoding. - const readable = new Readable({ - read() {} + var _readable = new Readable({ + read: function read() {} }); - readable.setEncoding('utf8'); - readable.push(DEF); - readable.unshift(ABC); - const out = readable.read(); + _readable.setEncoding('utf8'); + _readable.push(DEF); + _readable.unshift(ABC); + var out = _readable.read(); assert.strictEqual(out, 'ABCDEF'); } ; @@ -96,4 +102,6 @@ const GHI = new Uint8Array([0x47, 0x48, 0x49]); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-unpipe-event.js b/test/parallel/test-stream-unpipe-event.js index e531e0679..ebd402e28 100644 --- a/test/parallel/test-stream-unpipe-event.js +++ b/test/parallel/test-stream-unpipe-event.js @@ -1,95 +1,137 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } if (process.version.indexOf('v0.8') === 0) { process.exit(0); } /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var common = require('../common'); +var assert = require('assert/'); +var _require = require('../../'), Writable = _require.Writable, Readable = _require.Readable; -class NullWriteable extends Writable { - _write(chunk, encoding, callback) { - return callback(); +var NullWriteable = /*#__PURE__*/function (_Writable) { + _inherits(NullWriteable, _Writable); + var _super = _createSuper(NullWriteable); + function NullWriteable() { + _classCallCheck(this, NullWriteable); + return _super.apply(this, arguments); } -} -class QuickEndReadable extends Readable { - _read() { - this.push(null); + _createClass(NullWriteable, [{ + key: "_write", + value: function _write(chunk, encoding, callback) { + return callback(); + } + }]); + return NullWriteable; +}(Writable); +var QuickEndReadable = /*#__PURE__*/function (_Readable) { + _inherits(QuickEndReadable, _Readable); + var _super2 = _createSuper(QuickEndReadable); + function QuickEndReadable() { + _classCallCheck(this, QuickEndReadable); + return _super2.apply(this, arguments); } -} -class NeverEndReadable extends Readable { - _read() {} -} + _createClass(QuickEndReadable, [{ + key: "_read", + value: function _read() { + this.push(null); + } + }]); + return QuickEndReadable; +}(Readable); +var NeverEndReadable = /*#__PURE__*/function (_Readable2) { + _inherits(NeverEndReadable, _Readable2); + var _super3 = _createSuper(NeverEndReadable); + function NeverEndReadable() { + _classCallCheck(this, NeverEndReadable); + return _super3.apply(this, arguments); + } + _createClass(NeverEndReadable, [{ + key: "_read", + value: function _read() {} + }]); + return NeverEndReadable; +}(Readable); { - const dest = new NullWriteable(); - const src = new QuickEndReadable(); + var dest = new NullWriteable(); + var src = new QuickEndReadable(); dest.on('pipe', common.mustCall()); dest.on('unpipe', common.mustCall()); src.pipe(dest); - setImmediate(() => { + setImmediate(function () { assert.strictEqual(src._readableState.pipesCount, 0); }); } { - const dest = new NullWriteable(); - const src = new NeverEndReadable(); - dest.on('pipe', common.mustCall()); - dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); - src.pipe(dest); - setImmediate(() => { - assert.strictEqual(src._readableState.pipesCount, 1); + var _dest = new NullWriteable(); + var _src = new NeverEndReadable(); + _dest.on('pipe', common.mustCall()); + _dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); + _src.pipe(_dest); + setImmediate(function () { + assert.strictEqual(_src._readableState.pipesCount, 1); }); } { - const dest = new NullWriteable(); - const src = new NeverEndReadable(); - dest.on('pipe', common.mustCall()); - dest.on('unpipe', common.mustCall()); - src.pipe(dest); - src.unpipe(dest); - setImmediate(() => { - assert.strictEqual(src._readableState.pipesCount, 0); + var _dest2 = new NullWriteable(); + var _src2 = new NeverEndReadable(); + _dest2.on('pipe', common.mustCall()); + _dest2.on('unpipe', common.mustCall()); + _src2.pipe(_dest2); + _src2.unpipe(_dest2); + setImmediate(function () { + assert.strictEqual(_src2._readableState.pipesCount, 0); }); } { - const dest = new NullWriteable(); - const src = new QuickEndReadable(); - dest.on('pipe', common.mustCall()); - dest.on('unpipe', common.mustCall()); - src.pipe(dest, { + var _dest3 = new NullWriteable(); + var _src3 = new QuickEndReadable(); + _dest3.on('pipe', common.mustCall()); + _dest3.on('unpipe', common.mustCall()); + _src3.pipe(_dest3, { end: false }); - setImmediate(() => { - assert.strictEqual(src._readableState.pipesCount, 0); + setImmediate(function () { + assert.strictEqual(_src3._readableState.pipesCount, 0); }); } { - const dest = new NullWriteable(); - const src = new NeverEndReadable(); - dest.on('pipe', common.mustCall()); - dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); - src.pipe(dest, { + var _dest4 = new NullWriteable(); + var _src4 = new NeverEndReadable(); + _dest4.on('pipe', common.mustCall()); + _dest4.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); + _src4.pipe(_dest4, { end: false }); - setImmediate(() => { - assert.strictEqual(src._readableState.pipesCount, 1); + setImmediate(function () { + assert.strictEqual(_src4._readableState.pipesCount, 1); }); } { - const dest = new NullWriteable(); - const src = new NeverEndReadable(); - dest.on('pipe', common.mustCall()); - dest.on('unpipe', common.mustCall()); - src.pipe(dest, { + var _dest5 = new NullWriteable(); + var _src5 = new NeverEndReadable(); + _dest5.on('pipe', common.mustCall()); + _dest5.on('unpipe', common.mustCall()); + _src5.pipe(_dest5, { end: false }); - src.unpipe(dest); - setImmediate(() => { - assert.strictEqual(src._readableState.pipesCount, 0); + _src5.unpipe(_dest5); + setImmediate(function () { + assert.strictEqual(_src5._readableState.pipesCount, 0); }); } ; @@ -100,4 +142,6 @@ class NeverEndReadable extends Readable { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-unshift-empty-chunk.js b/test/parallel/test-stream-unshift-empty-chunk.js index ebf4b906f..b36124f14 100644 --- a/test/parallel/test-stream-unshift-empty-chunk.js +++ b/test/parallel/test-stream-unshift-empty-chunk.js @@ -22,26 +22,26 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); +var assert = require('assert/'); // This test verifies that stream.unshift(bufferShim.alloc(0)) or // stream.unshift('') does not set state.reading=false. -const Readable = require('../../').Readable; -const r = new Readable(); -let nChunks = 10; -const chunk = bufferShim.alloc(10, 'x'); +var Readable = require('../../').Readable; +var r = new Readable(); +var nChunks = 10; +var chunk = bufferShim.alloc(10, 'x'); r._read = function (n) { - setImmediate(() => { + setImmediate(function () { r.push(--nChunks === 0 ? null : chunk); }); }; -let readAll = false; -const seen = []; -r.on('readable', () => { - let chunk; +var readAll = false; +var seen = []; +r.on('readable', function () { + var chunk; while (chunk = r.read()) { seen.push(chunk.toString()); // simulate only reading a certain amount of the data, @@ -49,13 +49,13 @@ r.on('readable', () => { // stream, like a parser might do. We just fill it with // 'y' so that it's easy to see which bits were touched, // and which were not. - const putBack = bufferShim.alloc(readAll ? 0 : 5, 'y'); + var putBack = bufferShim.alloc(readAll ? 0 : 5, 'y'); readAll = !readAll; r.unshift(putBack); } }); -const expect = ['xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy']; -r.on('end', () => { +var expect = ['xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', 'yyyyy']; +r.on('end', function () { assert.deepStrictEqual(seen, expect); require('tap').pass(); }); @@ -67,4 +67,6 @@ r.on('end', () => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-unshift-read-race.js b/test/parallel/test-stream-unshift-read-race.js index 264cd89f2..375b9b321 100644 --- a/test/parallel/test-stream-unshift-read-race.js +++ b/test/parallel/test-stream-unshift-read-race.js @@ -22,10 +22,10 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); +var common = require('../common'); +var assert = require('assert/'); // This test verifies that: // 1. unshift() does not cause colliding _read() calls. @@ -34,19 +34,19 @@ const assert = require('assert/'); // 3. push() after the EOF signaling null is an error. // 4. _read() is not called after pushing the EOF null chunk. -const stream = require('../../'); -const hwm = 10; -const r = stream.Readable({ +var stream = require('../../'); +var hwm = 10; +var r = stream.Readable({ highWaterMark: hwm }); -const chunks = 10; -const data = bufferShim.allocUnsafe(chunks * hwm + Math.ceil(hwm / 2)); -for (let i = 0; i < data.length; i++) { - const c = 'asdf'.charCodeAt(i % 4); +var chunks = 10; +var data = bufferShim.allocUnsafe(chunks * hwm + Math.ceil(hwm / 2)); +for (var i = 0; i < data.length; i++) { + var c = 'asdf'.charCodeAt(i % 4); data[i] = c; } -let pos = 0; -let pushedNull = false; +var pos = 0; +var pushedNull = false; r._read = function (n) { assert(!pushedNull, '_read after null push'); @@ -54,7 +54,7 @@ r._read = function (n) { push(!(chunks % 3)); function push(fast) { assert(!pushedNull, 'push() after null push'); - const c = pos >= data.length ? null : data.slice(pos, pos + n); + var c = pos >= data.length ? null : data.slice(pos, pos + n); pushedNull = c === null; if (fast) { pos += n; @@ -78,8 +78,8 @@ function pushError() { message: 'stream.push() after EOF' }); } -const w = stream.Writable(); -const written = []; +var w = stream.Writable(); +var written = []; w._write = function (chunk, encoding, cb) { written.push(chunk.toString()); cb(); @@ -95,7 +95,7 @@ r.on('end', common.mustCall(function () { w.end(); })); r.on('readable', function () { - let chunk; + var chunk; while (null !== (chunk = r.read(10))) { w.write(chunk); if (chunk.length > 4) r.unshift(bufferShim.from('1234')); @@ -106,14 +106,14 @@ w.on('finish', common.mustCall(function () { // The first got pulled out before the first unshift('1234'), so it's // lacking that piece. assert.strictEqual(written[0], 'asdfasdfas'); - let asdf = 'd'; - console.error(`0: ${written[0]}`); - for (let i = 1; i < written.length; i++) { - console.error(`${i.toString(32)}: ${written[i]}`); - assert.strictEqual(written[i].slice(0, 4), '1234'); - for (let j = 4; j < written[i].length; j++) { - const c = written[i].charAt(j); - assert.strictEqual(c, asdf); + var asdf = 'd'; + console.error("0: ".concat(written[0])); + for (var _i = 1; _i < written.length; _i++) { + console.error("".concat(_i.toString(32), ": ").concat(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); + assert.strictEqual(_c, asdf); switch (asdf) { case 'a': asdf = 's'; @@ -143,4 +143,6 @@ process.on('exit', function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-change-default-encoding.js b/test/parallel/test-stream-writable-change-default-encoding.js index f952e22c7..102426957 100644 --- a/test/parallel/test-stream-writable-change-default-encoding.js +++ b/test/parallel/test-stream-writable-change-default-encoding.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,23 +34,32 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -class MyWritable extends stream.Writable { - constructor(fn, options) { - super(options); - this.fn = fn; +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var MyWritable = /*#__PURE__*/function (_stream$Writable) { + _inherits(MyWritable, _stream$Writable); + var _super = _createSuper(MyWritable); + function MyWritable(fn, options) { + var _this; + _classCallCheck(this, MyWritable); + _this = _super.call(this, options); + _this.fn = fn; + return _this; } - _write(chunk, encoding, callback) { - this.fn(Buffer.isBuffer(chunk), typeof chunk, encoding); - callback(); - } -} + _createClass(MyWritable, [{ + key: "_write", + value: function _write(chunk, encoding, callback) { + this.fn(Buffer.isBuffer(chunk), typeof chunk, encoding); + callback(); + } + }]); + return MyWritable; +}(stream.Writable); (function defaultCondingIsUtf8() { - const m = new MyWritable(function (isBuffer, type, enc) { + var m = new MyWritable(function (isBuffer, type, enc) { assert.strictEqual(enc, 'utf8'); }, { decodeStrings: false @@ -47,7 +68,7 @@ class MyWritable extends stream.Writable { m.end(); })(); (function changeDefaultEncodingToAscii() { - const m = new MyWritable(function (isBuffer, type, enc) { + var m = new MyWritable(function (isBuffer, type, enc) { assert.strictEqual(enc, 'ascii'); }, { decodeStrings: false @@ -57,7 +78,7 @@ class MyWritable extends stream.Writable { m.end(); })(); common.expectsError(function changeDefaultEncodingToInvalidValue() { - const m = new MyWritable(function (isBuffer, type, enc) {}, { + var m = new MyWritable(function (isBuffer, type, enc) {}, { decodeStrings: false }); m.setDefaultEncoding({}); @@ -69,7 +90,7 @@ common.expectsError(function changeDefaultEncodingToInvalidValue() { message: 'Unknown encoding: [object Object]' }); (function checkVairableCaseEncoding() { - const m = new MyWritable(function (isBuffer, type, enc) { + var m = new MyWritable(function (isBuffer, type, enc) { assert.strictEqual(enc, 'ascii'); }, { decodeStrings: false @@ -86,4 +107,6 @@ common.expectsError(function changeDefaultEncodingToInvalidValue() { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-constructor-set-methods.js b/test/parallel/test-stream-writable-constructor-set-methods.js index 23ab8be17..090f8b922 100644 --- a/test/parallel/test-stream-writable-constructor-set-methods.js +++ b/test/parallel/test-stream-writable-constructor-set-methods.js @@ -1,28 +1,28 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('assert/'), +var common = require('../common'); +var _require = require('assert/'), strictEqual = _require.strictEqual; -const _require2 = require('../../'), +var _require2 = require('../../'), Writable = _require2.Writable; -const w = new Writable(); +var w = new Writable(); w.on('error', common.expectsError({ type: Error, code: 'ERR_METHOD_NOT_IMPLEMENTED', message: 'The _write() method is not implemented' })); w.end(bufferShim.from('blerg')); -const _write = common.mustCall((chunk, _, next) => { +var _write = common.mustCall(function (chunk, _, next) { next(); }); -const _writev = common.mustCall((chunks, next) => { +var _writev = common.mustCall(function (chunks, next) { strictEqual(chunks.length, 2); next(); }); -const w2 = new Writable({ +var w2 = new Writable({ write: _write, writev: _writev }); @@ -41,4 +41,6 @@ w2.end(); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-decoded-encoding.js b/test/parallel/test-stream-writable-decoded-encoding.js index 2ce519c5f..5a23b8cd1 100644 --- a/test/parallel/test-stream-writable-decoded-encoding.js +++ b/test/parallel/test-stream-writable-decoded-encoding.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,23 +34,32 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -class MyWritable extends stream.Writable { - constructor(fn, options) { - super(options); - this.fn = fn; +var assert = require('assert/'); +var stream = require('../../'); +var MyWritable = /*#__PURE__*/function (_stream$Writable) { + _inherits(MyWritable, _stream$Writable); + var _super = _createSuper(MyWritable); + function MyWritable(fn, options) { + var _this; + _classCallCheck(this, MyWritable); + _this = _super.call(this, options); + _this.fn = fn; + return _this; } - _write(chunk, encoding, callback) { - this.fn(Buffer.isBuffer(chunk), typeof chunk, encoding); - callback(); - } -} + _createClass(MyWritable, [{ + key: "_write", + value: function _write(chunk, encoding, callback) { + this.fn(Buffer.isBuffer(chunk), typeof chunk, encoding); + callback(); + } + }]); + return MyWritable; +}(stream.Writable); { - const m = new MyWritable(function (isBuffer, type, enc) { + var m = new MyWritable(function (isBuffer, type, enc) { assert(isBuffer); assert.strictEqual(type, 'object'); assert.strictEqual(enc, 'buffer'); @@ -49,15 +70,15 @@ class MyWritable extends stream.Writable { m.end(); } { - const m = new MyWritable(function (isBuffer, type, enc) { + var _m = new MyWritable(function (isBuffer, type, enc) { assert(!isBuffer); assert.strictEqual(type, 'string'); assert.strictEqual(enc, 'utf8'); }, { decodeStrings: false }); - m.write('some-text', 'utf8'); - m.end(); + _m.write('some-text', 'utf8'); + _m.end(); } ; (function () { @@ -67,4 +88,6 @@ class MyWritable extends stream.Writable { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-destroy.js b/test/parallel/test-stream-writable-destroy.js index 1441e323c..a6e2f83d2 100644 --- a/test/parallel/test-stream-writable-destroy.js +++ b/test/parallel/test-stream-writable-destroy.js @@ -1,16 +1,16 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Writable = _require.Writable; -const assert = require('assert/'); +var assert = require('assert/'); { - const write = new Writable({ - write(chunk, enc, cb) { + var write = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); @@ -20,131 +20,132 @@ const assert = require('assert/'); assert.strictEqual(write.destroyed, true); } { - const write = new Writable({ - write(chunk, enc, cb) { + var _write = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); - const expected = new Error('kaboom'); - write.on('finish', common.mustNotCall()); - write.on('close', common.mustCall()); - write.on('error', common.mustCall(err => { + var expected = new Error('kaboom'); + _write.on('finish', common.mustNotCall()); + _write.on('close', common.mustCall()); + _write.on('error', common.mustCall(function (err) { assert.strictEqual(err, expected); })); - write.destroy(expected); - assert.strictEqual(write.destroyed, true); + _write.destroy(expected); + assert.strictEqual(_write.destroyed, true); } { - const write = new Writable({ - write(chunk, enc, cb) { + var _write2 = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); - write._destroy = function (err, cb) { - assert.strictEqual(err, expected); + _write2._destroy = function (err, cb) { + assert.strictEqual(err, _expected); cb(err); }; - const expected = new Error('kaboom'); - write.on('finish', common.mustNotCall('no finish event')); - write.on('close', common.mustCall()); - write.on('error', common.mustCall(err => { - assert.strictEqual(err, expected); + var _expected = new Error('kaboom'); + _write2.on('finish', common.mustNotCall('no finish event')); + _write2.on('close', common.mustCall()); + _write2.on('error', common.mustCall(function (err) { + assert.strictEqual(err, _expected); })); - write.destroy(expected); - assert.strictEqual(write.destroyed, true); + _write2.destroy(_expected); + assert.strictEqual(_write2.destroyed, true); } { - const write = new Writable({ - write(chunk, enc, cb) { + var _write3 = new Writable({ + write: function write(chunk, enc, cb) { cb(); }, destroy: common.mustCall(function (err, cb) { - assert.strictEqual(err, expected); + assert.strictEqual(err, _expected2); cb(); }) }); - const expected = new Error('kaboom'); - write.on('finish', common.mustNotCall('no finish event')); - write.on('close', common.mustCall()); + var _expected2 = new Error('kaboom'); + _write3.on('finish', common.mustNotCall('no finish event')); + _write3.on('close', common.mustCall()); // error is swallowed by the custom _destroy - write.on('error', common.mustNotCall('no error event')); - write.destroy(expected); - assert.strictEqual(write.destroyed, true); + _write3.on('error', common.mustNotCall('no error event')); + _write3.destroy(_expected2); + assert.strictEqual(_write3.destroyed, true); } { - const write = new Writable({ - write(chunk, enc, cb) { + var _write4 = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); - write._destroy = common.mustCall(function (err, cb) { + _write4._destroy = common.mustCall(function (err, cb) { assert.strictEqual(err, null); cb(); }); - write.destroy(); - assert.strictEqual(write.destroyed, true); + _write4.destroy(); + assert.strictEqual(_write4.destroyed, true); } { - const write = new Writable({ - write(chunk, enc, cb) { + var _write5 = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); - write._destroy = common.mustCall(function (err, cb) { + _write5._destroy = common.mustCall(function (err, cb) { + var _this = this; assert.strictEqual(err, null); - process.nextTick(() => { - this.end(); + process.nextTick(function () { + _this.end(); cb(); }); }); - const fail = common.mustNotCall('no finish event'); - write.on('finish', fail); - write.on('close', common.mustCall()); - write.destroy(); - write.removeListener('finish', fail); - write.on('finish', common.mustCall()); - assert.strictEqual(write.destroyed, true); + var fail = common.mustNotCall('no finish event'); + _write5.on('finish', fail); + _write5.on('close', common.mustCall()); + _write5.destroy(); + _write5.removeListener('finish', fail); + _write5.on('finish', common.mustCall()); + assert.strictEqual(_write5.destroyed, true); } { - const write = new Writable({ - write(chunk, enc, cb) { + var _write6 = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); - const expected = new Error('kaboom'); - write._destroy = common.mustCall(function (err, cb) { + var _expected3 = new Error('kaboom'); + _write6._destroy = common.mustCall(function (err, cb) { assert.strictEqual(err, null); - cb(expected); + cb(_expected3); }); - write.on('close', common.mustCall()); - write.on('finish', common.mustNotCall('no finish event')); - write.on('error', common.mustCall(err => { - assert.strictEqual(err, expected); + _write6.on('close', common.mustCall()); + _write6.on('finish', common.mustNotCall('no finish event')); + _write6.on('error', common.mustCall(function (err) { + assert.strictEqual(err, _expected3); })); - write.destroy(); - assert.strictEqual(write.destroyed, true); + _write6.destroy(); + assert.strictEqual(_write6.destroyed, true); } { // double error case - const write = new Writable({ - write(chunk, enc, cb) { + var _write7 = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); - write.on('close', common.mustCall()); - write.on('error', common.mustCall()); - write.destroy(new Error('kaboom 1')); - write.destroy(new Error('kaboom 2')); - assert.strictEqual(write._writableState.errorEmitted, true); - assert.strictEqual(write.destroyed, true); + _write7.on('close', common.mustCall()); + _write7.on('error', common.mustCall()); + _write7.destroy(new Error('kaboom 1')); + _write7.destroy(new Error('kaboom 2')); + assert.strictEqual(_write7._writableState.errorEmitted, true); + assert.strictEqual(_write7.destroyed, true); } { - const writable = new Writable({ + var writable = new Writable({ destroy: common.mustCall(function (err, cb) { process.nextTick(cb, new Error('kaboom 1')); }), - write(chunk, enc, cb) { + write: function write(chunk, enc, cb) { cb(); } }); @@ -163,52 +164,54 @@ const assert = require('assert/'); assert.strictEqual(writable._writableState.errorEmitted, true); } { - const write = new Writable({ - write(chunk, enc, cb) { + var _write8 = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); - write.destroyed = true; - assert.strictEqual(write.destroyed, true); + _write8.destroyed = true; + assert.strictEqual(_write8.destroyed, true); // the internal destroy() mechanism should not be triggered - write.on('close', common.mustNotCall()); - write.destroy(); + _write8.on('close', common.mustNotCall()); + _write8.destroy(); } { - function MyWritable() { + var MyWritable = function MyWritable() { assert.strictEqual(this.destroyed, false); this.destroyed = false; Writable.call(this); - } + }; Object.setPrototypeOf(MyWritable.prototype, Writable.prototype); Object.setPrototypeOf(MyWritable, Writable); new MyWritable(); } { // destroy and destroy callback - const write = new Writable({ - write(chunk, enc, cb) { + var _write9 = new Writable({ + write: function write(chunk, enc, cb) { cb(); } }); - write.destroy(); - const expected = new Error('kaboom'); - write.destroy(expected, common.mustCall(function (err) { - assert.strictEqual(err, expected); + _write9.destroy(); + var _expected4 = new Error('kaboom'); + _write9.destroy(_expected4, common.mustCall(function (err) { + assert.strictEqual(err, _expected4); })); } { // Checks that `._undestroy()` restores the state so that `final` will be // called again. - const write = new Writable({ + var _write10 = new Writable({ write: common.mustNotCall(), - final: common.mustCall(cb => cb(), 2) + final: common.mustCall(function (cb) { + return cb(); + }, 2) }); - write.end(); - write.destroy(); - write._undestroy(); - write.end(); + _write10.end(); + _write10.destroy(); + _write10._undestroy(); + _write10.end(); } ; (function () { @@ -218,4 +221,6 @@ const assert = require('assert/'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-ended-state.js b/test/parallel/test-stream-writable-ended-state.js index 96313b509..3d24d20bb 100644 --- a/test/parallel/test-stream-writable-ended-state.js +++ b/test/parallel/test-stream-writable-ended-state.js @@ -1,19 +1,19 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const writable = new stream.Writable(); -writable._write = (chunk, encoding, cb) => { +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var writable = new stream.Writable(); +writable._write = function (chunk, encoding, cb) { assert.strictEqual(writable._writableState.ended, false); cb(); }; assert.strictEqual(writable._writableState.ended, false); -writable.end('testing ended state', common.mustCall(() => { +writable.end('testing ended state', common.mustCall(function () { assert.strictEqual(writable._writableState.ended, true); })); assert.strictEqual(writable._writableState.ended, true); @@ -25,4 +25,6 @@ assert.strictEqual(writable._writableState.ended, true); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-finished-state.js b/test/parallel/test-stream-writable-finished-state.js index b1bfcfde4..ce2bf9ef2 100644 --- a/test/parallel/test-stream-writable-finished-state.js +++ b/test/parallel/test-stream-writable-finished-state.js @@ -1,22 +1,22 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const writable = new stream.Writable(); -writable._write = (chunk, encoding, cb) => { +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var writable = new stream.Writable(); +writable._write = function (chunk, encoding, cb) { // The state finished should start in false. assert.strictEqual(writable._writableState.finished, false); cb(); }; -writable.on('finish', common.mustCall(() => { +writable.on('finish', common.mustCall(function () { assert.strictEqual(writable._writableState.finished, true); })); -writable.end('testing finished state', common.mustCall(() => { +writable.end('testing finished state', common.mustCall(function () { assert.strictEqual(writable._writableState.finished, true); })); ; @@ -27,4 +27,6 @@ writable.end('testing finished state', common.mustCall(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-needdrain-state.js b/test/parallel/test-stream-writable-needdrain-state.js index f9d57a3e5..f8076e147 100644 --- a/test/parallel/test-stream-writable-needdrain-state.js +++ b/test/parallel/test-stream-writable-needdrain-state.js @@ -1,13 +1,13 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const stream = require('../../'); -const assert = require('assert/'); -const transform = new stream.Transform({ +var common = require('../common'); +var stream = require('../../'); +var assert = require('assert/'); +var transform = new stream.Transform({ transform: _transform, highWaterMark: 1 }); @@ -16,7 +16,7 @@ function _transform(chunk, encoding, cb) { cb(); } assert.strictEqual(transform._writableState.needDrain, false); -transform.write('asdasd', common.mustCall(() => { +transform.write('asdasd', common.mustCall(function () { assert.strictEqual(transform._writableState.needDrain, false); })); assert.strictEqual(transform._writableState.needDrain, true); @@ -28,4 +28,6 @@ assert.strictEqual(transform._writableState.needDrain, true); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-null.js b/test/parallel/test-stream-writable-null.js index bb42045aa..88fc5b423 100644 --- a/test/parallel/test-stream-writable-null.js +++ b/test/parallel/test-stream-writable-null.js @@ -1,22 +1,46 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -class MyWritable extends stream.Writable { - _write(chunk, encoding, callback) { - assert.notStrictEqual(chunk, null); - callback(); +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var MyWritable = /*#__PURE__*/function (_stream$Writable) { + _inherits(MyWritable, _stream$Writable); + var _super = _createSuper(MyWritable); + function MyWritable() { + _classCallCheck(this, MyWritable); + return _super.apply(this, arguments); } -} -common.expectsError(() => { - const m = new MyWritable({ + _createClass(MyWritable, [{ + key: "_write", + value: function _write(chunk, encoding, callback) { + assert.notStrictEqual(chunk, null); + callback(); + } + }]); + return MyWritable; +}(stream.Writable); +common.expectsError(function () { + var m = new MyWritable({ objectMode: true }); - m.write(null, err => assert.ok(err)); + m.write(null, function (err) { + return assert.ok(err); + }); }, { code: 'ERR_STREAM_NULL_VALUES', type: TypeError, @@ -24,38 +48,40 @@ common.expectsError(() => { }); { // Should not throw. - const m = new MyWritable({ + var m = new MyWritable({ objectMode: true }).on('error', assert); m.write(null, assert); } -common.expectsError(() => { - const m = new MyWritable(); - m.write(false, err => assert.ok(err)); +common.expectsError(function () { + var m = new MyWritable(); + m.write(false, function (err) { + return assert.ok(err); + }); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }); { // Should not throw. - const m = new MyWritable().on('error', assert); - m.write(false, assert); + var _m = new MyWritable().on('error', assert); + _m.write(false, assert); } { // Should not throw. - const m = new MyWritable({ + var _m2 = new MyWritable({ objectMode: true }); - m.write(false, assert.ifError); + _m2.write(false, assert.ifError); } { // Should not throw. - const m = new MyWritable({ + var _m3 = new MyWritable({ objectMode: true - }).on('error', e => { + }).on('error', function (e) { assert.ifError(e || new Error('should not get here')); }); - m.write(false, assert.ifError); + _m3.write(false, assert.ifError); } ; (function () { @@ -65,4 +91,6 @@ common.expectsError(() => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-write-cb-twice.js b/test/parallel/test-stream-writable-write-cb-twice.js index dd33b5bde..60146b904 100644 --- a/test/parallel/test-stream-writable-write-cb-twice.js +++ b/test/parallel/test-stream-writable-write-cb-twice.js @@ -1,15 +1,15 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const _require = require('../../'), +var common = require('../common'); +var _require = require('../../'), Writable = _require.Writable; { // Sync + Sync - const writable = new Writable({ - write: common.mustCall((buf, enc, cb) => { + var writable = new Writable({ + write: common.mustCall(function (buf, enc, cb) { cb(); common.expectsError(cb, { code: 'ERR_MULTIPLE_CALLBACK', @@ -21,10 +21,10 @@ const _require = require('../../'), } { // Sync + Async - const writable = new Writable({ - write: common.mustCall((buf, enc, cb) => { + var _writable = new Writable({ + write: common.mustCall(function (buf, enc, cb) { cb(); - process.nextTick(() => { + process.nextTick(function () { common.expectsError(cb, { code: 'ERR_MULTIPLE_CALLBACK', type: Error @@ -32,14 +32,14 @@ const _require = require('../../'), }); }) }); - writable.write('hi'); + _writable.write('hi'); } { // Async + Async - const writable = new Writable({ - write: common.mustCall((buf, enc, cb) => { + var _writable2 = new Writable({ + write: common.mustCall(function (buf, enc, cb) { process.nextTick(cb); - process.nextTick(() => { + process.nextTick(function () { common.expectsError(cb, { code: 'ERR_MULTIPLE_CALLBACK', type: Error @@ -47,7 +47,7 @@ const _require = require('../../'), }); }) }); - writable.write('hi'); + _writable2.write('hi'); } ; (function () { @@ -57,4 +57,6 @@ const _require = require('../../'), var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writable-write-writev-finish.js b/test/parallel/test-stream-writable-write-writev-finish.js index 442038d3e..8f83069ad 100644 --- a/test/parallel/test-stream-writable-write-writev-finish.js +++ b/test/parallel/test-stream-writable-write-writev-finish.js @@ -1,92 +1,92 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); // ensure consistency between the finish event when using cork() // and writev and when not using them { - const writable = new stream.Writable(); - writable._write = (chunks, encoding, cb) => { + var writable = new stream.Writable(); + writable._write = function (chunks, encoding, cb) { cb(new Error('write test error')); }; - let firstError = false; + var firstError = false; writable.on('finish', common.mustCall(function () { assert.strictEqual(firstError, true); })); writable.on('prefinish', common.mustCall()); - writable.on('error', common.mustCall(er => { + writable.on('error', common.mustCall(function (er) { assert.strictEqual(er.message, 'write test error'); firstError = true; })); writable.end('test'); } { - const writable = new stream.Writable(); - writable._write = (chunks, encoding, cb) => { + var _writable = new stream.Writable(); + _writable._write = function (chunks, encoding, cb) { setImmediate(cb, new Error('write test error')); }; - let firstError = false; - writable.on('finish', common.mustCall(function () { - assert.strictEqual(firstError, true); + var _firstError = false; + _writable.on('finish', common.mustCall(function () { + assert.strictEqual(_firstError, true); })); - writable.on('prefinish', common.mustCall()); - writable.on('error', common.mustCall(er => { + _writable.on('prefinish', common.mustCall()); + _writable.on('error', common.mustCall(function (er) { assert.strictEqual(er.message, 'write test error'); - firstError = true; + _firstError = true; })); - writable.end('test'); + _writable.end('test'); } { - const writable = new stream.Writable(); - writable._write = (chunks, encoding, cb) => { + var _writable2 = new stream.Writable(); + _writable2._write = function (chunks, encoding, cb) { cb(new Error('write test error')); }; - writable._writev = (chunks, cb) => { + _writable2._writev = function (chunks, cb) { cb(new Error('writev test error')); }; - let firstError = false; - writable.on('finish', common.mustCall(function () { - assert.strictEqual(firstError, true); + var _firstError2 = false; + _writable2.on('finish', common.mustCall(function () { + assert.strictEqual(_firstError2, true); })); - writable.on('prefinish', common.mustCall()); - writable.on('error', common.mustCall(er => { + _writable2.on('prefinish', common.mustCall()); + _writable2.on('error', common.mustCall(function (er) { assert.strictEqual(er.message, 'writev test error'); - firstError = true; + _firstError2 = true; })); - writable.cork(); - writable.write('test'); + _writable2.cork(); + _writable2.write('test'); setImmediate(function () { - writable.end('test'); + _writable2.end('test'); }); } { - const writable = new stream.Writable(); - writable._write = (chunks, encoding, cb) => { + var _writable3 = new stream.Writable(); + _writable3._write = function (chunks, encoding, cb) { setImmediate(cb, new Error('write test error')); }; - writable._writev = (chunks, cb) => { + _writable3._writev = function (chunks, cb) { setImmediate(cb, new Error('writev test error')); }; - let firstError = false; - writable.on('finish', common.mustCall(function () { - assert.strictEqual(firstError, true); + var _firstError3 = false; + _writable3.on('finish', common.mustCall(function () { + assert.strictEqual(_firstError3, true); })); - writable.on('prefinish', common.mustCall()); - writable.on('error', common.mustCall(er => { + _writable3.on('prefinish', common.mustCall()); + _writable3.on('error', common.mustCall(function (er) { assert.strictEqual(er.message, 'writev test error'); - firstError = true; + _firstError3 = true; })); - writable.cork(); - writable.write('test'); + _writable3.cork(); + _writable3.write('test'); setImmediate(function () { - writable.end('test'); + _writable3.end('test'); }); } @@ -94,57 +94,57 @@ const stream = require('../../'); // https://github.com/nodejs/node/issues/13812 { - const rs = new stream.Readable(); + var rs = new stream.Readable(); rs.push('ok'); rs.push(null); - rs._read = () => {}; - const ws = new stream.Writable(); - let firstError = false; + rs._read = function () {}; + var ws = new stream.Writable(); + var _firstError4 = false; ws.on('finish', common.mustCall(function () { - assert.strictEqual(firstError, true); + assert.strictEqual(_firstError4, true); })); ws.on('error', common.mustCall(function () { - firstError = true; + _firstError4 = true; })); - ws._write = (chunk, encoding, done) => { + ws._write = function (chunk, encoding, done) { setImmediate(done, new Error()); }; rs.pipe(ws); } { - const rs = new stream.Readable(); - rs.push('ok'); - rs.push(null); - rs._read = () => {}; - const ws = new stream.Writable(); - ws.on('finish', common.mustNotCall()); - ws.on('error', common.mustCall()); - ws._write = (chunk, encoding, done) => { + var _rs = new stream.Readable(); + _rs.push('ok'); + _rs.push(null); + _rs._read = function () {}; + var _ws = new stream.Writable(); + _ws.on('finish', common.mustNotCall()); + _ws.on('error', common.mustCall()); + _ws._write = function (chunk, encoding, done) { done(new Error()); }; - rs.pipe(ws); + _rs.pipe(_ws); } { - const w = new stream.Writable(); - w._write = (chunk, encoding, cb) => { + var w = new stream.Writable(); + w._write = function (chunk, encoding, cb) { process.nextTick(cb); }; w.on('error', common.mustCall()); - w.on('prefinish', () => { + w.on('prefinish', function () { w.write("shouldn't write in prefinish listener"); }); w.end(); } { - const w = new stream.Writable(); - w._write = (chunk, encoding, cb) => { + var _w = new stream.Writable(); + _w._write = function (chunk, encoding, cb) { process.nextTick(cb); }; - w.on('error', common.mustCall()); - w.on('finish', () => { - w.write("shouldn't write in finish listener"); + _w.on('error', common.mustCall()); + _w.on('finish', function () { + _w.write("shouldn't write in finish listener"); }); - w.end(); + _w.end(); } ; (function () { @@ -154,4 +154,6 @@ const stream = require('../../'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writableState-ending.js b/test/parallel/test-stream-writableState-ending.js index 5ec0074e3..9be0e94d0 100644 --- a/test/parallel/test-stream-writableState-ending.js +++ b/test/parallel/test-stream-writableState-ending.js @@ -1,28 +1,28 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const writable = new stream.Writable(); +var assert = require('assert/'); +var stream = require('../../'); +var writable = new stream.Writable(); function testStates(ending, finished, ended) { assert.strictEqual(writable._writableState.ending, ending); assert.strictEqual(writable._writableState.finished, finished); assert.strictEqual(writable._writableState.ended, ended); } -writable._write = (chunk, encoding, cb) => { +writable._write = function (chunk, encoding, cb) { // ending, finished, ended start in false. testStates(false, false, false); cb(); }; -writable.on('finish', () => { +writable.on('finish', function () { // ending, finished, ended = true. testStates(true, true, true); }); -const result = writable.end('testing function end()', () => { +var result = writable.end('testing function end()', function () { // ending, finished, ended = true. testStates(true, true, true); }); @@ -41,4 +41,6 @@ testStates(true, false, true); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writableState-uncorked-bufferedRequestCount.js b/test/parallel/test-stream-writableState-uncorked-bufferedRequestCount.js index d9bb48c66..331c51e10 100644 --- a/test/parallel/test-stream-writableState-uncorked-bufferedRequestCount.js +++ b/test/parallel/test-stream-writableState-uncorked-bufferedRequestCount.js @@ -1,18 +1,18 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const writable = new stream.Writable(); -writable._writev = common.mustCall((chunks, cb) => { +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var writable = new stream.Writable(); +writable._writev = common.mustCall(function (chunks, cb) { assert.strictEqual(chunks.length, 2); cb(); }, 1); -writable._write = common.mustCall((chunk, encoding, cb) => { +writable._write = common.mustCall(function (chunk, encoding, cb) { cb(); }, 1); @@ -62,4 +62,6 @@ function uncork() { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-write-destroy.js b/test/parallel/test-stream-write-destroy.js index b83752517..e321fa33d 100644 --- a/test/parallel/test-stream-write-destroy.js +++ b/test/parallel/test-stream-write-destroy.js @@ -1,34 +1,40 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var assert = require('assert/'); +var _require = require('../../'), Writable = _require.Writable; // Test interaction between calling .destroy() on a writable and pending // writes. for (var _i = 0, _arr = [false, true]; _i < _arr.length; _i++) { - const withPendingData = _arr[_i]; - for (var _i2 = 0, _arr2 = [false, true]; _i2 < _arr2.length; _i2++) { - const useEnd = _arr2[_i2]; - const callbacks = []; - const w = new Writable({ - write(data, enc, cb) { + var withPendingData = _arr[_i]; + var _loop = function _loop() { + var useEnd = _arr2[_i2]; + var callbacks = []; + var w = new Writable({ + write: function write(data, enc, cb) { callbacks.push(cb); }, // Effectively disable the HWM to observe 'drain' events more easily. highWaterMark: 1 }); - let chunksWritten = 0; - let drains = 0; - let finished = false; - w.on('drain', () => drains++); - w.on('finish', () => finished = true); - w.write('abc', () => chunksWritten++); + var chunksWritten = 0; + var drains = 0; + var finished = false; + w.on('drain', function () { + return drains++; + }); + w.on('finish', function () { + return finished = true; + }); + w.write('abc', function () { + return chunksWritten++; + }); assert.strictEqual(chunksWritten, 0); assert.strictEqual(drains, 0); callbacks.shift()(); @@ -37,14 +43,20 @@ for (var _i = 0, _arr = [false, true]; _i < _arr.length; _i++) { if (withPendingData) { // Test 2 cases: There either is or is not data still in the write queue. // (The second write will never actually get executed either way.) - w.write('def', () => chunksWritten++); + w.write('def', function () { + return chunksWritten++; + }); } if (useEnd) { // Again, test 2 cases: Either we indicate that we want to end the // writable or not. - w.end('ghi', () => chunksWritten++); + w.end('ghi', function () { + return chunksWritten++; + }); } else { - w.write('ghi', () => chunksWritten++); + w.write('ghi', function () { + return chunksWritten++; + }); } assert.strictEqual(chunksWritten, 1); w.destroy(); @@ -57,6 +69,9 @@ for (var _i = 0, _arr = [false, true]; _i < _arr.length; _i++) { // When we used `.end()`, we see the 'finished' event if and only if // we actually finished processing the write queue. assert.strictEqual(finished, !withPendingData && useEnd); + }; + for (var _i2 = 0, _arr2 = [false, true]; _i2 < _arr2.length; _i2++) { + _loop(); } } ; @@ -67,4 +82,6 @@ for (var _i = 0, _arr = [false, true]; _i < _arr.length; _i++) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-write-final.js b/test/parallel/test-stream-write-final.js index d16d052f2..0a0d1a16a 100644 --- a/test/parallel/test-stream-write-final.js +++ b/test/parallel/test-stream-write-final.js @@ -1,13 +1,13 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -let shutdown = false; -const w = new stream.Writable({ +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var shutdown = false; +var w = new stream.Writable({ final: common.mustCall(function (cb) { assert.strictEqual(this, w); setTimeout(function () { @@ -32,4 +32,6 @@ w.end(bufferShim.allocUnsafe(0)); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writev.js b/test/parallel/test-stream-writev.js index 9aba14f6b..c7d2152af 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -22,42 +22,42 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const queue = []; -for (let decode = 0; decode < 2; decode++) { - for (let uncork = 0; uncork < 2; uncork++) { - for (let multi = 0; multi < 2; multi++) { +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); +var queue = []; +for (var decode = 0; decode < 2; decode++) { + for (var uncork = 0; uncork < 2; uncork++) { + for (var multi = 0; multi < 2; multi++) { queue.push([!!decode, !!uncork, !!multi]); } } } run(); function run() { - const t = queue.pop(); + var t = queue.pop(); if (t) test(t[0], t[1], t[2], run);else require('tap').pass(); } function test(decode, uncork, multi, next) { - require('tap').test(`# decode=${decode} uncork=${uncork} multi=${multi}`); - let counter = 0; - let expectCount = 0; + require('tap').test("# decode=".concat(decode, " uncork=").concat(uncork, " multi=").concat(multi)); + var counter = 0; + var expectCount = 0; function cnt(msg) { expectCount++; - const expect = expectCount; + var expect = expectCount; return function (er) { assert.ifError(er); counter++; assert.strictEqual(counter, expect); }; } - const w = new stream.Writable({ + var w = new stream.Writable({ decodeStrings: decode }); w._write = common.mustNotCall('Should not call _write'); - const expectChunks = decode ? [{ + var expectChunks = decode ? [{ encoding: 'buffer', chunk: [104, 101, 108, 108, 111, 44, 32] }, { @@ -88,7 +88,7 @@ function test(decode, uncork, multi, next) { encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' }]; - let actualChunks; + var actualChunks; w._writev = function (chunks, cb) { actualChunks = chunks.map(function (chunk) { return { @@ -123,4 +123,6 @@ function test(decode, uncork, multi, next) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-base64-single-char-read-end.js b/test/parallel/test-stream2-base64-single-char-read-end.js index c95e20cf9..64e7929a7 100644 --- a/test/parallel/test-stream2-base64-single-char-read-end.js +++ b/test/parallel/test-stream2-base64-single-char-read-end.js @@ -22,18 +22,18 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const R = require('../../lib/_stream_readable'); -const W = require('../../lib/_stream_writable'); -const assert = require('assert/'); -const src = new R({ +var R = require('../../lib/_stream_readable'); +var W = require('../../lib/_stream_writable'); +var assert = require('assert/'); +var src = new R({ encoding: 'base64' }); -const dst = new W(); -let hasRead = false; -const accum = []; +var dst = new W(); +var hasRead = false; +var accum = []; src._read = function (n) { if (!hasRead) { hasRead = true; @@ -52,7 +52,7 @@ src.on('end', function () { clearTimeout(timeout); }); src.pipe(dst); -const timeout = setTimeout(function () { +var timeout = setTimeout(function () { assert.fail('timed out waiting for _write'); }, 100); ; @@ -63,4 +63,6 @@ const timeout = setTimeout(function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-basic.js b/test/parallel/test-stream2-basic.js index cbd08db5f..d0094c439 100644 --- a/test/parallel/test-stream2-basic.js +++ b/test/parallel/test-stream2-basic.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,100 +34,121 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const R = require('../../lib/_stream_readable'); -const assert = require('assert/'); -const EE = require('events').EventEmitter; -class TestReader extends R { - constructor(n) { - super(); - this._buffer = bufferShim.alloc(n || 100, 'x'); - this._pos = 0; - this._bufs = 10; +var common = require('../common'); +var R = require('../../lib/_stream_readable'); +var assert = require('assert/'); +var EE = require('events').EventEmitter; +var TestReader = /*#__PURE__*/function (_R) { + _inherits(TestReader, _R); + var _super = _createSuper(TestReader); + function TestReader(n) { + var _this; + _classCallCheck(this, TestReader); + _this = _super.call(this); + _this._buffer = bufferShim.alloc(n || 100, 'x'); + _this._pos = 0; + _this._bufs = 10; + return _this; } - _read(n) { - const max = this._buffer.length - this._pos; - n = Math.max(n, 0); - const toRead = Math.min(n, max); - if (toRead === 0) { - // simulate the read buffer filling up with some more bytes some time - // in the future. - setTimeout(() => { - this._pos = 0; - this._bufs -= 1; - if (this._bufs <= 0) { - // read them all! - if (!this.ended) this.push(null); - } else { - // now we have more. - // kinda cheating by calling _read, but whatever, - // it's just fake anyway. - this._read(n); - } - }, 10); - return; + _createClass(TestReader, [{ + key: "_read", + value: function _read(n) { + var _this2 = this; + var max = this._buffer.length - this._pos; + n = Math.max(n, 0); + var toRead = Math.min(n, max); + if (toRead === 0) { + // simulate the read buffer filling up with some more bytes some time + // in the future. + setTimeout(function () { + _this2._pos = 0; + _this2._bufs -= 1; + if (_this2._bufs <= 0) { + // read them all! + if (!_this2.ended) _this2.push(null); + } else { + // now we have more. + // kinda cheating by calling _read, but whatever, + // it's just fake anyway. + _this2._read(n); + } + }, 10); + return; + } + var ret = this._buffer.slice(this._pos, this._pos + toRead); + this._pos += toRead; + this.push(ret); } - const ret = this._buffer.slice(this._pos, this._pos + toRead); - this._pos += toRead; - this.push(ret); + }]); + return TestReader; +}(R); +var TestWriter = /*#__PURE__*/function (_EE) { + _inherits(TestWriter, _EE); + var _super2 = _createSuper(TestWriter); + function TestWriter() { + var _this3; + _classCallCheck(this, TestWriter); + _this3 = _super2.call(this); + _this3.received = []; + _this3.flush = false; + return _this3; } -} -class TestWriter extends EE { - constructor() { - super(); - this.received = []; - this.flush = false; - } - write(c) { - this.received.push(c.toString()); - this.emit('write', c); - return true; - } - end(c) { - if (c) this.write(c); - this.emit('end', this.received); - } -} + _createClass(TestWriter, [{ + key: "write", + value: function write(c) { + this.received.push(c.toString()); + this.emit('write', c); + return true; + } + }, { + key: "end", + value: function end(c) { + if (c) this.write(c); + this.emit('end', this.received); + } + }]); + return TestWriter; +}(EE); { - // Test basic functionality - const r = new TestReader(20); - const reads = []; - const expect = ['x', 'xx', 'xxx', 'xxxx', 'xxxxx', 'xxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxxxxx', 'xxxxxxxxxxxxx', 'xxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxx']; - r.on('end', common.mustCall(function () { - assert.deepStrictEqual(reads, expect); - })); - let readSize = 1; - function flow() { - let res; + var flow = function flow() { + var res; while (null !== (res = r.read(readSize++))) { reads.push(res.toString()); } r.once('readable', flow); - } + }; + // Test basic functionality + var r = new TestReader(20); + var reads = []; + var expect = ['x', 'xx', 'xxx', 'xxxx', 'xxxxx', 'xxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxxxxx', 'xxxxxxxxxxxxx', 'xxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxx']; + r.on('end', common.mustCall(function () { + assert.deepStrictEqual(reads, expect); + })); + var readSize = 1; flow(); } { // Verify pipe - const r = new TestReader(5); - const expect = ['xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']; - const w = new TestWriter(); + var _r = new TestReader(5); + var _expect = ['xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']; + var w = new TestWriter(); w.on('end', common.mustCall(function (received) { - assert.deepStrictEqual(received, expect); + assert.deepStrictEqual(received, _expect); })); - r.pipe(w); + _r.pipe(w); } forEach([1, 2, 3, 4, 5, 6, 7, 8, 9], function (SPLIT) { // Verify unpipe - const r = new TestReader(5); + var r = new TestReader(5); // unpipe after 3 writes, then write to another stream instead. - let expect = ['xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']; + var expect = ['xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']; expect = [expect.slice(0, SPLIT), expect.slice(SPLIT)]; - const w = [new TestWriter(), new TestWriter()]; - let writes = SPLIT; + var w = [new TestWriter(), new TestWriter()]; + var writes = SPLIT; w[0].on('write', function () { if (--writes === 0) { r.unpipe(); @@ -125,7 +158,7 @@ forEach([1, 2, 3, 4, 5, 6, 7, 8, 9], function (SPLIT) { assert.strictEqual(r._readableState.pipes, w[1]); } }); - let ended = 0; + var ended = 0; w[0].on('end', common.mustCall(function (results) { ended++; assert.strictEqual(ended, 1); @@ -140,27 +173,27 @@ forEach([1, 2, 3, 4, 5, 6, 7, 8, 9], function (SPLIT) { }); { // Verify both writers get the same data when piping to destinations - const r = new TestReader(5); - const w = [new TestWriter(), new TestWriter()]; - const expect = ['xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']; - w[0].on('end', common.mustCall(function (received) { - assert.deepStrictEqual(received, expect); + var _r2 = new TestReader(5); + var _w = [new TestWriter(), new TestWriter()]; + var _expect2 = ['xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']; + _w[0].on('end', common.mustCall(function (received) { + assert.deepStrictEqual(received, _expect2); })); - w[1].on('end', common.mustCall(function (received) { - assert.deepStrictEqual(received, expect); + _w[1].on('end', common.mustCall(function (received) { + assert.deepStrictEqual(received, _expect2); })); - r.pipe(w[0]); - r.pipe(w[1]); + _r2.pipe(_w[0]); + _r2.pipe(_w[1]); } forEach([1, 2, 3, 4, 5, 6, 7, 8, 9], function (SPLIT) { // Verify multi-unpipe - const r = new TestReader(5); + var r = new TestReader(5); // unpipe after 3 writes, then write to another stream instead. - let expect = ['xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']; + var expect = ['xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']; expect = [expect.slice(0, SPLIT), expect.slice(SPLIT)]; - const w = [new TestWriter(), new TestWriter(), new TestWriter()]; - let writes = SPLIT; + var w = [new TestWriter(), new TestWriter(), new TestWriter()]; + var writes = SPLIT; w[0].on('write', function () { if (--writes === 0) { r.unpipe(); @@ -168,7 +201,7 @@ forEach([1, 2, 3, 4, 5, 6, 7, 8, 9], function (SPLIT) { r.pipe(w[1]); } }); - let ended = 0; + var ended = 0; w[0].on('end', common.mustCall(function (results) { ended++; assert.strictEqual(ended, 1); @@ -184,29 +217,29 @@ forEach([1, 2, 3, 4, 5, 6, 7, 8, 9], function (SPLIT) { }); { // Verify that back pressure is respected - const r = new R({ + var _r3 = new R({ objectMode: true }); - r._read = common.mustNotCall(); - let counter = 0; - r.push(['one']); - r.push(['two']); - r.push(['three']); - r.push(['four']); - r.push(null); - const w1 = new R(); + _r3._read = common.mustNotCall(); + var counter = 0; + _r3.push(['one']); + _r3.push(['two']); + _r3.push(['three']); + _r3.push(['four']); + _r3.push(null); + var w1 = new R(); w1.write = function (chunk) { assert.strictEqual(chunk[0], 'one'); w1.emit('close'); process.nextTick(function () { - r.pipe(w2); - r.pipe(w3); + _r3.pipe(w2); + _r3.pipe(w3); }); }; w1.end = common.mustNotCall(); - r.pipe(w1); - const expected = ['two', 'two', 'three', 'three', 'four', 'four']; - const w2 = new R(); + _r3.pipe(w1); + var expected = ['two', 'two', 'three', 'three', 'four', 'four']; + var w2 = new R(); w2.write = function (chunk) { assert.strictEqual(chunk[0], expected.shift()); assert.strictEqual(counter, 0); @@ -221,7 +254,7 @@ forEach([1, 2, 3, 4, 5, 6, 7, 8, 9], function (SPLIT) { return false; }; w2.end = common.mustCall(); - const w3 = new R(); + var w3 = new R(); w3.write = function (chunk) { assert.strictEqual(chunk[0], expected.shift()); assert.strictEqual(counter, 1); @@ -242,67 +275,67 @@ forEach([1, 2, 3, 4, 5, 6, 7, 8, 9], function (SPLIT) { } { // Verify read(0) behavior for ended streams - const r = new R(); - let written = false; - let ended = false; - r._read = common.mustNotCall(); - r.push(bufferShim.from('foo')); - r.push(null); - const v = r.read(0); + var _r4 = new R(); + var written = false; + var ended = false; + _r4._read = common.mustNotCall(); + _r4.push(bufferShim.from('foo')); + _r4.push(null); + var v = _r4.read(0); assert.strictEqual(v, null); - const w = new R(); - w.write = function (buffer) { + var _w2 = new R(); + _w2.write = function (buffer) { written = true; assert.strictEqual(ended, false); assert.strictEqual(buffer.toString(), 'foo'); }; - w.end = common.mustCall(function () { + _w2.end = common.mustCall(function () { ended = true; assert.strictEqual(written, true); }); - r.pipe(w); + _r4.pipe(_w2); } { // Verify synchronous _read ending - const r = new R(); - let called = false; - r._read = function (n) { - r.push(null); + var _r5 = new R(); + var called = false; + _r5._read = function (n) { + _r5.push(null); }; - r.once('end', function () { + _r5.once('end', function () { // Verify that this is called before the next tick called = true; }); - r.read(); + _r5.read(); process.nextTick(function () { assert.strictEqual(called, true); }); } { // Verify that adding readable listeners trigger data flow - const r = new R({ + var _r6 = new R({ highWaterMark: 5 }); - let onReadable = false; - let readCalled = 0; - r._read = function (n) { - if (readCalled++ === 2) r.push(null);else r.push(bufferShim.from('asdf')); + var onReadable = false; + var readCalled = 0; + _r6._read = function (n) { + if (readCalled++ === 2) _r6.push(null);else _r6.push(bufferShim.from('asdf')); }; - r.on('readable', function () { + _r6.on('readable', function () { onReadable = true; - r.read(); + _r6.read(); }); - r.on('end', common.mustCall(function () { + _r6.on('end', common.mustCall(function () { assert.strictEqual(readCalled, 3); assert.ok(onReadable); })); } { // Verify that streams are chainable - const r = new R(); - r._read = common.mustCall(); - const r2 = r.setEncoding('utf8').pause().resume().pause(); - assert.strictEqual(r, r2); + var _r7 = new R(); + _r7._read = common.mustCall(); + var r2 = _r7.setEncoding('utf8').pause().resume().pause(); + assert.strictEqual(_r7, r2); } function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { @@ -317,4 +350,6 @@ function forEach(xs, f) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-compatibility.js b/test/parallel/test-stream2-compatibility.js index cca05c718..e773d6727 100644 --- a/test/parallel/test-stream2-compatibility.js +++ b/test/parallel/test-stream2-compatibility.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,43 +34,61 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const R = require('../../lib/_stream_readable'); -const W = require('../../lib/_stream_writable'); -const assert = require('assert/'); -let ondataCalled = 0; -class TestReader extends R { - constructor() { - super(); - this._buffer = bufferShim.alloc(100, 'x'); - this.on('data', () => { +var R = require('../../lib/_stream_readable'); +var W = require('../../lib/_stream_writable'); +var assert = require('assert/'); +var ondataCalled = 0; +var TestReader = /*#__PURE__*/function (_R) { + _inherits(TestReader, _R); + var _super = _createSuper(TestReader); + function TestReader() { + var _this; + _classCallCheck(this, TestReader); + _this = _super.call(this); + _this._buffer = bufferShim.alloc(100, 'x'); + _this.on('data', function () { ondataCalled++; }); + return _this; } - _read(n) { - this.push(this._buffer); - this._buffer = bufferShim.alloc(0); - } -} -const reader = new TestReader(); + _createClass(TestReader, [{ + key: "_read", + value: function _read(n) { + this.push(this._buffer); + this._buffer = bufferShim.alloc(0); + } + }]); + return TestReader; +}(R); +var reader = new TestReader(); setImmediate(function () { assert.strictEqual(ondataCalled, 1); require('tap').pass(); reader.push(null); }); -class TestWriter extends W { - constructor() { - super(); - this.write('foo'); - this.end(); - } - _write(chunk, enc, cb) { - cb(); +var TestWriter = /*#__PURE__*/function (_W) { + _inherits(TestWriter, _W); + var _super2 = _createSuper(TestWriter); + function TestWriter() { + var _this2; + _classCallCheck(this, TestWriter); + _this2 = _super2.call(this); + _this2.write('foo'); + _this2.end(); + return _this2; } -} -const writer = new TestWriter(); + _createClass(TestWriter, [{ + key: "_write", + value: function _write(chunk, enc, cb) { + cb(); + } + }]); + return TestWriter; +}(W); +var writer = new TestWriter(); process.on('exit', function () { assert.strictEqual(reader.readable, false); assert.strictEqual(writer.writable, false); @@ -72,4 +102,6 @@ process.on('exit', function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-decode-partial.js b/test/parallel/test-stream2-decode-partial.js index 86f9962ff..776650c20 100644 --- a/test/parallel/test-stream2-decode-partial.js +++ b/test/parallel/test-stream2-decode-partial.js @@ -1,16 +1,16 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const Readable = require('../../lib/_stream_readable'); -const assert = require('assert/'); -let buf = ''; -const euro = bufferShim.from([0xE2, 0x82, 0xAC]); -const cent = bufferShim.from([0xC2, 0xA2]); -const source = Buffer.concat([euro, cent]); -const readable = Readable({ +var Readable = require('../../lib/_stream_readable'); +var assert = require('assert/'); +var buf = ''; +var euro = bufferShim.from([0xE2, 0x82, 0xAC]); +var cent = bufferShim.from([0xC2, 0xA2]); +var source = Buffer.concat([euro, cent]); +var readable = Readable({ encoding: 'utf8' }); readable.push(source.slice(0, 2)); @@ -32,4 +32,6 @@ process.on('exit', function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-finish-pipe.js b/test/parallel/test-stream2-finish-pipe.js index 253b627d0..6165242a9 100644 --- a/test/parallel/test-stream2-finish-pipe.js +++ b/test/parallel/test-stream2-finish-pipe.js @@ -22,15 +22,15 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const stream = require('../../'); -const r = new stream.Readable(); +var stream = require('../../'); +var r = new stream.Readable(); r._read = function (size) { r.push(bufferShim.allocUnsafe(size)); }; -const w = new stream.Writable(); +var w = new stream.Writable(); w._write = function (data, encoding, cb) { cb(null); }; @@ -48,4 +48,6 @@ w.end(); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-large-read-stall.js b/test/parallel/test-stream2-large-read-stall.js index e64f7d973..fbc0777a9 100644 --- a/test/parallel/test-stream2-large-read-stall.js +++ b/test/parallel/test-stream2-large-read-stall.js @@ -22,34 +22,34 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); +var common = require('../common'); +var assert = require('assert/'); // If everything aligns so that you do a read(n) of exactly the // remaining buffer, then make sure that 'end' still emits. -const READSIZE = 100; -const PUSHSIZE = 20; -const PUSHCOUNT = 1000; -const HWM = 50; -const Readable = require('../../').Readable; -const r = new Readable({ +var READSIZE = 100; +var PUSHSIZE = 20; +var PUSHCOUNT = 1000; +var HWM = 50; +var Readable = require('../../').Readable; +var r = new Readable({ highWaterMark: HWM }); -const rs = r._readableState; +var rs = r._readableState; r._read = push; r.on('readable', function () { ; false && console.error('>> readable'); - let ret; + var ret; do { ; - false && console.error(` > read(${READSIZE})`); + false && console.error(" > read(".concat(READSIZE, ")")); ret = r.read(READSIZE); ; - false && console.error(` < ${ret && ret.length} (${rs.length} remain)`); + false && console.error(" < ".concat(ret && ret.length, " (").concat(rs.length, " remain)")); } while (ret && ret.length === READSIZE); ; false && console.error('<< after read()', ret && ret.length, rs.needReadable, rs.length); @@ -57,7 +57,7 @@ r.on('readable', function () { r.on('end', common.mustCall(function () { assert.strictEqual(pushes, PUSHCOUNT + 1); })); -let pushes = 0; +var pushes = 0; function push() { if (pushes > PUSHCOUNT) return; if (pushes++ === PUSHCOUNT) { @@ -66,7 +66,7 @@ function push() { return r.push(null); } ; - false && console.error(` push #${pushes}`); + false && console.error(" push #".concat(pushes)); if (r.push(bufferShim.allocUnsafe(PUSHSIZE))) setTimeout(push, 1); } ; @@ -77,4 +77,6 @@ function push() { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-objects.js b/test/parallel/test-stream2-objects.js index 237f9aa25..c79d85809 100644 --- a/test/parallel/test-stream2-objects.js +++ b/test/parallel/test-stream2-objects.js @@ -22,18 +22,18 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const Readable = require('../../lib/_stream_readable'); -const Writable = require('../../lib/_stream_writable'); -const assert = require('assert/'); +var common = require('../common'); +var Readable = require('../../lib/_stream_readable'); +var Writable = require('../../lib/_stream_writable'); +var assert = require('assert/'); function toArray(callback) { - const stream = new Writable({ + var stream = new Writable({ objectMode: true }); - const list = []; + var list = []; stream.write = function (chunk) { list.push(chunk); }; @@ -43,7 +43,7 @@ function toArray(callback) { return stream; } function fromArray(list) { - const r = new Readable({ + var r = new Readable({ objectMode: true }); r._read = common.mustNotCall(); @@ -55,14 +55,14 @@ function fromArray(list) { } { // Verify that objects can be read from the stream - const r = fromArray([{ + var r = fromArray([{ one: '1' }, { two: '2' }]); - const v1 = r.read(); - const v2 = r.read(); - const v3 = r.read(); + var v1 = r.read(); + var v2 = r.read(); + var v3 = r.read(); assert.deepStrictEqual(v1, { one: '1' }); @@ -73,12 +73,12 @@ function fromArray(list) { } { // Verify that objects can be piped into the stream - const r = fromArray([{ + var _r = fromArray([{ one: '1' }, { two: '2' }]); - r.pipe(toArray(common.mustCall(function (list) { + _r.pipe(toArray(common.mustCall(function (list) { assert.deepStrictEqual(list, [{ one: '1' }, { @@ -88,31 +88,31 @@ function fromArray(list) { } { // Verify that read(n) is ignored - const r = fromArray([{ + var _r2 = fromArray([{ one: '1' }, { two: '2' }]); - const value = r.read(2); + var value = _r2.read(2); assert.deepStrictEqual(value, { one: '1' }); } { // Verify that objects can be synchronously read - const r = new Readable({ + var _r3 = new Readable({ objectMode: true }); - const list = [{ + var list = [{ one: '1' }, { two: '2' }]; - r._read = function (n) { - const item = list.shift(); - r.push(item || null); + _r3._read = function (n) { + var item = list.shift(); + _r3.push(item || null); }; - r.pipe(toArray(common.mustCall(function (list) { + _r3.pipe(toArray(common.mustCall(function (list) { assert.deepStrictEqual(list, [{ one: '1' }, { @@ -122,21 +122,21 @@ function fromArray(list) { } { // Verify that objects can be asynchronously read - const r = new Readable({ + var _r4 = new Readable({ objectMode: true }); - const list = [{ + var _list2 = [{ one: '1' }, { two: '2' }]; - r._read = function (n) { - const item = list.shift(); + _r4._read = function (n) { + var item = _list2.shift(); process.nextTick(function () { - r.push(item || null); + _r4.push(item || null); }); }; - r.pipe(toArray(common.mustCall(function (list) { + _r4.pipe(toArray(common.mustCall(function (list) { assert.deepStrictEqual(list, [{ one: '1' }, { @@ -146,83 +146,83 @@ function fromArray(list) { } { // Verify that strings can be read as objects - const r = new Readable({ + var _r5 = new Readable({ objectMode: true }); - r._read = common.mustNotCall(); - const list = ['one', 'two', 'three']; - forEach(list, function (str) { - r.push(str); + _r5._read = common.mustNotCall(); + var _list3 = ['one', 'two', 'three']; + forEach(_list3, function (str) { + _r5.push(str); }); - r.push(null); - r.pipe(toArray(common.mustCall(function (array) { - assert.deepStrictEqual(array, list); + _r5.push(null); + _r5.pipe(toArray(common.mustCall(function (array) { + assert.deepStrictEqual(array, _list3); }))); } { // Verify read(0) behavior for object streams - const r = new Readable({ + var _r6 = new Readable({ objectMode: true }); - r._read = common.mustNotCall(); - r.push('foobar'); - r.push(null); - r.pipe(toArray(common.mustCall(function (array) { + _r6._read = common.mustNotCall(); + _r6.push('foobar'); + _r6.push(null); + _r6.pipe(toArray(common.mustCall(function (array) { assert.deepStrictEqual(array, ['foobar']); }))); } { // Verify the behavior of pushing falsey values - const r = new Readable({ + var _r7 = new Readable({ objectMode: true }); - r._read = common.mustNotCall(); - r.push(false); - r.push(0); - r.push(''); - r.push(null); - r.pipe(toArray(common.mustCall(function (array) { + _r7._read = common.mustNotCall(); + _r7.push(false); + _r7.push(0); + _r7.push(''); + _r7.push(null); + _r7.pipe(toArray(common.mustCall(function (array) { assert.deepStrictEqual(array, [false, 0, '']); }))); } { // Verify high watermark _read() behavior - const r = new Readable({ + var _r8 = new Readable({ highWaterMark: 6, objectMode: true }); - let calls = 0; - const list = ['1', '2', '3', '4', '5', '6', '7', '8']; - r._read = function (n) { + var calls = 0; + var _list4 = ['1', '2', '3', '4', '5', '6', '7', '8']; + _r8._read = function (n) { calls++; }; - forEach(list, function (c) { - r.push(c); + forEach(_list4, function (c) { + _r8.push(c); }); - const v = r.read(); + var v = _r8.read(); assert.strictEqual(calls, 0); assert.strictEqual(v, '1'); - const v2 = r.read(); - assert.strictEqual(v2, '2'); - const v3 = r.read(); - assert.strictEqual(v3, '3'); + var _v = _r8.read(); + assert.strictEqual(_v, '2'); + var _v2 = _r8.read(); + assert.strictEqual(_v2, '3'); assert.strictEqual(calls, 1); } { // Verify high watermark push behavior - const r = new Readable({ + var _r9 = new Readable({ highWaterMark: 6, objectMode: true }); - r._read = common.mustNotCall(); - for (let i = 0; i < 6; i++) { - const bool = r.push(i); + _r9._read = common.mustNotCall(); + for (var i = 0; i < 6; i++) { + var bool = _r9.push(i); assert.strictEqual(bool, i !== 5); } } { // Verify that objects can be written to stream - const w = new Writable({ + var w = new Writable({ objectMode: true }); w._write = function (chunk, encoding, cb) { @@ -239,62 +239,62 @@ function fromArray(list) { } { // Verify that multiple objects can be written to stream - const w = new Writable({ + var _w = new Writable({ objectMode: true }); - const list = []; - w._write = function (chunk, encoding, cb) { - list.push(chunk); + var _list5 = []; + _w._write = function (chunk, encoding, cb) { + _list5.push(chunk); cb(); }; - w.on('finish', common.mustCall(function () { - assert.deepStrictEqual(list, [0, 1, 2, 3, 4]); + _w.on('finish', common.mustCall(function () { + assert.deepStrictEqual(_list5, [0, 1, 2, 3, 4]); })); - w.write(0); - w.write(1); - w.write(2); - w.write(3); - w.write(4); - w.end(); + _w.write(0); + _w.write(1); + _w.write(2); + _w.write(3); + _w.write(4); + _w.end(); } { // Verify that strings can be written as objects - const w = new Writable({ + var _w2 = new Writable({ objectMode: true }); - const list = []; - w._write = function (chunk, encoding, cb) { - list.push(chunk); + var _list6 = []; + _w2._write = function (chunk, encoding, cb) { + _list6.push(chunk); process.nextTick(cb); }; - w.on('finish', common.mustCall(function () { - assert.deepStrictEqual(list, ['0', '1', '2', '3', '4']); + _w2.on('finish', common.mustCall(function () { + assert.deepStrictEqual(_list6, ['0', '1', '2', '3', '4']); })); - w.write('0'); - w.write('1'); - w.write('2'); - w.write('3'); - w.write('4'); - w.end(); + _w2.write('0'); + _w2.write('1'); + _w2.write('2'); + _w2.write('3'); + _w2.write('4'); + _w2.end(); } { // Verify that stream buffers finish until callback is called - const w = new Writable({ + var _w3 = new Writable({ objectMode: true }); - let called = false; - w._write = function (chunk, encoding, cb) { + var called = false; + _w3._write = function (chunk, encoding, cb) { assert.strictEqual(chunk, 'foo'); process.nextTick(function () { called = true; cb(); }); }; - w.on('finish', common.mustCall(function () { + _w3.on('finish', common.mustCall(function () { assert.strictEqual(called, true); })); - w.write('foo'); - w.end(); + _w3.write('foo'); + _w3.end(); } function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { @@ -309,4 +309,6 @@ function forEach(xs, f) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-pipe-error-handling.js b/test/parallel/test-stream2-pipe-error-handling.js index 82c1d1cc8..f6db5cec0 100644 --- a/test/parallel/test-stream2-pipe-error-handling.js +++ b/test/parallel/test-stream2-pipe-error-handling.js @@ -22,75 +22,75 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); +var assert = require('assert/'); +var stream = require('../../'); { - let count = 1000; - const source = new stream.Readable(); + var count = 1000; + var source = new stream.Readable(); source._read = function (n) { n = Math.min(count, n); count -= n; source.push(bufferShim.allocUnsafe(n)); }; - let unpipedDest; + var unpipedDest; source.unpipe = function (dest) { unpipedDest = dest; stream.Readable.prototype.unpipe.call(this, dest); }; - const dest = new stream.Writable(); + var dest = new stream.Writable(); dest._write = function (chunk, encoding, cb) { cb(); }; source.pipe(dest); - let gotErr = null; + var gotErr = null; dest.on('error', function (err) { gotErr = err; }); - let unpipedSource; + var unpipedSource; dest.on('unpipe', function (src) { unpipedSource = src; }); - const err = new Error('This stream turned into bacon.'); + var err = new Error('This stream turned into bacon.'); dest.emit('error', err); assert.strictEqual(gotErr, err); assert.strictEqual(unpipedSource, source); assert.strictEqual(unpipedDest, dest); } { - let count = 1000; - const source = new stream.Readable(); - source._read = function (n) { - n = Math.min(count, n); - count -= n; - source.push(bufferShim.allocUnsafe(n)); + var _count = 1000; + var _source = new stream.Readable(); + _source._read = function (n) { + n = Math.min(_count, n); + _count -= n; + _source.push(bufferShim.allocUnsafe(n)); }; - let unpipedDest; - source.unpipe = function (dest) { - unpipedDest = dest; + var _unpipedDest; + _source.unpipe = function (dest) { + _unpipedDest = dest; stream.Readable.prototype.unpipe.call(this, dest); }; - const dest = new stream.Writable(); - dest._write = function (chunk, encoding, cb) { + var _dest = new stream.Writable(); + _dest._write = function (chunk, encoding, cb) { cb(); }; - source.pipe(dest); - let unpipedSource; - dest.on('unpipe', function (src) { - unpipedSource = src; + _source.pipe(_dest); + var _unpipedSource; + _dest.on('unpipe', function (src) { + _unpipedSource = src; }); - const err = new Error('This stream turned into bacon.'); - let gotErr = null; + var _err = new Error('This stream turned into bacon.'); + var _gotErr = null; try { - dest.emit('error', err); + _dest.emit('error', _err); } catch (e) { - gotErr = e; + _gotErr = e; } - assert.strictEqual(gotErr, err); - assert.strictEqual(unpipedSource, source); - assert.strictEqual(unpipedDest, dest); + assert.strictEqual(_gotErr, _err); + assert.strictEqual(_unpipedSource, _source); + assert.strictEqual(_unpipedDest, _dest); } ; (function () { @@ -100,4 +100,6 @@ const stream = require('../../'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-pipe-error-once-listener.js b/test/parallel/test-stream2-pipe-error-once-listener.js index ffd10e638..c4abbf637 100644 --- a/test/parallel/test-stream2-pipe-error-once-listener.js +++ b/test/parallel/test-stream2-pipe-error-once-listener.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,26 +34,46 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const stream = require('../../'); -class Read extends stream.Readable { - _read(size) { - this.push('x'); - this.push(null); +var stream = require('../../'); +var Read = /*#__PURE__*/function (_stream$Readable) { + _inherits(Read, _stream$Readable); + var _super = _createSuper(Read); + function Read() { + _classCallCheck(this, Read); + return _super.apply(this, arguments); } -} -class Write extends stream.Writable { - _write(buffer, encoding, cb) { - this.emit('error', new Error('boom')); - this.emit('alldone'); + _createClass(Read, [{ + key: "_read", + value: function _read(size) { + this.push('x'); + this.push(null); + } + }]); + return Read; +}(stream.Readable); +var Write = /*#__PURE__*/function (_stream$Writable) { + _inherits(Write, _stream$Writable); + var _super2 = _createSuper(Write); + function Write() { + _classCallCheck(this, Write); + return _super2.apply(this, arguments); } -} -const read = new Read(); -const write = new Write(); -write.once('error', () => {}); + _createClass(Write, [{ + key: "_write", + value: function _write(buffer, encoding, cb) { + this.emit('error', new Error('boom')); + this.emit('alldone'); + } + }]); + return Write; +}(stream.Writable); +var read = new Read(); +var write = new Write(); +write.once('error', function () {}); write.once('alldone', function (err) { require('tap').pass(); }); @@ -57,4 +89,6 @@ read.pipe(write); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-push.js b/test/parallel/test-stream2-push.js index fdff67e69..9fe85f75a 100644 --- a/test/parallel/test-stream2-push.js +++ b/test/parallel/test-stream2-push.js @@ -22,39 +22,39 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const _require = require('../../'), +var assert = require('assert/'); +var _require = require('../../'), Readable = _require.Readable, Writable = _require.Writable; -const EE = require('events').EventEmitter; +var EE = require('events').EventEmitter; // a mock thing a bit like the net.Socket/tcp_wrap.handle interaction -const stream = new Readable({ +var stream = new Readable({ highWaterMark: 16, encoding: 'utf8' }); -const source = new EE(); +var source = new EE(); stream._read = function () { console.error('stream._read'); readStart(); }; -let ended = false; +var ended = false; stream.on('end', function () { ended = true; }); source.on('data', function (chunk) { - const ret = stream.push(chunk); + var ret = stream.push(chunk); console.error('data', stream.readableLength); if (!ret) readStop(); }); source.on('end', function () { stream.push(null); }); -let reading = false; +var reading = false; function readStart() { console.error('readStart'); reading = true; @@ -63,17 +63,17 @@ function readStop() { console.error('readStop'); reading = false; process.nextTick(function () { - const r = stream.read(); + var r = stream.read(); if (r !== null) writer.write(r); }); } -const writer = new Writable({ +var writer = new Writable({ decodeStrings: false }); -const written = []; -const expectWritten = ['asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg']; +var written = []; +var expectWritten = ['asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg']; writer._write = function (chunk, encoding, cb) { - console.error(`WRITE ${chunk}`); + console.error("WRITE ".concat(chunk)); written.push(chunk); process.nextTick(cb); }; @@ -81,8 +81,8 @@ writer.on('finish', finish); // now emit some chunks. -const chunk = 'asdfg'; -let set = 0; +var chunk = 'asdfg'; +var set = 0; readStart(); data(); function data() { @@ -118,4 +118,6 @@ function end() { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-read-sync-stack.js b/test/parallel/test-stream2-read-sync-stack.js index e48a9e7b0..f16f9394f 100644 --- a/test/parallel/test-stream2-read-sync-stack.js +++ b/test/parallel/test-stream2-read-sync-stack.js @@ -22,19 +22,19 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const Readable = require('../../').Readable; +var common = require('../common'); +var Readable = require('../../').Readable; // This tests synchronous read callbacks and verifies that even if they nest // heavily the process handles it without an error -const r = new Readable(); -const N = 256 * 1024; -let reads = 0; +var r = new Readable(); +var N = 256 * 1024; +var reads = 0; r._read = function (n) { - const chunk = reads++ === N ? null : bufferShim.allocUnsafe(1); + var chunk = reads++ === N ? null : bufferShim.allocUnsafe(1); r.push(chunk); }; r.on('readable', function onReadable() { @@ -51,4 +51,6 @@ r.read(0); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-readable-empty-buffer-no-eof.js b/test/parallel/test-stream2-readable-empty-buffer-no-eof.js index 7457c26f3..5d5c4e621 100644 --- a/test/parallel/test-stream2-readable-empty-buffer-no-eof.js +++ b/test/parallel/test-stream2-readable-empty-buffer-no-eof.js @@ -22,15 +22,15 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const Readable = require('../../').Readable; +var assert = require('assert/'); +var Readable = require('../../').Readable; test1(); test2(); function test1() { - const r = new Readable(); + var r = new Readable(); // should not end when we get a bufferShim.alloc(0) or '' as the _read // result that just means that there is *temporarily* no data, but to @@ -42,22 +42,22 @@ function test1() { // r.read(0) again later, otherwise there is no more work being done // and the process just exits. - const buf = bufferShim.alloc(5, 'x'); - let reads = 5; + var buf = bufferShim.alloc(5, 'x'); + var reads = 5; r._read = function (n) { switch (reads--) { case 5: - return setImmediate(() => { + return setImmediate(function () { return r.push(buf); }); case 4: - setImmediate(() => { + setImmediate(function () { return r.push(bufferShim.alloc(0)); }); return setImmediate(r.read.bind(r, 0)); case 3: setTimeout(r.read.bind(r, 0), 50); - return process.nextTick(() => { + return process.nextTick(function () { return r.push(bufferShim.alloc(0)); }); case 2: @@ -73,41 +73,41 @@ function test1() { throw new Error('unreachable'); } }; - const results = []; + var results = []; function flow() { - let chunk; + var chunk; while (null !== (chunk = r.read())) results.push(String(chunk)); } r.on('readable', flow); - r.on('end', () => { + r.on('end', function () { results.push('EOF'); }); flow(); - process.on('exit', () => { + process.on('exit', function () { assert.deepStrictEqual(results, ['xxxxx', 'xxxxx', 'EOF']); require('tap').pass(); }); } function test2() { - const r = new Readable({ + var r = new Readable({ encoding: 'base64' }); - let reads = 5; + var reads = 5; r._read = function (n) { if (!reads--) return r.push(null); // EOF else return r.push(bufferShim.from('x')); }; - const results = []; + var results = []; function flow() { - let chunk; + var chunk; while (null !== (chunk = r.read())) results.push(String(chunk)); } r.on('readable', flow); - r.on('end', () => { + r.on('end', function () { results.push('EOF'); }); flow(); - process.on('exit', () => { + process.on('exit', function () { assert.deepStrictEqual(results, ['eHh4', 'eHg=', 'EOF']); require('tap').pass(); }); @@ -120,4 +120,6 @@ function test2() { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-readable-from-list.js b/test/parallel/test-stream2-readable-from-list.js index a62c53f1e..f44511af4 100644 --- a/test/parallel/test-stream2-readable-from-list.js +++ b/test/parallel/test-stream2-readable-from-list.js @@ -22,28 +22,28 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const fromList = require('../../lib/_stream_readable')._fromList; -const BufferList = require('../../lib/internal/streams/buffer_list'); -const util = require('util'); +var assert = require('assert/'); +var fromList = require('../../lib/_stream_readable')._fromList; +var BufferList = require('../../lib/internal/streams/buffer_list'); +var util = require('util'); function bufferListFromArray(arr) { - const bl = new BufferList(); - for (let i = 0; i < arr.length; ++i) bl.push(arr[i]); + var bl = new BufferList(); + for (var i = 0; i < arr.length; ++i) bl.push(arr[i]); return bl; } { // Verify behavior with buffers - let list = [bufferShim.from('foog'), bufferShim.from('bark'), bufferShim.from('bazy'), bufferShim.from('kuel')]; + var list = [bufferShim.from('foog'), bufferShim.from('bark'), bufferShim.from('bazy'), bufferShim.from('kuel')]; list = bufferListFromArray(list); assert.strictEqual(util.inspect([list], { compact: false }).indexOf('BufferList') > 0, true); // read more than the first element. - let ret = fromList(6, { + var ret = fromList(6, { buffer: list, length: 16 }); @@ -75,43 +75,43 @@ function bufferListFromArray(arr) { } { // Verify behavior with strings - let list = ['foog', 'bark', 'bazy', 'kuel']; - list = bufferListFromArray(list); + var _list2 = ['foog', 'bark', 'bazy', 'kuel']; + _list2 = bufferListFromArray(_list2); // read more than the first element. - let ret = fromList(6, { - buffer: list, + var _ret = fromList(6, { + buffer: _list2, length: 16, decoder: true }); - assert.strictEqual(ret, 'foogba'); + assert.strictEqual(_ret, 'foogba'); // read exactly the first element. - ret = fromList(2, { - buffer: list, + _ret = fromList(2, { + buffer: _list2, length: 10, decoder: true }); - assert.strictEqual(ret, 'rk'); + assert.strictEqual(_ret, 'rk'); // read less than the first element. - ret = fromList(2, { - buffer: list, + _ret = fromList(2, { + buffer: _list2, length: 8, decoder: true }); - assert.strictEqual(ret, 'ba'); + assert.strictEqual(_ret, 'ba'); // read more than we have. - ret = fromList(100, { - buffer: list, + _ret = fromList(100, { + buffer: _list2, length: 6, decoder: true }); - assert.strictEqual(ret, 'zykuel'); + assert.strictEqual(_ret, 'zykuel'); // all consumed. - assert.deepStrictEqual(list, new BufferList()); + assert.deepStrictEqual(_list2, new BufferList()); } ; (function () { @@ -121,4 +121,6 @@ function bufferListFromArray(arr) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-readable-legacy-drain.js b/test/parallel/test-stream2-readable-legacy-drain.js index 5f5f020bc..53eac68ea 100644 --- a/test/parallel/test-stream2-readable-legacy-drain.js +++ b/test/parallel/test-stream2-readable-legacy-drain.js @@ -22,22 +22,22 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Stream = require('../../'); -const Readable = require('../../').Readable; -const r = new Readable(); -const N = 256; -let reads = 0; +var common = require('../common'); +var assert = require('assert/'); +var Stream = require('../../'); +var Readable = require('../../').Readable; +var r = new Readable(); +var N = 256; +var reads = 0; r._read = function (n) { return r.push(++reads === N ? null : bufferShim.allocUnsafe(1)); }; r.on('end', common.mustCall()); -const w = new Stream(); +var w = new Stream(); w.writable = true; -let buffered = 0; +var buffered = 0; w.write = function (c) { buffered += c.length; process.nextTick(drain); @@ -65,4 +65,6 @@ r.pipe(w); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-readable-non-empty-end.js b/test/parallel/test-stream2-readable-non-empty-end.js index 1d33ff2dd..d0e753d0b 100644 --- a/test/parallel/test-stream2-readable-non-empty-end.js +++ b/test/parallel/test-stream2-readable-non-empty-end.js @@ -22,21 +22,21 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const Readable = require('../../lib/_stream_readable'); -let len = 0; -const chunks = new Array(10); -for (let i = 1; i <= 10; i++) { +var common = require('../common'); +var assert = require('assert/'); +var Readable = require('../../lib/_stream_readable'); +var len = 0; +var chunks = new Array(10); +for (var i = 1; i <= 10; i++) { chunks[i - 1] = bufferShim.allocUnsafe(i); len += i; } -const test = new Readable(); -let n = 0; +var test = new Readable(); +var n = 0; test._read = function (size) { - const chunk = chunks[n++]; + var chunk = chunks[n++]; setTimeout(function () { test.push(chunk === undefined ? null : chunk); }, 1); @@ -45,13 +45,13 @@ test.on('end', thrower); function thrower() { throw new Error('this should not happen!'); } -let bytesread = 0; +var bytesread = 0; test.on('readable', function () { - const b = len - bytesread - 1; - const res = test.read(b); + var b = len - bytesread - 1; + var res = test.read(b); if (res) { bytesread += res.length; - console.error(`br=${bytesread} len=${len}`); + console.error("br=".concat(bytesread, " len=").concat(len)); setTimeout(next, 1); } test.read(0); @@ -63,7 +63,7 @@ function next() { test.on('end', common.mustCall()); // one to get the last byte - let r = test.read(); + var r = test.read(); assert(r); assert.strictEqual(r.length, 1); r = test.read(); @@ -77,4 +77,6 @@ function next() { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-readable-wrap-empty.js b/test/parallel/test-stream2-readable-wrap-empty.js index 16edb4b76..ee59ad728 100644 --- a/test/parallel/test-stream2-readable-wrap-empty.js +++ b/test/parallel/test-stream2-readable-wrap-empty.js @@ -22,16 +22,16 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const Readable = require('../../lib/_stream_readable'); -const EE = require('events').EventEmitter; -const oldStream = new EE(); -oldStream.pause = () => {}; -oldStream.resume = () => {}; -const newStream = new Readable().wrap(oldStream); -newStream.on('readable', () => {}).on('end', common.mustCall()); +var common = require('../common'); +var Readable = require('../../lib/_stream_readable'); +var EE = require('events').EventEmitter; +var oldStream = new EE(); +oldStream.pause = function () {}; +oldStream.resume = function () {}; +var newStream = new Readable().wrap(oldStream); +newStream.on('readable', function () {}).on('end', common.mustCall()); oldStream.emit('end'); ; (function () { @@ -41,4 +41,6 @@ oldStream.emit('end'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-set-encoding.js b/test/parallel/test-stream2-set-encoding.js index 1eb5a8924..1970f8a3d 100644 --- a/test/parallel/test-stream2-set-encoding.js +++ b/test/parallel/test-stream2-set-encoding.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,44 +34,54 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const R = require('../../lib/_stream_readable'); -class TestReader extends R { - constructor(n, opts) { - super(opts); - this.pos = 0; - this.len = n || 100; +var common = require('../common'); +var assert = require('assert/'); +var R = require('../../lib/_stream_readable'); +var TestReader = /*#__PURE__*/function (_R) { + _inherits(TestReader, _R); + var _super = _createSuper(TestReader); + function TestReader(n, opts) { + var _this; + _classCallCheck(this, TestReader); + _this = _super.call(this, opts); + _this.pos = 0; + _this.len = n || 100; + return _this; } - _read(n) { - setTimeout(() => { - if (this.pos >= this.len) { - // double push(null) to test eos handling - this.push(null); - return this.push(null); - } - n = Math.min(n, this.len - this.pos); - if (n <= 0) { - // double push(null) to test eos handling - this.push(null); - return this.push(null); - } - this.pos += n; - const ret = bufferShim.alloc(n, 'a'); - return this.push(ret); - }, 1); - } -} + _createClass(TestReader, [{ + key: "_read", + value: function _read(n) { + var _this2 = this; + setTimeout(function () { + if (_this2.pos >= _this2.len) { + // double push(null) to test eos handling + _this2.push(null); + return _this2.push(null); + } + n = Math.min(n, _this2.len - _this2.pos); + if (n <= 0) { + // double push(null) to test eos handling + _this2.push(null); + return _this2.push(null); + } + _this2.pos += n; + var ret = bufferShim.alloc(n, 'a'); + return _this2.push(ret); + }, 1); + } + }]); + return TestReader; +}(R); { // Verify utf8 encoding - const tr = new TestReader(100); + var tr = new TestReader(100); tr.setEncoding('utf8'); - const out = []; - const expect = ['aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa']; + var out = []; + var expect = ['aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa']; tr.on('readable', function flow() { - let chunk; + var chunk; while (null !== (chunk = tr.read(10))) out.push(chunk); }); tr.on('end', common.mustCall(function () { @@ -68,110 +90,110 @@ class TestReader extends R { } { // Verify hex encoding - const tr = new TestReader(100); - tr.setEncoding('hex'); - const out = []; - const expect = ['6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161']; - tr.on('readable', function flow() { - let chunk; - while (null !== (chunk = tr.read(10))) out.push(chunk); + var _tr = new TestReader(100); + _tr.setEncoding('hex'); + var _out = []; + var _expect = ['6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161']; + _tr.on('readable', function flow() { + var chunk; + while (null !== (chunk = _tr.read(10))) _out.push(chunk); }); - tr.on('end', common.mustCall(function () { - assert.deepStrictEqual(out, expect); + _tr.on('end', common.mustCall(function () { + assert.deepStrictEqual(_out, _expect); })); } { // Verify hex encoding with read(13) - const tr = new TestReader(100); - tr.setEncoding('hex'); - const out = []; - const expect = ['6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '16161']; - tr.on('readable', function flow() { - let chunk; - while (null !== (chunk = tr.read(13))) out.push(chunk); + var _tr2 = new TestReader(100); + _tr2.setEncoding('hex'); + var _out2 = []; + var _expect2 = ['6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '16161']; + _tr2.on('readable', function flow() { + var chunk; + while (null !== (chunk = _tr2.read(13))) _out2.push(chunk); }); - tr.on('end', common.mustCall(function () { - assert.deepStrictEqual(out, expect); + _tr2.on('end', common.mustCall(function () { + assert.deepStrictEqual(_out2, _expect2); })); } { // Verify base64 encoding - const tr = new TestReader(100); - tr.setEncoding('base64'); - const out = []; - const expect = ['YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYQ==']; - tr.on('readable', function flow() { - let chunk; - while (null !== (chunk = tr.read(10))) out.push(chunk); + var _tr3 = new TestReader(100); + _tr3.setEncoding('base64'); + var _out3 = []; + var _expect3 = ['YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYQ==']; + _tr3.on('readable', function flow() { + var chunk; + while (null !== (chunk = _tr3.read(10))) _out3.push(chunk); }); - tr.on('end', common.mustCall(function () { - assert.deepStrictEqual(out, expect); + _tr3.on('end', common.mustCall(function () { + assert.deepStrictEqual(_out3, _expect3); })); } { // Verify utf8 encoding - const tr = new TestReader(100, { + var _tr4 = new TestReader(100, { encoding: 'utf8' }); - const out = []; - const expect = ['aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa']; - tr.on('readable', function flow() { - let chunk; - while (null !== (chunk = tr.read(10))) out.push(chunk); + var _out4 = []; + var _expect4 = ['aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa']; + _tr4.on('readable', function flow() { + var chunk; + while (null !== (chunk = _tr4.read(10))) _out4.push(chunk); }); - tr.on('end', common.mustCall(function () { - assert.deepStrictEqual(out, expect); + _tr4.on('end', common.mustCall(function () { + assert.deepStrictEqual(_out4, _expect4); })); } { // Verify hex encoding - const tr = new TestReader(100, { + var _tr5 = new TestReader(100, { encoding: 'hex' }); - const out = []; - const expect = ['6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161']; - tr.on('readable', function flow() { - let chunk; - while (null !== (chunk = tr.read(10))) out.push(chunk); + var _out5 = []; + var _expect5 = ['6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161', '6161616161']; + _tr5.on('readable', function flow() { + var chunk; + while (null !== (chunk = _tr5.read(10))) _out5.push(chunk); }); - tr.on('end', common.mustCall(function () { - assert.deepStrictEqual(out, expect); + _tr5.on('end', common.mustCall(function () { + assert.deepStrictEqual(_out5, _expect5); })); } { // Verify hex encoding with read(13) - const tr = new TestReader(100, { + var _tr6 = new TestReader(100, { encoding: 'hex' }); - const out = []; - const expect = ['6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '16161']; - tr.on('readable', function flow() { - let chunk; - while (null !== (chunk = tr.read(13))) out.push(chunk); + var _out6 = []; + var _expect6 = ['6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '1616161616161', '6161616161616', '16161']; + _tr6.on('readable', function flow() { + var chunk; + while (null !== (chunk = _tr6.read(13))) _out6.push(chunk); }); - tr.on('end', common.mustCall(function () { - assert.deepStrictEqual(out, expect); + _tr6.on('end', common.mustCall(function () { + assert.deepStrictEqual(_out6, _expect6); })); } { // Verify base64 encoding - const tr = new TestReader(100, { + var _tr7 = new TestReader(100, { encoding: 'base64' }); - const out = []; - const expect = ['YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYQ==']; - tr.on('readable', function flow() { - let chunk; - while (null !== (chunk = tr.read(10))) out.push(chunk); + var _out7 = []; + var _expect7 = ['YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', 'FhYQ==']; + _tr7.on('readable', function flow() { + var chunk; + while (null !== (chunk = _tr7.read(10))) _out7.push(chunk); }); - tr.on('end', common.mustCall(function () { - assert.deepStrictEqual(out, expect); + _tr7.on('end', common.mustCall(function () { + assert.deepStrictEqual(_out7, _expect7); })); } { // Verify chaining behavior - const tr = new TestReader(100); - assert.deepStrictEqual(tr.setEncoding('utf8'), tr); + var _tr8 = new TestReader(100); + assert.deepStrictEqual(_tr8.setEncoding('utf8'), _tr8); } ; (function () { @@ -181,4 +203,6 @@ class TestReader extends R { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-transform.js b/test/parallel/test-stream2-transform.js index ba7112319..d0c85f84d 100644 --- a/test/parallel/test-stream2-transform.js +++ b/test/parallel/test-stream2-transform.js @@ -22,24 +22,24 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const PassThrough = require('../../lib/_stream_passthrough'); -const Transform = require('../../lib/_stream_transform'); +var common = require('../common'); +var assert = require('assert/'); +var PassThrough = require('../../lib/_stream_passthrough'); +var Transform = require('../../lib/_stream_transform'); { // Verify writable side consumption - const tx = new Transform({ + var tx = new Transform({ highWaterMark: 10 }); - let transformed = 0; + var transformed = 0; tx._transform = function (chunk, encoding, cb) { transformed += chunk.length; tx.push(chunk); cb(); }; - for (let i = 1; i <= 10; i++) { + for (var i = 1; i <= 10; i++) { tx.write(bufferShim.allocUnsafe(i)); } tx.end(); @@ -52,7 +52,7 @@ const Transform = require('../../lib/_stream_transform'); } { // Verify passthrough behavior - const pt = new PassThrough(); + var pt = new PassThrough(); pt.write(bufferShim.from('foog')); pt.write(bufferShim.from('bark')); pt.write(bufferShim.from('bazy')); @@ -65,180 +65,181 @@ const Transform = require('../../lib/_stream_transform'); } { // Verify object passthrough behavior - const pt = new PassThrough({ + var _pt = new PassThrough({ objectMode: true }); - pt.write(1); - pt.write(true); - pt.write(false); - pt.write(0); - pt.write('foo'); - pt.write(''); - pt.write({ + _pt.write(1); + _pt.write(true); + _pt.write(false); + _pt.write(0); + _pt.write('foo'); + _pt.write(''); + _pt.write({ a: 'b' }); - pt.end(); - assert.strictEqual(pt.read(), 1); - assert.strictEqual(pt.read(), true); - assert.strictEqual(pt.read(), false); - assert.strictEqual(pt.read(), 0); - assert.strictEqual(pt.read(), 'foo'); - assert.strictEqual(pt.read(), ''); - assert.deepStrictEqual(pt.read(), { + _pt.end(); + assert.strictEqual(_pt.read(), 1); + assert.strictEqual(_pt.read(), true); + assert.strictEqual(_pt.read(), false); + assert.strictEqual(_pt.read(), 0); + assert.strictEqual(_pt.read(), 'foo'); + assert.strictEqual(_pt.read(), ''); + assert.deepStrictEqual(_pt.read(), { a: 'b' }); } { // Verify passthrough constructor behavior - const pt = PassThrough(); - assert(pt instanceof PassThrough); + var _pt2 = PassThrough(); + assert(_pt2 instanceof PassThrough); } { // Verify transform constructor behavior - const pt = Transform(); - assert(pt instanceof Transform); + var _pt3 = Transform(); + assert(_pt3 instanceof Transform); } { // Perform a simple transform - const pt = new Transform(); - pt._transform = function (c, e, cb) { - const ret = bufferShim.alloc(c.length, 'x'); - pt.push(ret); + var _pt4 = new Transform(); + _pt4._transform = function (c, e, cb) { + var ret = bufferShim.alloc(c.length, 'x'); + _pt4.push(ret); cb(); }; - pt.write(bufferShim.from('foog')); - pt.write(bufferShim.from('bark')); - pt.write(bufferShim.from('bazy')); - pt.write(bufferShim.from('kuel')); - pt.end(); - assert.strictEqual(pt.read(5).toString(), 'xxxxx'); - assert.strictEqual(pt.read(5).toString(), 'xxxxx'); - assert.strictEqual(pt.read(5).toString(), 'xxxxx'); - assert.strictEqual(pt.read(5).toString(), 'x'); + _pt4.write(bufferShim.from('foog')); + _pt4.write(bufferShim.from('bark')); + _pt4.write(bufferShim.from('bazy')); + _pt4.write(bufferShim.from('kuel')); + _pt4.end(); + assert.strictEqual(_pt4.read(5).toString(), 'xxxxx'); + assert.strictEqual(_pt4.read(5).toString(), 'xxxxx'); + assert.strictEqual(_pt4.read(5).toString(), 'xxxxx'); + assert.strictEqual(_pt4.read(5).toString(), 'x'); } { // Verify simple object transform - const pt = new Transform({ + var _pt5 = new Transform({ objectMode: true }); - pt._transform = function (c, e, cb) { - pt.push(JSON.stringify(c)); + _pt5._transform = function (c, e, cb) { + _pt5.push(JSON.stringify(c)); cb(); }; - pt.write(1); - pt.write(true); - pt.write(false); - pt.write(0); - pt.write('foo'); - pt.write(''); - pt.write({ + _pt5.write(1); + _pt5.write(true); + _pt5.write(false); + _pt5.write(0); + _pt5.write('foo'); + _pt5.write(''); + _pt5.write({ a: 'b' }); - pt.end(); - assert.strictEqual(pt.read(), '1'); - assert.strictEqual(pt.read(), 'true'); - assert.strictEqual(pt.read(), 'false'); - assert.strictEqual(pt.read(), '0'); - assert.strictEqual(pt.read(), '"foo"'); - assert.strictEqual(pt.read(), '""'); - assert.strictEqual(pt.read(), '{"a":"b"}'); + _pt5.end(); + assert.strictEqual(_pt5.read(), '1'); + assert.strictEqual(_pt5.read(), 'true'); + assert.strictEqual(_pt5.read(), 'false'); + assert.strictEqual(_pt5.read(), '0'); + assert.strictEqual(_pt5.read(), '"foo"'); + assert.strictEqual(_pt5.read(), '""'); + assert.strictEqual(_pt5.read(), '{"a":"b"}'); } { // Verify async passthrough - const pt = new Transform(); - pt._transform = function (chunk, encoding, cb) { + var _pt6 = new Transform(); + _pt6._transform = function (chunk, encoding, cb) { setTimeout(function () { - pt.push(chunk); + _pt6.push(chunk); cb(); }, 10); }; - pt.write(bufferShim.from('foog')); - pt.write(bufferShim.from('bark')); - pt.write(bufferShim.from('bazy')); - pt.write(bufferShim.from('kuel')); - pt.end(); - pt.on('finish', common.mustCall(function () { - assert.strictEqual(pt.read(5).toString(), 'foogb'); - assert.strictEqual(pt.read(5).toString(), 'arkba'); - assert.strictEqual(pt.read(5).toString(), 'zykue'); - assert.strictEqual(pt.read(5).toString(), 'l'); + _pt6.write(bufferShim.from('foog')); + _pt6.write(bufferShim.from('bark')); + _pt6.write(bufferShim.from('bazy')); + _pt6.write(bufferShim.from('kuel')); + _pt6.end(); + _pt6.on('finish', common.mustCall(function () { + assert.strictEqual(_pt6.read(5).toString(), 'foogb'); + assert.strictEqual(_pt6.read(5).toString(), 'arkba'); + assert.strictEqual(_pt6.read(5).toString(), 'zykue'); + assert.strictEqual(_pt6.read(5).toString(), 'l'); })); } { // Verify asymmetric transform (expand) - const pt = new Transform(); + var _pt7 = new Transform(); // emit each chunk 2 times. - pt._transform = function (chunk, encoding, cb) { + _pt7._transform = function (chunk, encoding, cb) { setTimeout(function () { - pt.push(chunk); + _pt7.push(chunk); setTimeout(function () { - pt.push(chunk); + _pt7.push(chunk); cb(); }, 10); }, 10); }; - pt.write(bufferShim.from('foog')); - pt.write(bufferShim.from('bark')); - pt.write(bufferShim.from('bazy')); - pt.write(bufferShim.from('kuel')); - pt.end(); - pt.on('finish', common.mustCall(function () { - assert.strictEqual(pt.read(5).toString(), 'foogf'); - assert.strictEqual(pt.read(5).toString(), 'oogba'); - assert.strictEqual(pt.read(5).toString(), 'rkbar'); - assert.strictEqual(pt.read(5).toString(), 'kbazy'); - assert.strictEqual(pt.read(5).toString(), 'bazyk'); - assert.strictEqual(pt.read(5).toString(), 'uelku'); - assert.strictEqual(pt.read(5).toString(), 'el'); + _pt7.write(bufferShim.from('foog')); + _pt7.write(bufferShim.from('bark')); + _pt7.write(bufferShim.from('bazy')); + _pt7.write(bufferShim.from('kuel')); + _pt7.end(); + _pt7.on('finish', common.mustCall(function () { + assert.strictEqual(_pt7.read(5).toString(), 'foogf'); + assert.strictEqual(_pt7.read(5).toString(), 'oogba'); + assert.strictEqual(_pt7.read(5).toString(), 'rkbar'); + assert.strictEqual(_pt7.read(5).toString(), 'kbazy'); + assert.strictEqual(_pt7.read(5).toString(), 'bazyk'); + assert.strictEqual(_pt7.read(5).toString(), 'uelku'); + assert.strictEqual(_pt7.read(5).toString(), 'el'); })); } { // Verify asymmetric transform (compress) - const pt = new Transform(); + var _pt8 = new Transform(); // each output is the first char of 3 consecutive chunks, // or whatever's left. - pt.state = ''; - pt._transform = function (chunk, encoding, cb) { + _pt8.state = ''; + _pt8._transform = function (chunk, encoding, cb) { + var _this = this; if (!chunk) chunk = ''; - const s = chunk.toString(); - setTimeout(() => { - this.state += s.charAt(0); - if (this.state.length === 3) { - pt.push(bufferShim.from(this.state)); - this.state = ''; + var s = chunk.toString(); + setTimeout(function () { + _this.state += s.charAt(0); + if (_this.state.length === 3) { + _pt8.push(bufferShim.from(_this.state)); + _this.state = ''; } cb(); }, 10); }; - pt._flush = function (cb) { + _pt8._flush = function (cb) { // just output whatever we have. - pt.push(bufferShim.from(this.state)); + _pt8.push(bufferShim.from(this.state)); this.state = ''; cb(); }; - pt.write(bufferShim.from('aaaa')); - pt.write(bufferShim.from('bbbb')); - pt.write(bufferShim.from('cccc')); - pt.write(bufferShim.from('dddd')); - pt.write(bufferShim.from('eeee')); - pt.write(bufferShim.from('aaaa')); - pt.write(bufferShim.from('bbbb')); - pt.write(bufferShim.from('cccc')); - pt.write(bufferShim.from('dddd')); - pt.write(bufferShim.from('eeee')); - pt.write(bufferShim.from('aaaa')); - pt.write(bufferShim.from('bbbb')); - pt.write(bufferShim.from('cccc')); - pt.write(bufferShim.from('dddd')); - pt.end(); + _pt8.write(bufferShim.from('aaaa')); + _pt8.write(bufferShim.from('bbbb')); + _pt8.write(bufferShim.from('cccc')); + _pt8.write(bufferShim.from('dddd')); + _pt8.write(bufferShim.from('eeee')); + _pt8.write(bufferShim.from('aaaa')); + _pt8.write(bufferShim.from('bbbb')); + _pt8.write(bufferShim.from('cccc')); + _pt8.write(bufferShim.from('dddd')); + _pt8.write(bufferShim.from('eeee')); + _pt8.write(bufferShim.from('aaaa')); + _pt8.write(bufferShim.from('bbbb')); + _pt8.write(bufferShim.from('cccc')); + _pt8.write(bufferShim.from('dddd')); + _pt8.end(); // 'abcdeabcdeabcd' - pt.on('finish', common.mustCall(function () { - assert.strictEqual(pt.read(5).toString(), 'abcde'); - assert.strictEqual(pt.read(5).toString(), 'abcde'); - assert.strictEqual(pt.read(5).toString(), 'abcd'); + _pt8.on('finish', common.mustCall(function () { + assert.strictEqual(_pt8.read(5).toString(), 'abcde'); + assert.strictEqual(_pt8.read(5).toString(), 'abcde'); + assert.strictEqual(_pt8.read(5).toString(), 'abcd'); })); } @@ -246,106 +247,106 @@ const Transform = require('../../lib/_stream_transform'); // that has empty transforms. { // Verify complex transform behavior - let count = 0; - let saved = null; - const pt = new Transform({ + var count = 0; + var saved = null; + var _pt9 = new Transform({ highWaterMark: 3 }); - pt._transform = function (c, e, cb) { + _pt9._transform = function (c, e, cb) { if (count++ === 1) saved = c;else { if (saved) { - pt.push(saved); + _pt9.push(saved); saved = null; } - pt.push(c); + _pt9.push(c); } cb(); }; - pt.once('readable', function () { + _pt9.once('readable', function () { process.nextTick(function () { - pt.write(bufferShim.from('d')); - pt.write(bufferShim.from('ef'), common.mustCall(function () { - pt.end(); + _pt9.write(bufferShim.from('d')); + _pt9.write(bufferShim.from('ef'), common.mustCall(function () { + _pt9.end(); })); - assert.strictEqual(pt.read().toString(), 'abcdef'); - assert.strictEqual(pt.read(), null); + assert.strictEqual(_pt9.read().toString(), 'abcdef'); + assert.strictEqual(_pt9.read(), null); }); }); - pt.write(bufferShim.from('abc')); + _pt9.write(bufferShim.from('abc')); } { // Verify passthrough event emission - const pt = new PassThrough(); - let emits = 0; - pt.on('readable', function () { + var _pt10 = new PassThrough(); + var emits = 0; + _pt10.on('readable', function () { emits++; }); - pt.write(bufferShim.from('foog')); - pt.write(bufferShim.from('bark')); + _pt10.write(bufferShim.from('foog')); + _pt10.write(bufferShim.from('bark')); assert.strictEqual(emits, 0); - assert.strictEqual(pt.read(5).toString(), 'foogb'); - assert.strictEqual(String(pt.read(5)), 'null'); + assert.strictEqual(_pt10.read(5).toString(), 'foogb'); + assert.strictEqual(String(_pt10.read(5)), 'null'); assert.strictEqual(emits, 0); - pt.write(bufferShim.from('bazy')); - pt.write(bufferShim.from('kuel')); + _pt10.write(bufferShim.from('bazy')); + _pt10.write(bufferShim.from('kuel')); assert.strictEqual(emits, 0); - assert.strictEqual(pt.read(5).toString(), 'arkba'); - assert.strictEqual(pt.read(5).toString(), 'zykue'); - assert.strictEqual(pt.read(5), null); - pt.end(); + assert.strictEqual(_pt10.read(5).toString(), 'arkba'); + assert.strictEqual(_pt10.read(5).toString(), 'zykue'); + assert.strictEqual(_pt10.read(5), null); + _pt10.end(); assert.strictEqual(emits, 1); - assert.strictEqual(pt.read(5).toString(), 'l'); - assert.strictEqual(pt.read(5), null); + assert.strictEqual(_pt10.read(5).toString(), 'l'); + assert.strictEqual(_pt10.read(5), null); assert.strictEqual(emits, 1); } { // Verify passthrough event emission reordering - const pt = new PassThrough(); - let emits = 0; - pt.on('readable', function () { - emits++; + var _pt11 = new PassThrough(); + var _emits = 0; + _pt11.on('readable', function () { + _emits++; }); - pt.write(bufferShim.from('foog')); - pt.write(bufferShim.from('bark')); - assert.strictEqual(emits, 0); - assert.strictEqual(pt.read(5).toString(), 'foogb'); - assert.strictEqual(pt.read(5), null); - pt.once('readable', common.mustCall(function () { - assert.strictEqual(pt.read(5).toString(), 'arkba'); - assert.strictEqual(pt.read(5), null); - pt.once('readable', common.mustCall(function () { - assert.strictEqual(pt.read(5).toString(), 'zykue'); - assert.strictEqual(pt.read(5), null); - pt.once('readable', common.mustCall(function () { - assert.strictEqual(pt.read(5).toString(), 'l'); - assert.strictEqual(pt.read(5), null); - assert.strictEqual(emits, 3); + _pt11.write(bufferShim.from('foog')); + _pt11.write(bufferShim.from('bark')); + assert.strictEqual(_emits, 0); + assert.strictEqual(_pt11.read(5).toString(), 'foogb'); + assert.strictEqual(_pt11.read(5), null); + _pt11.once('readable', common.mustCall(function () { + assert.strictEqual(_pt11.read(5).toString(), 'arkba'); + assert.strictEqual(_pt11.read(5), null); + _pt11.once('readable', common.mustCall(function () { + assert.strictEqual(_pt11.read(5).toString(), 'zykue'); + assert.strictEqual(_pt11.read(5), null); + _pt11.once('readable', common.mustCall(function () { + assert.strictEqual(_pt11.read(5).toString(), 'l'); + assert.strictEqual(_pt11.read(5), null); + assert.strictEqual(_emits, 3); })); - pt.end(); + _pt11.end(); })); - pt.write(bufferShim.from('kuel')); + _pt11.write(bufferShim.from('kuel')); })); - pt.write(bufferShim.from('bazy')); + _pt11.write(bufferShim.from('bazy')); } { // Verify passthrough facade - const pt = new PassThrough(); - const datas = []; - pt.on('data', function (chunk) { + var _pt12 = new PassThrough(); + var datas = []; + _pt12.on('data', function (chunk) { datas.push(chunk.toString()); }); - pt.on('end', common.mustCall(function () { + _pt12.on('end', common.mustCall(function () { assert.deepStrictEqual(datas, ['foog', 'bark', 'bazy', 'kuel']); })); - pt.write(bufferShim.from('foog')); + _pt12.write(bufferShim.from('foog')); setTimeout(function () { - pt.write(bufferShim.from('bark')); + _pt12.write(bufferShim.from('bark')); setTimeout(function () { - pt.write(bufferShim.from('bazy')); + _pt12.write(bufferShim.from('bazy')); setTimeout(function () { - pt.write(bufferShim.from('kuel')); + _pt12.write(bufferShim.from('kuel')); setTimeout(function () { - pt.end(); + _pt12.end(); }, 10); }, 10); }, 10); @@ -353,7 +354,7 @@ const Transform = require('../../lib/_stream_transform'); } { // Verify object transform (JSON parse) - const jp = new Transform({ + var jp = new Transform({ objectMode: true }); jp._transform = function (data, encoding, cb) { @@ -367,7 +368,7 @@ const Transform = require('../../lib/_stream_transform'); // anything except null/undefined is fine. // those are "magic" in the stream API, because they signal EOF. - const objects = [{ + var objects = [{ foo: 'bar' }, 100, 'string', { nested: { @@ -376,13 +377,13 @@ const Transform = require('../../lib/_stream_transform'); }, 100, 'string'] } }]; - let ended = false; + var ended = false; jp.on('end', function () { ended = true; }); forEach(objects, function (obj) { jp.write(JSON.stringify(obj)); - const res = jp.read(); + var res = jp.read(); assert.deepStrictEqual(res, obj); }); jp.end(); @@ -394,7 +395,7 @@ const Transform = require('../../lib/_stream_transform'); } { // Verify object transform (JSON stringify) - const js = new Transform({ + var js = new Transform({ objectMode: true }); js._transform = function (data, encoding, cb) { @@ -408,7 +409,7 @@ const Transform = require('../../lib/_stream_transform'); // anything except null/undefined is fine. // those are "magic" in the stream API, because they signal EOF. - const objects = [{ + var _objects = [{ foo: 'bar' }, 100, 'string', { nested: { @@ -417,20 +418,20 @@ const Transform = require('../../lib/_stream_transform'); }, 100, 'string'] } }]; - let ended = false; + var _ended = false; js.on('end', function () { - ended = true; + _ended = true; }); - forEach(objects, function (obj) { + forEach(_objects, function (obj) { js.write(obj); - const res = js.read(); + var res = js.read(); assert.strictEqual(res, JSON.stringify(obj)); }); js.end(); // read one more time to get the 'end' event js.read(); process.nextTick(common.mustCall(function () { - assert.strictEqual(ended, true); + assert.strictEqual(_ended, true); })); } function forEach(xs, f) { @@ -446,4 +447,6 @@ function forEach(xs, f) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-unpipe-drain.js b/test/parallel/test-stream2-unpipe-drain.js index 994fd64c3..3253b3552 100644 --- a/test/parallel/test-stream2-unpipe-drain.js +++ b/test/parallel/test-stream2-unpipe-drain.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } (function () { // Copyright Joyent, Inc. and other Node contributors. // @@ -23,43 +35,61 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ - const bufferShim = require('safe-buffer').Buffer; + var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); - const assert = require('assert/'); - const stream = require('../../'); - class TestWriter extends stream.Writable { - _write(buffer, encoding, callback) { - console.log('write called'); - // super slow write stream (callback never called) + var assert = require('assert/'); + var stream = require('../../'); + var TestWriter = /*#__PURE__*/function (_stream$Writable) { + _inherits(TestWriter, _stream$Writable); + var _super = _createSuper(TestWriter); + function TestWriter() { + _classCallCheck(this, TestWriter); + return _super.apply(this, arguments); } - } - - const dest = new TestWriter(); - class TestReader extends stream.Readable { - constructor() { - super(); - this.reads = 0; - } - _read(size) { - this.reads += 1; - this.push(bufferShim.alloc(size)); + _createClass(TestWriter, [{ + key: "_write", + value: function _write(buffer, encoding, callback) { + console.log('write called'); + // super slow write stream (callback never called) + } + }]); + return TestWriter; + }(stream.Writable); + var dest = new TestWriter(); + var TestReader = /*#__PURE__*/function (_stream$Readable) { + _inherits(TestReader, _stream$Readable); + var _super2 = _createSuper(TestReader); + function TestReader() { + var _this; + _classCallCheck(this, TestReader); + _this = _super2.call(this); + _this.reads = 0; + return _this; } - } - const src1 = new TestReader(); - const src2 = new TestReader(); + _createClass(TestReader, [{ + key: "_read", + value: function _read(size) { + this.reads += 1; + this.push(bufferShim.alloc(size)); + } + }]); + return TestReader; + }(stream.Readable); + var src1 = new TestReader(); + var src2 = new TestReader(); src1.pipe(dest); - src1.once('readable', () => { - process.nextTick(() => { + src1.once('readable', function () { + process.nextTick(function () { src2.pipe(dest); - src2.once('readable', () => { - process.nextTick(() => { + src2.once('readable', function () { + process.nextTick(function () { src1.unpipe(dest); }); }); }); }); - process.on('exit', () => { + process.on('exit', function () { assert.strictEqual(src1.reads, 2); assert.strictEqual(src2.reads, 2); }); @@ -71,4 +101,6 @@ var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-unpipe-leak.js b/test/parallel/test-stream2-unpipe-leak.js index a7884aca6..26005d7b6 100644 --- a/test/parallel/test-stream2-unpipe-leak.js +++ b/test/parallel/test-stream2-unpipe-leak.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,33 +34,50 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const chunk = bufferShim.from('hallo'); -class TestWriter extends stream.Writable { - _write(buffer, encoding, callback) { - callback(null); +var assert = require('assert/'); +var stream = require('../../'); +var chunk = bufferShim.from('hallo'); +var TestWriter = /*#__PURE__*/function (_stream$Writable) { + _inherits(TestWriter, _stream$Writable); + var _super = _createSuper(TestWriter); + function TestWriter() { + _classCallCheck(this, TestWriter); + return _super.apply(this, arguments); } -} -const dest = new TestWriter(); + _createClass(TestWriter, [{ + key: "_write", + value: function _write(buffer, encoding, callback) { + callback(null); + } + }]); + return TestWriter; +}(stream.Writable); +var dest = new TestWriter(); // Set this high so that we'd trigger a nextTick warning // and/or RangeError if we do maybeReadMore wrong. -class TestReader extends stream.Readable { - constructor() { - super({ +var TestReader = /*#__PURE__*/function (_stream$Readable) { + _inherits(TestReader, _stream$Readable); + var _super2 = _createSuper(TestReader); + function TestReader() { + _classCallCheck(this, TestReader); + return _super2.call(this, { highWaterMark: 0x10000 }); } - _read(size) { - this.push(chunk); - } -} -const src = new TestReader(); -for (let i = 0; i < 10; i++) { + _createClass(TestReader, [{ + key: "_read", + value: function _read(size) { + this.push(chunk); + } + }]); + return TestReader; +}(stream.Readable); +var src = new TestReader(); +for (var i = 0; i < 10; i++) { src.pipe(dest); src.unpipe(dest); } @@ -74,4 +103,6 @@ process.on('exit', function () { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 9bbe46c32..8ae96f781 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -1,5 +1,17 @@ "use strict"; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,35 +34,45 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const W = require('../../lib/_stream_writable'); -const D = require('../../lib/_stream_duplex'); -const assert = require('assert/'); -class TestWriter extends W { - constructor(opts) { - super(opts); - this.buffer = []; - this.written = 0; +var common = require('../common'); +var W = require('../../lib/_stream_writable'); +var D = require('../../lib/_stream_duplex'); +var assert = require('assert/'); +var TestWriter = /*#__PURE__*/function (_W) { + _inherits(TestWriter, _W); + var _super = _createSuper(TestWriter); + function TestWriter(opts) { + var _this; + _classCallCheck(this, TestWriter); + _this = _super.call(this, opts); + _this.buffer = []; + _this.written = 0; + return _this; } - _write(chunk, encoding, cb) { - // simulate a small unpredictable latency - setTimeout(() => { - this.buffer.push(chunk.toString()); - this.written += chunk.length; - cb(); - }, Math.floor(Math.random() * 10)); - } -} -const chunks = new Array(50); -for (let i = 0; i < chunks.length; i++) { + _createClass(TestWriter, [{ + key: "_write", + value: function _write(chunk, encoding, cb) { + var _this2 = this; + // simulate a small unpredictable latency + setTimeout(function () { + _this2.buffer.push(chunk.toString()); + _this2.written += chunk.length; + cb(); + }, Math.floor(Math.random() * 10)); + } + }]); + return TestWriter; +}(W); +var chunks = new Array(50); +for (var i = 0; i < chunks.length; i++) { chunks[i] = 'x'.repeat(i); } { // Verify fast writing - const tw = new TestWriter({ + var tw = new TestWriter({ highWaterMark: 100 }); tw.on('finish', common.mustCall(function () { @@ -65,159 +87,159 @@ for (let i = 0; i < chunks.length; i++) { } { // Verify slow writing - const tw = new TestWriter({ + var _tw = new TestWriter({ highWaterMark: 100 }); - tw.on('finish', common.mustCall(function () { + _tw.on('finish', common.mustCall(function () { // got chunks in the right order - assert.deepStrictEqual(tw.buffer, chunks); + assert.deepStrictEqual(_tw.buffer, chunks); })); - let i = 0; + var _i = 0; (function W() { - tw.write(chunks[i++]); - if (i < chunks.length) setTimeout(W, 10);else tw.end(); + _tw.write(chunks[_i++]); + if (_i < chunks.length) setTimeout(W, 10);else _tw.end(); })(); } { // Verify write backpressure - const tw = new TestWriter({ + var _tw2 = new TestWriter({ highWaterMark: 50 }); - let drains = 0; - tw.on('finish', common.mustCall(function () { + var drains = 0; + _tw2.on('finish', common.mustCall(function () { // got chunks in the right order - assert.deepStrictEqual(tw.buffer, chunks); + assert.deepStrictEqual(_tw2.buffer, chunks); assert.strictEqual(drains, 17); })); - tw.on('drain', function () { + _tw2.on('drain', function () { drains++; }); - let i = 0; + var _i2 = 0; (function W() { - let ret; + var ret; do { - ret = tw.write(chunks[i++]); - } while (ret !== false && i < chunks.length); - if (i < chunks.length) { - assert(tw.writableLength >= 50); - tw.once('drain', W); + ret = _tw2.write(chunks[_i2++]); + } while (ret !== false && _i2 < chunks.length); + if (_i2 < chunks.length) { + assert(_tw2.writableLength >= 50); + _tw2.once('drain', W); } else { - tw.end(); + _tw2.end(); } })(); } { // Verify write buffersize - const tw = new TestWriter({ + var _tw3 = new TestWriter({ highWaterMark: 100 }); - const encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; - tw.on('finish', function () { + var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; + _tw3.on('finish', function () { // got the expected chunks - assert.deepStrictEqual(tw.buffer, chunks); + assert.deepStrictEqual(_tw3.buffer, chunks); }); forEach(chunks, function (chunk, i) { - const enc = encodings[i % encodings.length]; + var enc = encodings[i % encodings.length]; chunk = bufferShim.from(chunk); - tw.write(chunk.toString(enc), enc); + _tw3.write(chunk.toString(enc), enc); }); } { // Verify write with no buffersize - const tw = new TestWriter({ + var _tw4 = new TestWriter({ highWaterMark: 100, decodeStrings: false }); - tw._write = function (chunk, encoding, cb) { + _tw4._write = function (chunk, encoding, cb) { assert.strictEqual(typeof chunk, 'string'); chunk = bufferShim.from(chunk, encoding); return TestWriter.prototype._write.call(this, chunk, encoding, cb); }; - const encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; - tw.on('finish', function () { + var _encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; + _tw4.on('finish', function () { // got the expected chunks - assert.deepStrictEqual(tw.buffer, chunks); + assert.deepStrictEqual(_tw4.buffer, chunks); }); forEach(chunks, function (chunk, i) { - const enc = encodings[i % encodings.length]; + var enc = _encodings[i % _encodings.length]; chunk = bufferShim.from(chunk); - tw.write(chunk.toString(enc), enc); + _tw4.write(chunk.toString(enc), enc); }); } { // Verify write callbacks - const callbacks = chunks.map(function (chunk, i) { + var callbacks = chunks.map(function (chunk, i) { return [i, function () { callbacks._called[i] = chunk; }]; }).reduce(function (set, x) { - set[`callback-${x[0]}`] = x[1]; + set["callback-".concat(x[0])] = x[1]; return set; }, {}); callbacks._called = []; - const tw = new TestWriter({ + var _tw5 = new TestWriter({ highWaterMark: 100 }); - tw.on('finish', common.mustCall(function () { + _tw5.on('finish', common.mustCall(function () { process.nextTick(common.mustCall(function () { // got chunks in the right order - assert.deepStrictEqual(tw.buffer, chunks); + assert.deepStrictEqual(_tw5.buffer, chunks); // called all callbacks assert.deepStrictEqual(callbacks._called, chunks); })); })); forEach(chunks, function (chunk, i) { - tw.write(chunk, callbacks[`callback-${i}`]); + _tw5.write(chunk, callbacks["callback-".concat(i)]); }); - tw.end(); + _tw5.end(); } { // Verify end() callback - const tw = new TestWriter(); - tw.end(common.mustCall()); + var _tw6 = new TestWriter(); + _tw6.end(common.mustCall()); } { // Verify end() callback with chunk - const tw = new TestWriter(); - tw.end(bufferShim.from('hello world'), common.mustCall()); + var _tw7 = new TestWriter(); + _tw7.end(bufferShim.from('hello world'), common.mustCall()); } { // Verify end() callback with chunk and encoding - const tw = new TestWriter(); - tw.end('hello world', 'ascii', common.mustCall()); + var _tw8 = new TestWriter(); + _tw8.end('hello world', 'ascii', common.mustCall()); } { // Verify end() callback after write() call - const tw = new TestWriter(); - tw.write(bufferShim.from('hello world')); - tw.end(common.mustCall()); + var _tw9 = new TestWriter(); + _tw9.write(bufferShim.from('hello world')); + _tw9.end(common.mustCall()); } { // Verify end() callback after write() callback - const tw = new TestWriter(); - let writeCalledback = false; - tw.write(bufferShim.from('hello world'), function () { + var _tw10 = new TestWriter(); + var writeCalledback = false; + _tw10.write(bufferShim.from('hello world'), function () { writeCalledback = true; }); - tw.end(common.mustCall(function () { + _tw10.end(common.mustCall(function () { assert.strictEqual(writeCalledback, true); })); } { // Verify encoding is ignored for buffers - const tw = new W(); - const hex = '018b5e9a8f6236ffe30e31baf80d2cf6eb'; - tw._write = common.mustCall(function (chunk) { + var _tw11 = new W(); + var hex = '018b5e9a8f6236ffe30e31baf80d2cf6eb'; + _tw11._write = common.mustCall(function (chunk) { assert.strictEqual(chunk.toString('hex'), hex); }); - const buf = bufferShim.from(hex, 'hex'); - tw.write(buf, 'latin1'); + var buf = bufferShim.from(hex, 'hex'); + _tw11.write(buf, 'latin1'); } { // Verify writables cannot be piped - const w = new W(); + var w = new W(); w._write = common.mustNotCall(); - let gotError = false; + var gotError = false; w.on('error', function () { gotError = true; }); @@ -226,38 +248,38 @@ for (let i = 0; i < chunks.length; i++) { } { // Verify that duplex streams cannot be piped - const d = new D(); + var d = new D(); d._read = common.mustCall(); d._write = common.mustNotCall(); - let gotError = false; + var _gotError = false; d.on('error', function () { - gotError = true; + _gotError = true; }); d.pipe(process.stdout); - assert.strictEqual(gotError, false); + assert.strictEqual(_gotError, false); } { // Verify that end(chunk) twice is an error - const w = new W(); - w._write = common.mustCall(msg => { + var _w = new W(); + _w._write = common.mustCall(function (msg) { assert.strictEqual(msg.toString(), 'this is the end'); }); - let gotError = false; - w.on('error', function (er) { - gotError = true; + var _gotError2 = false; + _w.on('error', function (er) { + _gotError2 = true; assert.strictEqual(er.message, 'write after end'); }); - w.end('this is the end'); - w.end('and so is this'); + _w.end('this is the end'); + _w.end('and so is this'); process.nextTick(common.mustCall(function () { - assert.strictEqual(gotError, true); + assert.strictEqual(_gotError2, true); })); } { // Verify stream doesn't end while writing - const w = new W(); - let wrote = false; - w._write = function (chunk, e, cb) { + var _w2 = new W(); + var wrote = false; + _w2._write = function (chunk, e, cb) { assert.strictEqual(this.writing, undefined); wrote = true; this.writing = true; @@ -266,72 +288,72 @@ for (let i = 0; i < chunks.length; i++) { cb(); }, 1); }; - w.on('finish', common.mustCall(function () { + _w2.on('finish', common.mustCall(function () { assert.strictEqual(wrote, true); })); - w.write(bufferShim.alloc(0)); - w.end(); + _w2.write(bufferShim.alloc(0)); + _w2.end(); } { // Verify finish does not come before write() callback - const w = new W(); - let writeCb = false; - w._write = function (chunk, e, cb) { + var _w3 = new W(); + var writeCb = false; + _w3._write = function (chunk, e, cb) { setTimeout(function () { writeCb = true; cb(); }, 10); }; - w.on('finish', common.mustCall(function () { + _w3.on('finish', common.mustCall(function () { assert.strictEqual(writeCb, true); })); - w.write(bufferShim.alloc(0)); - w.end(); + _w3.write(bufferShim.alloc(0)); + _w3.end(); } { // Verify finish does not come before synchronous _write() callback - const w = new W(); - let writeCb = false; - w._write = function (chunk, e, cb) { + var _w4 = new W(); + var _writeCb = false; + _w4._write = function (chunk, e, cb) { cb(); }; - w.on('finish', common.mustCall(function () { - assert.strictEqual(writeCb, true); + _w4.on('finish', common.mustCall(function () { + assert.strictEqual(_writeCb, true); })); - w.write(bufferShim.alloc(0), function () { - writeCb = true; + _w4.write(bufferShim.alloc(0), function () { + _writeCb = true; }); - w.end(); + _w4.end(); } { // Verify finish is emitted if the last chunk is empty - const w = new W(); - w._write = function (chunk, e, cb) { + var _w5 = new W(); + _w5._write = function (chunk, e, cb) { process.nextTick(cb); }; - w.on('finish', common.mustCall()); - w.write(bufferShim.allocUnsafe(1)); - w.end(bufferShim.alloc(0)); + _w5.on('finish', common.mustCall()); + _w5.write(bufferShim.allocUnsafe(1)); + _w5.end(bufferShim.alloc(0)); } { // Verify that finish is emitted after shutdown - const w = new W(); - let shutdown = false; - w._final = common.mustCall(function (cb) { - assert.strictEqual(this, w); + var _w6 = new W(); + var shutdown = false; + _w6._final = common.mustCall(function (cb) { + assert.strictEqual(this, _w6); setTimeout(function () { shutdown = true; cb(); }, 100); }); - w._write = function (chunk, e, cb) { + _w6._write = function (chunk, e, cb) { process.nextTick(cb); }; - w.on('finish', common.mustCall(function () { + _w6.on('finish', common.mustCall(function () { assert.strictEqual(shutdown, true); })); - w.write(bufferShim.allocUnsafe(1)); - w.end(bufferShim.allocUnsafe(0)); + _w6.write(bufferShim.allocUnsafe(1)); + _w6.end(bufferShim.allocUnsafe(0)); } function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { @@ -346,4 +368,6 @@ function forEach(xs, f) { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream3-cork-end.js b/test/parallel/test-stream3-cork-end.js index 2f12be3f4..1e18e3236 100644 --- a/test/parallel/test-stream3-cork-end.js +++ b/test/parallel/test-stream3-cork-end.js @@ -1,12 +1,12 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const Writable = stream.Writable; +var assert = require('assert/'); +var stream = require('../../'); +var Writable = stream.Writable; // Test the buffering behavior of Writable streams. // @@ -15,11 +15,11 @@ const Writable = stream.Writable; // // node version target: 0.12 -const expectedChunks = ['please', 'buffer', 'me', 'kindly']; -const inputChunks = expectedChunks.slice(0); -let seenChunks = []; -let seenEnd = false; -const w = new Writable(); +var expectedChunks = ['please', 'buffer', 'me', 'kindly']; +var inputChunks = expectedChunks.slice(0); +var seenChunks = []; +var seenEnd = false; +var w = new Writable(); // lets arrange to store the chunks w._write = function (chunk, encoding, cb) { // stream end event is not seen before the last write @@ -30,14 +30,14 @@ w._write = function (chunk, encoding, cb) { cb(); }; // lets record the stream end event -w.on('finish', () => { +w.on('finish', function () { seenEnd = true; }); function writeChunks(remainingChunks, callback) { - const writeChunk = remainingChunks.shift(); - let writeState; + var writeChunk = remainingChunks.shift(); + var writeState; if (writeChunk) { - setImmediate(() => { + setImmediate(function () { writeState = w.write(writeChunk); // we were not told to stop writing assert.ok(writeState); @@ -59,7 +59,7 @@ seenChunks = []; w.cork(); // write the bufferedChunks -writeChunks(inputChunks, () => { +writeChunks(inputChunks, function () { // should not have seen anything yet assert.strictEqual(seenChunks.length, 0); @@ -73,15 +73,15 @@ writeChunks(inputChunks, () => { assert.strictEqual(seenChunks.length, 4); // did the chunks match - for (let i = 0, l = expectedChunks.length; i < l; i++) { - const seen = seenChunks[i]; + for (var i = 0, l = expectedChunks.length; i < l; i++) { + var seen = seenChunks[i]; // there was a chunk assert.ok(seen); - const expected = bufferShim.from(expectedChunks[i]); + var expected = bufferShim.from(expectedChunks[i]); // it was what we expected assert.deepEqual(seen, expected); } - setImmediate(() => { + setImmediate(function () { // stream should have ended in next tick assert.ok(seenEnd); }); @@ -94,4 +94,6 @@ writeChunks(inputChunks, () => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-stream3-cork-uncork.js b/test/parallel/test-stream3-cork-uncork.js index 85b75b5c6..7f4c36a4d 100644 --- a/test/parallel/test-stream3-cork-uncork.js +++ b/test/parallel/test-stream3-cork-uncork.js @@ -1,12 +1,12 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const Writable = stream.Writable; +var assert = require('assert/'); +var stream = require('../../'); +var Writable = stream.Writable; // Test the buffering behavior of Writable streams. // @@ -15,11 +15,11 @@ const Writable = stream.Writable; // // node version target: 0.12 -const expectedChunks = ['please', 'buffer', 'me', 'kindly']; -const inputChunks = expectedChunks.slice(0); -let seenChunks = []; -let seenEnd = false; -const w = new Writable(); +var expectedChunks = ['please', 'buffer', 'me', 'kindly']; +var inputChunks = expectedChunks.slice(0); +var seenChunks = []; +var seenEnd = false; +var w = new Writable(); // lets arrange to store the chunks w._write = function (chunk, encoding, cb) { // default encoding given none was specified @@ -28,14 +28,14 @@ w._write = function (chunk, encoding, cb) { cb(); }; // lets record the stream end event -w.on('finish', () => { +w.on('finish', function () { seenEnd = true; }); function writeChunks(remainingChunks, callback) { - const writeChunk = remainingChunks.shift(); - let writeState; + var writeChunk = remainingChunks.shift(); + var writeState; if (writeChunk) { - setImmediate(() => { + setImmediate(function () { writeState = w.write(writeChunk); // we were not told to stop writing assert.ok(writeState); @@ -57,7 +57,7 @@ seenChunks = []; w.cork(); // write the bufferedChunks -writeChunks(inputChunks, () => { +writeChunks(inputChunks, function () { // should not have seen anything yet assert.strictEqual(seenChunks.length, 0); @@ -68,15 +68,15 @@ writeChunks(inputChunks, () => { assert.strictEqual(seenChunks.length, 4); // did the chunks match - for (let i = 0, l = expectedChunks.length; i < l; i++) { - const seen = seenChunks[i]; + for (var i = 0, l = expectedChunks.length; i < l; i++) { + var seen = seenChunks[i]; // there was a chunk assert.ok(seen); - const expected = bufferShim.from(expectedChunks[i]); + var expected = bufferShim.from(expectedChunks[i]); // it was what we expected assert.deepEqual(seen, expected); } - setImmediate(() => { + setImmediate(function () { // the stream should not have been ended assert.ok(!seenEnd); }); @@ -89,4 +89,6 @@ writeChunks(inputChunks, () => { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ 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 8a552932c..9a548f91b 100644 --- a/test/parallel/test-stream3-pause-then-read.js +++ b/test/parallel/test-stream3-pause-then-read.js @@ -22,28 +22,28 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ require('../common'); -const assert = require('assert/'); -const stream = require('../../'); -const Readable = stream.Readable; -const Writable = stream.Writable; -const totalChunks = 100; -const chunkSize = 99; -const expectTotalData = totalChunks * chunkSize; -let expectEndingData = expectTotalData; -const r = new Readable({ +var assert = require('assert/'); +var stream = require('../../'); +var Readable = stream.Readable; +var Writable = stream.Writable; +var totalChunks = 100; +var chunkSize = 99; +var expectTotalData = totalChunks * chunkSize; +var expectEndingData = expectTotalData; +var r = new Readable({ highWaterMark: 1000 }); -let chunks = totalChunks; +var chunks = totalChunks; r._read = function (n) { console.log('_read called', chunks); if (!(chunks % 2)) setImmediate(push);else if (!(chunks % 3)) process.nextTick(push);else push(); }; -let totalPushed = 0; +var totalPushed = 0; function push() { - const chunk = chunks-- > 0 ? bufferShim.alloc(chunkSize, 'x') : null; + var chunk = chunks-- > 0 ? bufferShim.alloc(chunkSize, 'x') : null; if (chunk) { totalPushed += chunk.length; } @@ -57,10 +57,10 @@ function read100() { readn(100, onData); } function readn(n, then) { - console.error(`read ${n}`); + console.error("read ".concat(n)); expectEndingData -= n; (function read() { - const c = r.read(n); + var c = r.read(n); console.error('c', c); if (!c) r.once('readable', read);else { assert.strictEqual(c.length, n); @@ -74,7 +74,7 @@ function readn(n, then) { function onData() { expectEndingData -= 100; console.error('onData'); - let seen = 0; + var seen = 0; r.on('data', function od(c) { seen += c.length; if (seen >= 100) { @@ -84,7 +84,7 @@ function onData() { if (seen > 100) { // oh no, seen too much! // put the extra back. - const diff = seen - 100; + var diff = seen - 100; r.unshift(c.slice(c.length - diff)); console.error('seen too much', seen, diff); } @@ -99,8 +99,8 @@ function onData() { function pipeLittle() { expectEndingData -= 200; console.error('pipe a little'); - const w = new Writable(); - let written = 0; + var w = new Writable(); + var written = 0; w.on('finish', function () { assert.strictEqual(written, 200); setImmediate(read1234); @@ -112,7 +112,7 @@ function pipeLittle() { w.end(); cb(); if (written > 200) { - const diff = written - 200; + var diff = written - 200; written -= diff; r.unshift(chunk.slice(chunk.length - diff)); } @@ -144,8 +144,8 @@ function resumePause() { } function pipe() { console.error('pipe the rest'); - const w = new Writable(); - let written = 0; + var w = new Writable(); + var written = 0; w._write = function (chunk, encoding, cb) { written += chunk.length; cb(); @@ -166,4 +166,6 @@ function pipe() { var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file diff --git a/test/parallel/test-streams-highwatermark.js b/test/parallel/test-streams-highwatermark.js index 849d6f5b6..63349c0b7 100644 --- a/test/parallel/test-streams-highwatermark.js +++ b/test/parallel/test-streams-highwatermark.js @@ -1,11 +1,11 @@ "use strict"; /**/ -const bufferShim = require('safe-buffer').Buffer; +var bufferShim = require('safe-buffer').Buffer; /**/ -const common = require('../common'); -const assert = require('assert/'); -const stream = require('../../'); +var common = require('../common'); +var assert = require('assert/'); +var stream = require('../../'); { // This test ensures that the stream implementation correctly handles values // for highWaterMark which exceed the range of signed 32 bit integers and @@ -13,29 +13,35 @@ const stream = require('../../'); // This number exceeds the range of 32 bit integer arithmetic but should still // be handled correctly. - const ovfl = Number.MAX_SAFE_INTEGER; - const readable = stream.Readable({ + var ovfl = Number.MAX_SAFE_INTEGER; + var readable = stream.Readable({ highWaterMark: ovfl }); assert.strictEqual(readable._readableState.highWaterMark, ovfl); - const writable = stream.Writable({ + var writable = stream.Writable({ highWaterMark: ovfl }); assert.strictEqual(writable._writableState.highWaterMark, ovfl); - for (var _i = 0, _arr = [true, false, '5', {}, -5, NaN]; _i < _arr.length; _i++) { - const invalidHwm = _arr[_i]; - for (var _i2 = 0, _arr2 = [stream.Readable, stream.Writable]; _i2 < _arr2.length; _i2++) { - const type = _arr2[_i2]; - common.expectsError(() => { + var _loop = function _loop() { + var invalidHwm = _arr[_i]; + var _loop2 = function _loop2() { + var type = _arr2[_i2]; + common.expectsError(function () { type({ highWaterMark: invalidHwm }); }, { type: TypeError, code: 'ERR_INVALID_OPT_VALUE', - message: `The value "${invalidHwm}" is invalid for option "highWaterMark"` + message: "The value \"".concat(invalidHwm, "\" is invalid for option \"highWaterMark\"") }); + }; + for (var _i2 = 0, _arr2 = [stream.Readable, stream.Writable]; _i2 < _arr2.length; _i2++) { + _loop2(); } + }; + for (var _i = 0, _arr = [true, false, '5', {}, -5, NaN]; _i < _arr.length; _i++) { + _loop(); } } { @@ -43,11 +49,11 @@ const stream = require('../../'); // correctly handles the edge case where the highWaterMark and // the state.length are both zero - const readable = stream.Readable({ + var _readable = stream.Readable({ highWaterMark: 0 }); - for (let i = 0; i < 3; i++) { - const needMoreData = readable.push(); + for (var i = 0; i < 3; i++) { + var needMoreData = _readable.push(); assert.strictEqual(needMoreData, true); } } @@ -56,11 +62,11 @@ const stream = require('../../'); // correctly handles the edge case where the highWaterMark, state.length // and n are all zero - const readable = stream.Readable({ + var _readable2 = stream.Readable({ highWaterMark: 0 }); - readable._read = common.mustCall(); - readable.read(0); + _readable2._read = common.mustCall(); + _readable2.read(0); } ; (function () { @@ -70,4 +76,6 @@ const stream = require('../../'); var _list = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); _list.pop(); -_list.forEach(e => process.on('uncaughtException', e)); \ No newline at end of file +_list.forEach(function (e) { + return process.on('uncaughtException', e); +}); \ No newline at end of file