Skip to content

Commit

Permalink
stream: remove undefined check
Browse files Browse the repository at this point in the history
`validChunk` allowed `undefined` as a chunk in object mode; however,
this was redundant, since:

- `validChunk()` is only used by `.write()`
- If the `validChunk()` check passes for `undefined`, `.write()`
  calls `writeOrBuffer()`
- If `writeOrBuffer()` does not receive a Buffer, it calls
  `decodeChunk()`
  - `decodeChunk()` ignores `undefined` because it checks
    `typeof chunk === 'string'`
  - After that call, `chunk.length` is accessed, which throws an
    error if `chunk` is undefined`.

This “fixes” a bug in the sense that `state.pendingcb` is no longer
incremented for write attempts that fail like this.

PR-URL: #17644
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
  • Loading branch information
addaleax authored and MylesBorins committed Jan 9, 2018
1 parent 6d9b1e4 commit 757e685
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ function validChunk(stream, state, chunk, cb) {

if (chunk === null) {
er = new errors.TypeError('ERR_STREAM_NULL_VALUES');
} else if (typeof chunk !== 'string' &&
chunk !== undefined &&
!state.objectMode) {
} else if (typeof chunk !== 'string' && !state.objectMode) {
er = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'chunk',
['string', 'Buffer']);
}
Expand Down

0 comments on commit 757e685

Please sign in to comment.