Skip to content

Commit

Permalink
stream: avoid writing to writable
Browse files Browse the repository at this point in the history
A remainder from a previous refactoring.

Refs: #31197

PR-URL: #31805
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
ronag committed Feb 17, 2020
1 parent 5bef2cc commit 85c6fcd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ function endWritable(stream, state, cb) {
onFinished(stream, state, cb);
}
state.ended = true;
stream.writable = false;
}

function onCorkedFinish(corkReq, state, err) {
Expand Down Expand Up @@ -741,7 +740,7 @@ ObjectDefineProperties(Writable.prototype, {
get() {
const w = this._writableState;
if (!w) return false;
if (w.writable !== undefined) return w.writable;
if (w.writable !== undefined) return w.writable && !w.ended;
return Boolean(!w.destroyed && !w.errored && !w.ending);
},
set(val) {
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-stream-writable-ended-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ const writable = new stream.Writable();

writable._write = (chunk, encoding, cb) => {
assert.strictEqual(writable._writableState.ended, false);
assert.strictEqual(writable._writableState.writable, undefined);
assert.strictEqual(writable.writableEnded, false);
cb();
};

assert.strictEqual(writable._writableState.ended, false);
assert.strictEqual(writable._writableState.writable, undefined);
assert.strictEqual(writable.writable, true);
assert.strictEqual(writable.writableEnded, false);

writable.end('testing ended state', common.mustCall(() => {
assert.strictEqual(writable._writableState.ended, true);
assert.strictEqual(writable._writableState.writable, undefined);
assert.strictEqual(writable.writable, false);
assert.strictEqual(writable.writableEnded, true);
}));

assert.strictEqual(writable._writableState.ended, true);
assert.strictEqual(writable._writableState.writable, undefined);
assert.strictEqual(writable.writable, false);
assert.strictEqual(writable.writableEnded, true);

0 comments on commit 85c6fcd

Please sign in to comment.