stream,net: slightly more consistent typechecking
-
stream: remove
undefined
checkvalidChunk
allowedundefined
as a chunk in object mode; however, this was redundant, since:-
validChunk()
is only used by.write()
- If the
validChunk()
check passes forundefined
,.write()
callswriteOrBuffer()
- If
writeOrBuffer()
does not receive a Buffer, it callsdecodeChunk()
-
decodeChunk()
ignoresundefined
because it checkstypeof chunk === 'string'
- After that call,
chunk.length
is accessed, which throws an error ifchunk
isundefined
.
-
This “fixes” a bug in the sense that
state.pendingcb
is no longer incremented for write attempts that fail like this. -
-
net: remove Socket.prototype.write
This is superfluous now that typechecking in
net
andstream
are aligned.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included ( test-net-connect-buffer
checks the error forundefined
) -
commit message follows commit guidelines
Affected core subsystem(s)
net, stream