diff options
-rw-r--r-- | doc/api/stream.md | 19 | ||||
-rw-r--r-- | lib/_stream_duplex.js | 16 | ||||
-rw-r--r-- | lib/_stream_readable.js | 14 | ||||
-rw-r--r-- | lib/_stream_writable.js | 13 | ||||
-rw-r--r-- | lib/_tls_legacy.js | 2 | ||||
-rw-r--r-- | lib/_tls_wrap.js | 2 | ||||
-rw-r--r-- | lib/net.js | 6 | ||||
-rw-r--r-- | test/parallel/test-https-truncate.js | 2 | ||||
-rw-r--r-- | test/parallel/test-stream-readable-flow-recursion.js | 2 | ||||
-rw-r--r-- | test/parallel/test-stream2-push.js | 2 | ||||
-rw-r--r-- | test/parallel/test-stream2-read-sync-stack.js | 4 | ||||
-rw-r--r-- | test/parallel/test-stream2-transform.js | 2 | ||||
-rw-r--r-- | test/parallel/test-stream2-unpipe-leak.js | 2 | ||||
-rw-r--r-- | test/parallel/test-stream2-writable.js | 2 | ||||
-rw-r--r-- | test/pummel/test-https-no-reader.js | 2 | ||||
-rw-r--r-- | test/pummel/test-net-throttle.js | 2 |
16 files changed, 75 insertions, 17 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md index dc74df7720..741f105464 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -441,10 +441,18 @@ See also: [`writable.cork()`][]. <!-- YAML added: v9.3.0 --> - Return the value of `highWaterMark` passed when constructing this `Writable`. +##### writable.writableLength +<!-- YAML +added: REPLACEME +--> + +This property contains the number of bytes (or objects) in the queue +ready to be written. The value provides introspection data regarding +the status of the `highWaterMark`. + ##### writable.write(chunk[, encoding][, callback]) <!-- YAML added: v0.9.4 @@ -945,6 +953,15 @@ event will also be emitted. *Note*: Calling [`stream.read([size])`][stream-read] after the [`'end'`][] event has been emitted will return `null`. No runtime error will be raised. +##### readable.readableLength +<!-- YAML +added: REPLACEME +--> + +This property contains the number of bytes (or objects) in the queue +ready to be read. The value provides introspection data regarding +the status of the `highWaterMark`. + ##### readable.resume() <!-- YAML added: v0.9.4 diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index e99d246396..288b8b538c 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -69,7 +69,7 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { // because otherwise some prototype manipulation in // userland will fail enumerable: false, - get: function() { + get() { return this._writableState.highWaterMark; } }); @@ -84,6 +84,16 @@ Object.defineProperty(Duplex.prototype, 'writableBuffer', { } }); +Object.defineProperty(Duplex.prototype, 'writableLength', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get() { + return this._writableState.length; + } +}); + // the no-half-open enforcer function onend() { // if we allow half-open state, or if the writable side ended, @@ -101,6 +111,10 @@ function onEndNT(self) { } Object.defineProperty(Duplex.prototype, 'destroyed', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, get() { if (this._readableState === undefined || this._writableState === undefined) { diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 2653d3835d..21598efa65 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -159,6 +159,10 @@ function Readable(options) { } Object.defineProperty(Readable.prototype, 'destroyed', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, get() { if (this._readableState === undefined) { return false; @@ -953,6 +957,16 @@ Object.defineProperty(Readable.prototype, 'readableFlowing', { // exposed for testing purposes only. Readable._fromList = fromList; +Object.defineProperty(Readable.prototype, 'readableLength', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get() { + return this._readableState.length; + } +}); + // Pluck off n bytes from an array of buffers. // Length is the combined lengths of all the buffers in the list. // This function is designed to be inlinable, so please take care when making diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 97fbebdd66..549bff1599 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -583,6 +583,15 @@ Writable.prototype.end = function(chunk, encoding, cb) { endWritable(this, state, cb); }; +Object.defineProperty(Writable.prototype, 'writableLength', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get() { + return this._writableState.length; + } +}); function needFinish(state) { return (state.ending && @@ -657,6 +666,10 @@ function onCorkedFinish(corkReq, state, err) { } Object.defineProperty(Writable.prototype, 'destroyed', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, get() { if (this._writableState === undefined) { return false; diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js index d65da58e8c..c2bbb973cf 100644 --- a/lib/_tls_legacy.js +++ b/lib/_tls_legacy.js @@ -531,7 +531,7 @@ function CleartextStream(pair, options) { self._reading = false; }, readStart: function() { - if (self._reading && self._readableState.length > 0) return; + if (self._reading && self.readableLength > 0) return; self._reading = true; self.read(0); if (self._opposite.readable) self._opposite.read(0); diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index d1764ce38d..3a1b8753f0 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -267,7 +267,7 @@ function initRead(tls, wrapped) { return; // Socket already has some buffered data - emulate receiving it - if (wrapped && wrapped._readableState && wrapped._readableState.length) { + if (wrapped && wrapped.readableLength) { var buf; while ((buf = wrapped.read()) !== null) tls._handle.receive(buf); diff --git a/lib/net.js b/lib/net.js index aa27e70050..994c1e3390 100644 --- a/lib/net.js +++ b/lib/net.js @@ -473,7 +473,7 @@ Object.defineProperty(Socket.prototype, 'readyState', { Object.defineProperty(Socket.prototype, 'bufferSize', { get: function() { if (this._handle) { - return this._handle.writeQueueSize + this._writableState.length; + return this._handle.writeQueueSize + this.writableLength; } } }); @@ -519,7 +519,7 @@ function maybeDestroy(socket) { !socket.writable && !socket.destroyed && !socket.connecting && - !socket._writableState.length) { + !socket.writableLength) { socket.destroy(); } } @@ -627,7 +627,7 @@ function onread(nread, buffer) { // `end` -> `close` self.push(null); - if (self._readableState.length === 0) { + if (self.readableLength === 0) { self.readable = false; maybeDestroy(self); } diff --git a/test/parallel/test-https-truncate.js b/test/parallel/test-https-truncate.js index c549da1571..9d2679ee9a 100644 --- a/test/parallel/test-https-truncate.js +++ b/test/parallel/test-https-truncate.js @@ -57,7 +57,7 @@ function httpsTest() { const test = common.mustCall(function(res) { res.on('end', common.mustCall(function() { - assert.strictEqual(res._readableState.length, 0); + assert.strictEqual(res.readableLength, 0); assert.strictEqual(bytes, data.length); })); diff --git a/test/parallel/test-stream-readable-flow-recursion.js b/test/parallel/test-stream-readable-flow-recursion.js index 744298946c..43b8103eb6 100644 --- a/test/parallel/test-stream-readable-flow-recursion.js +++ b/test/parallel/test-stream-readable-flow-recursion.js @@ -70,7 +70,7 @@ process.on('exit', function(code) { // we pushed up the high water mark assert.strictEqual(stream.readableHighWaterMark, 8192); // length is 0 right now, because we pulled it all out. - assert.strictEqual(stream._readableState.length, 0); + assert.strictEqual(stream.readableLength, 0); assert(!code); assert.strictEqual(depth, 0); console.log('ok'); diff --git a/test/parallel/test-stream2-push.js b/test/parallel/test-stream2-push.js index 21dc303695..cc4dce4a87 100644 --- a/test/parallel/test-stream2-push.js +++ b/test/parallel/test-stream2-push.js @@ -48,7 +48,7 @@ stream.on('end', function() { source.on('data', function(chunk) { const ret = stream.push(chunk); - console.error('data', stream._readableState.length); + console.error('data', stream.readableLength); if (!ret) readStop(); }); diff --git a/test/parallel/test-stream2-read-sync-stack.js b/test/parallel/test-stream2-read-sync-stack.js index 3f70588946..3fa84547fe 100644 --- a/test/parallel/test-stream2-read-sync-stack.js +++ b/test/parallel/test-stream2-read-sync-stack.js @@ -36,8 +36,8 @@ r._read = function(n) { }; r.on('readable', function onReadable() { - if (!(r._readableState.length % 256)) - console.error('readable', r._readableState.length); + if (!(r.readableLength % 256)) + console.error('readable', r.readableLength); r.read(N * 2); }); diff --git a/test/parallel/test-stream2-transform.js b/test/parallel/test-stream2-transform.js index 16a0523994..d085926542 100644 --- a/test/parallel/test-stream2-transform.js +++ b/test/parallel/test-stream2-transform.js @@ -43,7 +43,7 @@ const Transform = require('_stream_transform'); } tx.end(); - assert.strictEqual(tx._readableState.length, 10); + assert.strictEqual(tx.readableLength, 10); assert.strictEqual(transformed, 10); assert.strictEqual(tx._transformState.writechunk.length, 5); assert.deepStrictEqual(tx.writableBuffer.map(function(c) { diff --git a/test/parallel/test-stream2-unpipe-leak.js b/test/parallel/test-stream2-unpipe-leak.js index 5c19be061f..52c16368f5 100644 --- a/test/parallel/test-stream2-unpipe-leak.js +++ b/test/parallel/test-stream2-unpipe-leak.js @@ -68,6 +68,6 @@ console.error(src._readableState); process.on('exit', function() { src.readableBuffer.length = 0; console.error(src._readableState); - assert(src._readableState.length >= src.readableHighWaterMark); + assert(src.readableLength >= src.readableHighWaterMark); console.log('ok'); }); diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 712440368c..6d4f5e9f7e 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -110,7 +110,7 @@ for (let i = 0; i < chunks.length; i++) { } while (ret !== false && i < chunks.length); if (i < chunks.length) { - assert(tw._writableState.length >= 50); + assert(tw.writableLength >= 50); tw.once('drain', W); } else { tw.end(); diff --git a/test/pummel/test-https-no-reader.js b/test/pummel/test-https-no-reader.js index 985d888e6d..ad0b56c1f3 100644 --- a/test/pummel/test-https-no-reader.js +++ b/test/pummel/test-https-no-reader.js @@ -54,7 +54,7 @@ server.listen(common.PORT, function() { setTimeout(function() { // Read buffer should be somewhere near high watermark // (i.e. should not leak) - assert(res._readableState.length < 100 * 1024); + assert(res.readableLength < 100 * 1024); process.exit(0); }, 2000); }); diff --git a/test/pummel/test-net-throttle.js b/test/pummel/test-net-throttle.js index c273853362..ea48aa74d2 100644 --- a/test/pummel/test-net-throttle.js +++ b/test/pummel/test-net-throttle.js @@ -40,7 +40,7 @@ const server = net.createServer(function(connection) { assert.strictEqual(false, connection.write(body.slice(2 * part_N, N))); console.log(`bufferSize: ${connection.bufferSize}`, 'expecting', N); assert.ok(0 <= connection.bufferSize && - connection._writableState.length <= N); + connection.writableLength <= N); connection.end(); }); |