From 443697fd1eae20fb3c92cbd16a4ac9edd2a35e17 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Mon, 23 May 2016 00:20:31 -0700 Subject: [PATCH] rebuild mocha.js --- mocha.js | 320 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 229 insertions(+), 91 deletions(-) diff --git a/mocha.js b/mocha.js index 9d98db7101..bcb7ab1e14 100644 --- a/mocha.js +++ b/mocha.js @@ -162,10 +162,13 @@ Mocha.process = process; global.Mocha = Mocha; global.mocha = mocha; +// this allows test/acceptance/required-tokens.js to pass; thus, +// you can now do `const describe = require('mocha').describe` in a +// browser context (assuming browserification). should fix #880 module.exports = global; }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./lib/mocha":14,"_process":57,"browser-stdout":42}],2:[function(require,module,exports){ +},{"./lib/mocha":14,"_process":58,"browser-stdout":42}],2:[function(require,module,exports){ /* eslint-disable no-unused-vars */ module.exports = function(type) { return function() {}; @@ -488,7 +491,7 @@ Progress.prototype.draw = function(ctx) { },{}],5:[function(require,module,exports){ (function (global){ exports.isatty = function isatty() { - return false; + return true; }; exports.getWindowSize = function getWindowSize() { @@ -773,7 +776,7 @@ module.exports = function(suite) { }); }; -},{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":47}],9:[function(require,module,exports){ +},{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":48}],9:[function(require,module,exports){ 'use strict'; /** @@ -1025,7 +1028,7 @@ module.exports = function(suite) { }); }; -},{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":47}],13:[function(require,module,exports){ +},{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":48}],13:[function(require,module,exports){ /** * Module dependencies. */ @@ -1133,7 +1136,7 @@ module.exports = function(suite) { }); }; -},{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":47}],14:[function(require,module,exports){ +},{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":48}],14:[function(require,module,exports){ (function (process,global,__dirname){ /*! * mocha @@ -1640,7 +1643,7 @@ Mocha.prototype.run = function(fn) { }; }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},"/lib") -},{"./context":6,"./hook":7,"./interfaces":11,"./reporters":22,"./runnable":35,"./runner":36,"./suite":37,"./test":38,"./utils":39,"_process":57,"escape-string-regexp":47,"growl":49,"path":43}],15:[function(require,module,exports){ +},{"./context":6,"./hook":7,"./interfaces":11,"./reporters":22,"./runnable":35,"./runner":36,"./suite":37,"./test":38,"./utils":39,"_process":58,"escape-string-regexp":48,"growl":50,"path":43}],15:[function(require,module,exports){ /** * Helpers. */ @@ -2278,7 +2281,7 @@ function sameType(a, b) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../ms":15,"../utils":39,"_process":57,"diff":46,"supports-color":43,"tty":5}],18:[function(require,module,exports){ +},{"../ms":15,"../utils":39,"_process":58,"diff":47,"supports-color":43,"tty":5}],18:[function(require,module,exports){ /** * Module dependencies. */ @@ -2412,7 +2415,7 @@ function Dot(runner) { inherits(Dot, Base); }).call(this,require('_process')) -},{"../utils":39,"./base":17,"_process":57}],20:[function(require,module,exports){ +},{"../utils":39,"./base":17,"_process":58}],20:[function(require,module,exports){ (function (process,__dirname){ /** * Module dependencies. @@ -2472,7 +2475,7 @@ function coverageClass(coveragePctg) { } }).call(this,require('_process'),"/lib/reporters") -},{"./json-cov":23,"_process":57,"fs":43,"jade":43,"path":43}],21:[function(require,module,exports){ +},{"./json-cov":23,"_process":58,"fs":43,"jade":43,"path":43}],21:[function(require,module,exports){ (function (global){ /* eslint-env browser */ @@ -2805,7 +2808,7 @@ function on(el, event, fn) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../browser/progress":4,"../utils":39,"./base":17,"escape-string-regexp":47}],22:[function(require,module,exports){ +},{"../browser/progress":4,"../utils":39,"./base":17,"escape-string-regexp":48}],22:[function(require,module,exports){ // Alias exports to a their normalized format Mocha#reporter to prevent a need // for dynamic (try/catch) requires, which Browserify doesn't handle. exports.Base = exports.base = require('./base'); @@ -2981,7 +2984,7 @@ function clean(test) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./base":17,"_process":57}],24:[function(require,module,exports){ +},{"./base":17,"_process":58}],24:[function(require,module,exports){ (function (process){ /** * Module dependencies. @@ -3045,7 +3048,7 @@ function clean(test) { } }).call(this,require('_process')) -},{"./base":17,"_process":57}],25:[function(require,module,exports){ +},{"./base":17,"_process":58}],25:[function(require,module,exports){ (function (process){ /** * Module dependencies. @@ -3139,7 +3142,7 @@ function errorJSON(err) { } }).call(this,require('_process')) -},{"./base":17,"_process":57}],26:[function(require,module,exports){ +},{"./base":17,"_process":58}],26:[function(require,module,exports){ (function (process){ /** * Module dependencies. @@ -3235,7 +3238,7 @@ function Landing(runner) { inherits(Landing, Base); }).call(this,require('_process')) -},{"../utils":39,"./base":17,"_process":57}],27:[function(require,module,exports){ +},{"../utils":39,"./base":17,"_process":58}],27:[function(require,module,exports){ (function (process){ /** * Module dependencies. @@ -3300,7 +3303,7 @@ function List(runner) { inherits(List, Base); }).call(this,require('_process')) -},{"../utils":39,"./base":17,"_process":57}],28:[function(require,module,exports){ +},{"../utils":39,"./base":17,"_process":58}],28:[function(require,module,exports){ (function (process){ /** * Module dependencies. @@ -3401,7 +3404,7 @@ function Markdown(runner) { } }).call(this,require('_process')) -},{"../utils":39,"./base":17,"_process":57}],29:[function(require,module,exports){ +},{"../utils":39,"./base":17,"_process":58}],29:[function(require,module,exports){ (function (process){ /** * Module dependencies. @@ -3441,7 +3444,7 @@ function Min(runner) { inherits(Min, Base); }).call(this,require('_process')) -},{"../utils":39,"./base":17,"_process":57}],30:[function(require,module,exports){ +},{"../utils":39,"./base":17,"_process":58}],30:[function(require,module,exports){ (function (process){ /** * Module dependencies. @@ -3706,7 +3709,7 @@ function write(string) { } }).call(this,require('_process')) -},{"../utils":39,"./base":17,"_process":57}],31:[function(require,module,exports){ +},{"../utils":39,"./base":17,"_process":58}],31:[function(require,module,exports){ (function (process){ /** * Module dependencies. @@ -3799,7 +3802,7 @@ function Progress(runner, options) { inherits(Progress, Base); }).call(this,require('_process')) -},{"../utils":39,"./base":17,"_process":57}],32:[function(require,module,exports){ +},{"../utils":39,"./base":17,"_process":58}],32:[function(require,module,exports){ /** * Module dependencies. */ @@ -4132,7 +4135,7 @@ function cdata(str) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../utils":39,"./base":17,"_process":57,"fs":43,"mkdirp":54,"path":43}],35:[function(require,module,exports){ +},{"../utils":39,"./base":17,"_process":58,"fs":43,"mkdirp":55,"path":43}],35:[function(require,module,exports){ (function (global){ /** * Module dependencies. @@ -5397,7 +5400,7 @@ function extraGlobals() { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./pending":16,"./runnable":35,"./utils":39,"_process":57,"debug":2,"events":3}],37:[function(require,module,exports){ +},{"./pending":16,"./runnable":35,"./utils":39,"_process":58,"debug":2,"events":3}],37:[function(require,module,exports){ /** * Module dependencies. */ @@ -6594,7 +6597,7 @@ exports.stackTraceFilter = function() { }; }).call(this,require('_process'),require("buffer").Buffer) -},{"_process":57,"buffer":44,"debug":2,"fs":43,"glob":43,"path":43,"to-iso-string":70,"util":73}],40:[function(require,module,exports){ +},{"_process":58,"buffer":45,"debug":2,"fs":43,"glob":43,"path":43,"to-iso-string":71,"util":74}],40:[function(require,module,exports){ 'use strict' exports.toByteArray = toByteArray @@ -6736,10 +6739,122 @@ BrowserStdout.prototype._write = function(chunks, encoding, cb) { } }).call(this,require('_process')) -},{"_process":57,"stream":68,"util":73}],43:[function(require,module,exports){ +},{"_process":58,"stream":69,"util":74}],43:[function(require,module,exports){ arguments[4][41][0].apply(exports,arguments) },{"dup":41}],44:[function(require,module,exports){ (function (global){ +'use strict'; + +var buffer = require('buffer'); +var Buffer = buffer.Buffer; +var SlowBuffer = buffer.SlowBuffer; +var MAX_LEN = buffer.kMaxLength || 2147483647; +exports.alloc = function alloc(size, fill, encoding) { + if (typeof Buffer.alloc === 'function') { + return Buffer.alloc(size, fill, encoding); + } + if (typeof encoding === 'number') { + throw new TypeError('encoding must not be number'); + } + if (typeof size !== 'number') { + throw new TypeError('size must be a number'); + } + if (size > MAX_LEN) { + throw new RangeError('size is too large'); + } + var enc = encoding; + var _fill = fill; + if (_fill === undefined) { + enc = undefined; + _fill = 0; + } + var buf = new Buffer(size); + if (typeof _fill === 'string') { + var fillBuf = new Buffer(_fill, enc); + var flen = fillBuf.length; + var i = -1; + while (++i < size) { + buf[i] = fillBuf[i % flen]; + } + } else { + buf.fill(_fill); + } + return buf; +} +exports.allocUnsafe = function allocUnsafe(size) { + if (typeof Buffer.allocUnsafe === 'function') { + return Buffer.allocUnsafe(size); + } + if (typeof size !== 'number') { + throw new TypeError('size must be a number'); + } + if (size > MAX_LEN) { + throw new RangeError('size is too large'); + } + return new Buffer(size); +} +exports.from = function from(value, encodingOrOffset, length) { + if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) { + return Buffer.from(value, encodingOrOffset, length); + } + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number'); + } + if (typeof value === 'string') { + return new Buffer(value, encodingOrOffset); + } + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + var offset = encodingOrOffset; + if (arguments.length === 1) { + return new Buffer(value); + } + if (typeof offset === 'undefined') { + offset = 0; + } + var len = length; + if (typeof len === 'undefined') { + len = value.byteLength - offset; + } + if (offset >= value.byteLength) { + throw new RangeError('\'offset\' is out of bounds'); + } + if (len > value.byteLength - offset) { + throw new RangeError('\'length\' is out of bounds'); + } + return new Buffer(value.slice(offset, offset + len)); + } + if (Buffer.isBuffer(value)) { + var out = new Buffer(value.length); + value.copy(out, 0, 0, value.length); + return out; + } + if (value) { + if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) { + return new Buffer(value); + } + if (value.type === 'Buffer' && Array.isArray(value.data)) { + return new Buffer(value.data); + } + } + + throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.'); +} +exports.allocUnsafeSlow = function allocUnsafeSlow(size) { + if (typeof Buffer.allocUnsafeSlow === 'function') { + return Buffer.allocUnsafeSlow(size); + } + if (typeof size !== 'number') { + throw new TypeError('size must be a number'); + } + if (size >= MAX_LEN) { + throw new RangeError('size is too large'); + } + return new SlowBuffer(size); +} + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"buffer":45}],45:[function(require,module,exports){ +(function (global){ /*! * The buffer module from node.js, for the browser. * @@ -8453,7 +8568,7 @@ function isnan (val) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"base64-js":40,"ieee754":50,"isarray":53}],45:[function(require,module,exports){ +},{"base64-js":40,"ieee754":51,"isarray":54}],46:[function(require,module,exports){ (function (Buffer){ // Copyright Joyent, Inc. and other Node contributors. // @@ -8564,7 +8679,7 @@ function objectToString(o) { } }).call(this,{"isBuffer":require("../../is-buffer/index.js")}) -},{"../../is-buffer/index.js":52}],46:[function(require,module,exports){ +},{"../../is-buffer/index.js":53}],47:[function(require,module,exports){ /* See LICENSE file for terms of use */ /* @@ -9185,7 +9300,7 @@ function objectToString(o) { } }(this)); -},{}],47:[function(require,module,exports){ +},{}],48:[function(require,module,exports){ 'use strict'; var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; @@ -9198,7 +9313,7 @@ module.exports = function (str) { return str.replace(matchOperatorsRe, '\\$&'); }; -},{}],48:[function(require,module,exports){ +},{}],49:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -9498,7 +9613,7 @@ function isUndefined(arg) { return arg === void 0; } -},{}],49:[function(require,module,exports){ +},{}],50:[function(require,module,exports){ (function (process){ // Growl - Copyright TJ Holowaychuk (MIT Licensed) @@ -9792,7 +9907,7 @@ function growl(msg, options, fn) { }; }).call(this,require('_process')) -},{"_process":57,"child_process":43,"fs":43,"os":55,"path":43}],50:[function(require,module,exports){ +},{"_process":58,"child_process":43,"fs":43,"os":56,"path":43}],51:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m var eLen = nBytes * 8 - mLen - 1 @@ -9878,7 +9993,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],51:[function(require,module,exports){ +},{}],52:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -9903,7 +10018,7 @@ if (typeof Object.create === 'function') { } } -},{}],52:[function(require,module,exports){ +},{}],53:[function(require,module,exports){ /** * Determine if an object is Buffer * @@ -9922,14 +10037,14 @@ module.exports = function (obj) { )) } -},{}],53:[function(require,module,exports){ +},{}],54:[function(require,module,exports){ var toString = {}.toString; module.exports = Array.isArray || function (arr) { return toString.call(arr) == '[object Array]'; }; -},{}],54:[function(require,module,exports){ +},{}],55:[function(require,module,exports){ (function (process){ var path = require('path'); var fs = require('fs'); @@ -10031,7 +10146,7 @@ mkdirP.sync = function sync (p, opts, made) { }; }).call(this,require('_process')) -},{"_process":57,"fs":43,"path":43}],55:[function(require,module,exports){ +},{"_process":58,"fs":43,"path":43}],56:[function(require,module,exports){ exports.endianness = function () { return 'LE' }; exports.hostname = function () { @@ -10078,7 +10193,7 @@ exports.tmpdir = exports.tmpDir = function () { exports.EOL = '\n'; -},{}],56:[function(require,module,exports){ +},{}],57:[function(require,module,exports){ (function (process){ 'use strict'; @@ -10125,7 +10240,7 @@ function nextTick(fn, arg1, arg2, arg3) { } }).call(this,require('_process')) -},{"_process":57}],57:[function(require,module,exports){ +},{"_process":58}],58:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -10221,10 +10336,10 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],58:[function(require,module,exports){ +},{}],59:[function(require,module,exports){ module.exports = require("./lib/_stream_duplex.js") -},{"./lib/_stream_duplex.js":59}],59:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":60}],60:[function(require,module,exports){ // a duplex stream is just a stream that is both readable and writable. // Since JS doesn't have multiple prototypal inheritance, this class // prototypally inherits from Readable, and then parasitically from @@ -10300,7 +10415,7 @@ function forEach(xs, f) { f(xs[i], i); } } -},{"./_stream_readable":61,"./_stream_writable":63,"core-util-is":45,"inherits":51,"process-nextick-args":56}],60:[function(require,module,exports){ +},{"./_stream_readable":62,"./_stream_writable":64,"core-util-is":46,"inherits":52,"process-nextick-args":57}],61:[function(require,module,exports){ // a passthrough stream. // basically just the most minimal sort of Transform stream. // Every written chunk gets output as-is. @@ -10327,7 +10442,7 @@ function PassThrough(options) { PassThrough.prototype._transform = function (chunk, encoding, cb) { cb(null, chunk); }; -},{"./_stream_transform":62,"core-util-is":45,"inherits":51}],61:[function(require,module,exports){ +},{"./_stream_transform":63,"core-util-is":46,"inherits":52}],62:[function(require,module,exports){ (function (process){ 'use strict'; @@ -10341,15 +10456,11 @@ var processNextTick = require('process-nextick-args'); var isArray = require('isarray'); /**/ -/**/ -var Buffer = require('buffer').Buffer; -/**/ - Readable.ReadableState = ReadableState; -var EE = require('events'); - /**/ +var EE = require('events').EventEmitter; + var EElistenerCount = function (emitter, type) { return emitter.listeners(type).length; }; @@ -10367,6 +10478,9 @@ var Stream; /**/ var Buffer = require('buffer').Buffer; +/**/ +var bufferShim = require('buffer-shims'); +/**/ /**/ var util = require('core-util-is'); @@ -10375,7 +10489,7 @@ util.inherits = require('inherits'); /**/ var debugUtil = require('util'); -var debug = undefined; +var debug = void 0; if (debugUtil && debugUtil.debuglog) { debug = debugUtil.debuglog('stream'); } else { @@ -10387,6 +10501,19 @@ var StringDecoder; util.inherits(Readable, Stream); +var hasPrependListener = typeof EE.prototype.prependListener === 'function'; + +function prependListener(emitter, event, fn) { + if (hasPrependListener) return emitter.prependListener(event, fn); + + // This is a brutally ugly hack to make sure that our error handler + // is attached before any userland ones. NEVER DO THIS. This is here + // only because this code needs to continue to work with older versions + // of Node.js that do not include the prependListener() method. The goal + // is to eventually remove this hack. + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; +} + var Duplex; function ReadableState(options, stream) { Duplex = Duplex || require('./_stream_duplex'); @@ -10480,7 +10607,7 @@ Readable.prototype.push = function (chunk, encoding) { if (!state.objectMode && typeof chunk === 'string') { encoding = encoding || state.defaultEncoding; if (encoding !== state.encoding) { - chunk = new Buffer(chunk, encoding); + chunk = bufferShim.from(chunk, encoding); encoding = ''; } } @@ -10510,8 +10637,8 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) { var e = new Error('stream.push() after EOF'); stream.emit('error', e); } else if (state.endEmitted && addToFront) { - var e = new Error('stream.unshift() after end event'); - stream.emit('error', e); + var _e = new Error('stream.unshift() after end event'); + stream.emit('error', _e); } else { var skipAdd; if (state.decoder && !addToFront && !encoding) { @@ -10864,7 +10991,8 @@ Readable.prototype.pipe = function (dest, pipeOpts) { // If the user unpiped during `dest.write()`, it is possible // to get stuck in a permanently paused state if that write // also returned false. - if (state.pipesCount === 1 && state.pipes[0] === dest && src.listenerCount('data') === 1 && !cleanedUp) { + // => Check whether `dest` is still a piping destination. + if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { debug('false write response, pause', src._readableState.awaitDrain); src._readableState.awaitDrain++; } @@ -10880,9 +11008,9 @@ Readable.prototype.pipe = function (dest, pipeOpts) { dest.removeListener('error', onerror); if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); } - // This is a brutally ugly hack to make sure that our error handler - // is attached before any userland ones. NEVER DO THIS. - if (!dest._events || !dest._events.error) dest.on('error', onerror);else if (isArray(dest._events.error)) dest._events.error.unshift(onerror);else dest._events.error = [onerror, dest._events.error]; + + // Make sure our error handler is attached before userland ones. + prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once. function onclose() { @@ -11156,16 +11284,16 @@ function fromList(n, state) { } else { // complex case. // we have enough to cover it, but it spans past the first buffer. - if (stringMode) ret = '';else ret = new Buffer(n); + if (stringMode) ret = '';else ret = bufferShim.allocUnsafe(n); var c = 0; for (var i = 0, l = list.length; i < l && c < n; i++) { - var buf = list[0]; - var cpy = Math.min(n - c, buf.length); + var _buf = list[0]; + var cpy = Math.min(n - c, _buf.length); - if (stringMode) ret += buf.slice(0, cpy);else buf.copy(ret, c, 0, cpy); + if (stringMode) ret += _buf.slice(0, cpy);else _buf.copy(ret, c, 0, cpy); - if (cpy < buf.length) list[0] = buf.slice(cpy);else list.shift(); + if (cpy < _buf.length) list[0] = _buf.slice(cpy);else list.shift(); c += cpy; } @@ -11180,7 +11308,7 @@ function endReadable(stream) { // If we get here before consuming all the bytes, then that is a // bug in node. Should never happen. - if (state.length > 0) throw new Error('endReadable called on non-empty stream'); + if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream'); if (!state.endEmitted) { state.ended = true; @@ -11210,7 +11338,7 @@ function indexOf(xs, x) { return -1; } }).call(this,require('_process')) -},{"./_stream_duplex":59,"_process":57,"buffer":44,"core-util-is":45,"events":48,"inherits":51,"isarray":53,"process-nextick-args":56,"string_decoder/":69,"util":41}],62:[function(require,module,exports){ +},{"./_stream_duplex":60,"_process":58,"buffer":45,"buffer-shims":44,"core-util-is":46,"events":49,"inherits":52,"isarray":54,"process-nextick-args":57,"string_decoder/":70,"util":41}],63:[function(require,module,exports){ // a transform stream is a readable/writable stream where you do // something with the data. Sometimes it's called a "filter", // but that's not a great name for it, since that implies a thing where @@ -11347,7 +11475,7 @@ Transform.prototype.push = function (chunk, encoding) { // an error, then that'll put the hurt on the whole operation. If you // never call cb(), then you'll never get another chunk. Transform.prototype._transform = function (chunk, encoding, cb) { - throw new Error('not implemented'); + throw new Error('Not implemented'); }; Transform.prototype._write = function (chunk, encoding, cb) { @@ -11385,13 +11513,13 @@ function done(stream, er) { var ws = stream._writableState; var ts = stream._transformState; - if (ws.length) throw new Error('calling transform done when ws.length != 0'); + if (ws.length) throw new Error('Calling transform done when ws.length != 0'); - if (ts.transforming) throw new Error('calling transform done when still transforming'); + if (ts.transforming) throw new Error('Calling transform done when still transforming'); return stream.push(null); } -},{"./_stream_duplex":59,"core-util-is":45,"inherits":51}],63:[function(require,module,exports){ +},{"./_stream_duplex":60,"core-util-is":46,"inherits":52}],64:[function(require,module,exports){ (function (process){ // A bit simpler than readable streams. // Implement an async ._write(chunk, encoding, cb), and it'll handle all @@ -11409,10 +11537,6 @@ var processNextTick = require('process-nextick-args'); var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; /**/ -/**/ -var Buffer = require('buffer').Buffer; -/**/ - Writable.WritableState = WritableState; /**/ @@ -11438,6 +11562,9 @@ var Stream; /**/ var Buffer = require('buffer').Buffer; +/**/ +var bufferShim = require('buffer-shims'); +/**/ util.inherits(Writable, Stream); @@ -11541,10 +11668,9 @@ function WritableState(options, stream) { // count buffered requests this.bufferedRequestCount = 0; - // create the two objects needed to store the corked requests - // they are not a linked list, as no new elements are inserted in there + // allocate the first CorkedRequest, there is always + // one allocated and free to use, and we maintain at most two this.corkedRequestsFree = new CorkedRequest(this); - this.corkedRequestsFree.next = new CorkedRequest(this); } WritableState.prototype.getBuffer = function writableStateGetBuffer() { @@ -11591,7 +11717,7 @@ function Writable(options) { // Otherwise people can pipe Writable streams, which is just wrong. Writable.prototype.pipe = function () { - this.emit('error', new Error('Cannot pipe. Not readable.')); + this.emit('error', new Error('Cannot pipe, not readable')); }; function writeAfterEnd(stream, cb) { @@ -11608,9 +11734,16 @@ function writeAfterEnd(stream, cb) { // how many bytes or characters. function validChunk(stream, state, chunk, cb) { var valid = true; - - if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { - var er = new TypeError('Invalid non-string/buffer chunk'); + var er = false; + // Always throw error if a null is written + // if we are not in object mode then throw + // if it is not a buffer, string, or undefined. + if (chunk === null) { + er = new TypeError('May not write null values to stream'); + } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { + er = new TypeError('Invalid non-string/buffer chunk'); + } + if (er) { stream.emit('error', er); processNextTick(cb, er); valid = false; @@ -11660,11 +11793,12 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { if (typeof encoding === 'string') encoding = encoding.toLowerCase(); if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding); this._writableState.defaultEncoding = encoding; + return this; }; function decodeChunk(state, chunk, encoding) { if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { - chunk = new Buffer(chunk, encoding); + chunk = bufferShim.from(chunk, encoding); } return chunk; } @@ -11787,12 +11921,16 @@ function clearBuffer(stream, state) { doWrite(stream, state, true, state.length, buffer, '', holder.finish); - // doWrite is always async, defer these to save a bit of time + // doWrite is almost always async, defer these to save a bit of time // as the hot path ends with doWrite state.pendingcb++; state.lastBufferedRequest = null; - state.corkedRequestsFree = holder.next; - holder.next = null; + if (holder.next) { + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + state.corkedRequestsFree = new CorkedRequest(state); + } } else { // Slow case, write chunks one-by-one while (entry) { @@ -11910,10 +12048,10 @@ function CorkedRequest(state) { }; } }).call(this,require('_process')) -},{"./_stream_duplex":59,"_process":57,"buffer":44,"core-util-is":45,"events":48,"inherits":51,"process-nextick-args":56,"util-deprecate":71}],64:[function(require,module,exports){ +},{"./_stream_duplex":60,"_process":58,"buffer":45,"buffer-shims":44,"core-util-is":46,"events":49,"inherits":52,"process-nextick-args":57,"util-deprecate":72}],65:[function(require,module,exports){ module.exports = require("./lib/_stream_passthrough.js") -},{"./lib/_stream_passthrough.js":60}],65:[function(require,module,exports){ +},{"./lib/_stream_passthrough.js":61}],66:[function(require,module,exports){ (function (process){ var Stream = (function (){ try { @@ -11933,13 +12071,13 @@ if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) { } }).call(this,require('_process')) -},{"./lib/_stream_duplex.js":59,"./lib/_stream_passthrough.js":60,"./lib/_stream_readable.js":61,"./lib/_stream_transform.js":62,"./lib/_stream_writable.js":63,"_process":57}],66:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":60,"./lib/_stream_passthrough.js":61,"./lib/_stream_readable.js":62,"./lib/_stream_transform.js":63,"./lib/_stream_writable.js":64,"_process":58}],67:[function(require,module,exports){ module.exports = require("./lib/_stream_transform.js") -},{"./lib/_stream_transform.js":62}],67:[function(require,module,exports){ +},{"./lib/_stream_transform.js":63}],68:[function(require,module,exports){ module.exports = require("./lib/_stream_writable.js") -},{"./lib/_stream_writable.js":63}],68:[function(require,module,exports){ +},{"./lib/_stream_writable.js":64}],69:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -12068,7 +12206,7 @@ Stream.prototype.pipe = function(dest, options) { return dest; }; -},{"events":48,"inherits":51,"readable-stream/duplex.js":58,"readable-stream/passthrough.js":64,"readable-stream/readable.js":65,"readable-stream/transform.js":66,"readable-stream/writable.js":67}],69:[function(require,module,exports){ +},{"events":49,"inherits":52,"readable-stream/duplex.js":59,"readable-stream/passthrough.js":65,"readable-stream/readable.js":66,"readable-stream/transform.js":67,"readable-stream/writable.js":68}],70:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -12291,7 +12429,7 @@ function base64DetectIncompleteChar(buffer) { this.charLength = this.charReceived ? 3 : 0; } -},{"buffer":44}],70:[function(require,module,exports){ +},{"buffer":45}],71:[function(require,module,exports){ /** * Expose `toIsoString`. @@ -12332,7 +12470,7 @@ function pad (number) { var n = number.toString(); return n.length === 1 ? '0' + n : n; } -},{}],71:[function(require,module,exports){ +},{}],72:[function(require,module,exports){ (function (global){ /** @@ -12403,14 +12541,14 @@ function config (name) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],72:[function(require,module,exports){ +},{}],73:[function(require,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } -},{}],73:[function(require,module,exports){ +},{}],74:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -13000,4 +13138,4 @@ function hasOwnProperty(obj, prop) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":72,"_process":57,"inherits":51}]},{},[1]); +},{"./support/isBuffer":73,"_process":58,"inherits":52}]},{},[1]);