11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst net = require('net');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst socket = net.Stream({ highWaterMark: 0 });
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci// Make sure that anything besides a buffer or a string throws.
81cb0ef41Sopenharmony_cisocket.on('error', common.mustNotCall());
91cb0ef41Sopenharmony_ciassert.throws(() => {
101cb0ef41Sopenharmony_ci  socket.write(null);
111cb0ef41Sopenharmony_ci}, {
121cb0ef41Sopenharmony_ci  code: 'ERR_STREAM_NULL_VALUES',
131cb0ef41Sopenharmony_ci  name: 'TypeError',
141cb0ef41Sopenharmony_ci  message: 'May not write null values to stream'
151cb0ef41Sopenharmony_ci});
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci[
181cb0ef41Sopenharmony_ci  true,
191cb0ef41Sopenharmony_ci  false,
201cb0ef41Sopenharmony_ci  undefined,
211cb0ef41Sopenharmony_ci  1,
221cb0ef41Sopenharmony_ci  1.0,
231cb0ef41Sopenharmony_ci  +Infinity,
241cb0ef41Sopenharmony_ci  -Infinity,
251cb0ef41Sopenharmony_ci  [],
261cb0ef41Sopenharmony_ci  {},
271cb0ef41Sopenharmony_ci].forEach((value) => {
281cb0ef41Sopenharmony_ci  const socket = net.Stream({ highWaterMark: 0 });
291cb0ef41Sopenharmony_ci  // We need to check the callback since 'error' will only
301cb0ef41Sopenharmony_ci  // be emitted once per instance.
311cb0ef41Sopenharmony_ci  assert.throws(() => {
321cb0ef41Sopenharmony_ci    socket.write(value);
331cb0ef41Sopenharmony_ci  }, {
341cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
351cb0ef41Sopenharmony_ci    name: 'TypeError',
361cb0ef41Sopenharmony_ci    message: 'The "chunk" argument must be of type string or an instance of ' +
371cb0ef41Sopenharmony_ci              `Buffer or Uint8Array.${common.invalidArgTypeHelper(value)}`
381cb0ef41Sopenharmony_ci  });
391cb0ef41Sopenharmony_ci});
40