@@ -353,4 +353,42 @@ async function testAsyncValidation() {
353353 assert . strictEqual ( typeof transform . transform , 'function' ) ;
354354}
355355
356+ // Writer methods validate options.signal on every surface
357+ {
358+ const { writer } = push ( ) ;
359+ assert . throws ( ( ) => writer . write ( 'a' , { signal : 'bad' } ) ,
360+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
361+ assert . throws ( ( ) => writer . writev ( [ 'a' ] , { signal : { } } ) ,
362+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
363+ assert . throws ( ( ) => writer . end ( { signal : 'bad' } ) ,
364+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
365+ // A valid signal and an absent signal are both accepted.
366+ writer . write ( 'a' , { signal : new AbortController ( ) . signal } ) ;
367+ writer . write ( 'b' ) ;
368+ writer . endSync ( ) ;
369+ }
370+
371+ {
372+ const { writer } = broadcast ( ) ;
373+ assert . throws ( ( ) => writer . write ( 'a' , { signal : 'bad' } ) ,
374+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
375+ assert . throws ( ( ) => writer . writev ( [ 'a' ] , { signal : { } } ) ,
376+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
377+ assert . throws ( ( ) => writer . end ( { signal : 'bad' } ) ,
378+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
379+ writer . endSync ( ) ;
380+ }
381+
382+ {
383+ const { Writable } = require ( 'stream' ) ;
384+ const { fromWritable } = require ( 'stream/iter' ) ;
385+ const writer = fromWritable ( new Writable ( { write ( chunk , enc , cb ) { cb ( ) ; } } ) ) ;
386+ assert . throws ( ( ) => writer . write ( 'a' , { signal : 'bad' } ) ,
387+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
388+ assert . throws ( ( ) => writer . writev ( [ 'a' ] , { signal : { } } ) ,
389+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
390+ assert . throws ( ( ) => writer . end ( { signal : 'bad' } ) ,
391+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
392+ }
393+
356394testAsyncValidation ( ) . then ( common . mustCall ( ) ) ;
0 commit comments