• 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  const socket = net.Stream({ highWaterMark: 0 });
29  // We need to check the callback since 'error' will only
30  // be emitted once per instance.
31  assert.throws(() => {
32    socket.write(value);
33  }, {
34    code: 'ERR_INVALID_ARG_TYPE',
35    name: 'TypeError',
36    message: 'The "chunk" argument must be of type string or an instance of ' +
37              `Buffer or Uint8Array.${common.invalidArgTypeHelper(value)}`
38  });
39});
40