• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const net = require('net');
4const assert = require('assert');
5const socket = net.Stream({ highWaterMark: 0 });
6
7// Make sure that anything besides a buffer or a string throws.
8socket.on('error', common.mustNotCall());
9assert.throws(() => {
10  socket.write(null);
11}, {
12  code: 'ERR_STREAM_NULL_VALUES',
13  name: 'TypeError',
14  message: 'May not write null values to stream'
15});
16
17[
18  true,
19  false,
20  undefined,
21  1,
22  1.0,
23  +Infinity,
24  -Infinity,
25  [],
26  {},
27].forEach((value) => {
28  // We need to check the callback since 'error' will only
29  // be emitted once per instance.
30  assert.throws(() => {
31    socket.write(value);
32  }, {
33    code: 'ERR_INVALID_ARG_TYPE',
34    name: 'TypeError',
35    message: 'The "chunk" argument must be of type string or an instance of ' +
36              `Buffer or Uint8Array.${common.invalidArgTypeHelper(value)}`
37  });
38});
39