Skip to content

stream,net: slightly more consistent typechecking

  • stream: remove undefined check

    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.

  • net: remove Socket.prototype.write

    This is superfluous now that typechecking in net and stream are aligned.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included (test-net-connect-buffer checks the error for undefined)
  • commit message follows commit guidelines
Affected core subsystem(s)

net, stream

Merge request reports

Loading