11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst stream = require('stream'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciclass MyWritable extends stream.Writable { 81cb0ef41Sopenharmony_ci constructor(options) { 91cb0ef41Sopenharmony_ci super({ autoDestroy: false, ...options }); 101cb0ef41Sopenharmony_ci } 111cb0ef41Sopenharmony_ci _write(chunk, encoding, callback) { 121cb0ef41Sopenharmony_ci assert.notStrictEqual(chunk, null); 131cb0ef41Sopenharmony_ci callback(); 141cb0ef41Sopenharmony_ci } 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci{ 181cb0ef41Sopenharmony_ci const m = new MyWritable({ objectMode: true }); 191cb0ef41Sopenharmony_ci m.on('error', common.mustNotCall()); 201cb0ef41Sopenharmony_ci assert.throws(() => { 211cb0ef41Sopenharmony_ci m.write(null); 221cb0ef41Sopenharmony_ci }, { 231cb0ef41Sopenharmony_ci code: 'ERR_STREAM_NULL_VALUES' 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci{ 281cb0ef41Sopenharmony_ci const m = new MyWritable(); 291cb0ef41Sopenharmony_ci m.on('error', common.mustNotCall()); 301cb0ef41Sopenharmony_ci assert.throws(() => { 311cb0ef41Sopenharmony_ci m.write(false); 321cb0ef41Sopenharmony_ci }, { 331cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE' 341cb0ef41Sopenharmony_ci }); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci{ // Should not throw. 381cb0ef41Sopenharmony_ci const m = new MyWritable({ objectMode: true }); 391cb0ef41Sopenharmony_ci m.write(false, assert.ifError); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci{ // Should not throw. 431cb0ef41Sopenharmony_ci const m = new MyWritable({ objectMode: true }).on('error', (e) => { 441cb0ef41Sopenharmony_ci assert.ifError(e || new Error('should not get here')); 451cb0ef41Sopenharmony_ci }); 461cb0ef41Sopenharmony_ci m.write(false, assert.ifError); 471cb0ef41Sopenharmony_ci} 48