summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-08-02 08:09:06 +0200
committerRich Trott <rtrott@gmail.com>2019-08-17 00:28:06 -0700
commit6f613d8abb05619e35c828b665a76215861bbf04 (patch)
tree18a904d44299c6564c5c83adc0051076f27bb922 /lib
parente4bbbcc84bd10be1e9e8e66d42542c70c1a02056 (diff)
downloadandroid-node-v8-6f613d8abb05619e35c828b665a76215861bbf04.tar.gz
android-node-v8-6f613d8abb05619e35c828b665a76215861bbf04.tar.bz2
android-node-v8-6f613d8abb05619e35c828b665a76215861bbf04.zip
http,stream: add writableEnded
This is work towards resolving the response.finished confusion and future deprecation. Note that implementation-wise, streams have both an ending and ended state. However, in this case (in order to avoid confusion in user space) writableEnded is equal to writable.ending. The ending vs ended situation is internal state required for internal stream logic. PR-URL: https://github.com/nodejs/node/pull/28934 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/_http_outgoing.js4
-rw-r--r--lib/_stream_duplex.js16
-rw-r--r--lib/_stream_writable.js14
-rw-r--r--lib/internal/http2/compat.js5
4 files changed, 34 insertions, 5 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index f2390a686d..2d2bbaa0e7 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -575,6 +575,10 @@ Object.defineProperty(OutgoingMessage.prototype, 'headersSent', {
get: function() { return !!this._header; }
});
+Object.defineProperty(OutgoingMessage.prototype, 'writableEnded', {
+ get: function() { return this.finished; }
+});
+
const crlf_buf = Buffer.from('\r\n');
OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js
index d20877e921..b96a0439f7 100644
--- a/lib/_stream_duplex.js
+++ b/lib/_stream_duplex.js
@@ -74,7 +74,7 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
// userland will fail
enumerable: false,
get() {
- return this._writableState.highWaterMark;
+ return this._writableState && this._writableState.highWaterMark;
}
});
@@ -94,7 +94,7 @@ Object.defineProperty(Duplex.prototype, 'writableLength', {
// userland will fail
enumerable: false,
get() {
- return this._writableState.length;
+ return this._writableState && this._writableState.length;
}
});
@@ -104,7 +104,17 @@ Object.defineProperty(Duplex.prototype, 'writableFinished', {
// userland will fail
enumerable: false,
get() {
- return this._writableState.finished;
+ return this._writableState ? this._writableState.finished : false;
+ }
+});
+
+Object.defineProperty(Duplex.prototype, 'writableEnded', {
+ // Making it explicit this property is not enumerable
+ // because otherwise some prototype manipulation in
+ // userland will fail
+ enumerable: false,
+ get() {
+ return this._writableState ? this._writableState.ending : false;
}
});
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
index 315360ca6b..47a9bb208c 100644
--- a/lib/_stream_writable.js
+++ b/lib/_stream_writable.js
@@ -352,13 +352,23 @@ function decodeChunk(state, chunk, encoding) {
return chunk;
}
+Object.defineProperty(Writable.prototype, 'writableEnded', {
+ // Making it explicit this property is not enumerable
+ // because otherwise some prototype manipulation in
+ // userland will fail
+ enumerable: false,
+ get: function() {
+ return this._writableState ? this._writableState.ending : false;
+ }
+});
+
Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
// Making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get: function() {
- return this._writableState.highWaterMark;
+ return this._writableState && this._writableState.highWaterMark;
}
});
@@ -711,7 +721,7 @@ Object.defineProperty(Writable.prototype, 'writableFinished', {
// userland will fail
enumerable: false,
get() {
- return this._writableState.finished;
+ return this._writableState ? this._writableState.finished : false;
}
});
diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js
index b435705854..9cf19250a8 100644
--- a/lib/internal/http2/compat.js
+++ b/lib/internal/http2/compat.js
@@ -454,6 +454,11 @@ class Http2ServerResponse extends Stream {
return this.headersSent;
}
+ get writableEnded() {
+ const state = this[kState];
+ return state.ending;
+ }
+
get finished() {
const stream = this[kStream];
return stream.destroyed ||