@@ -31,44 +31,35 @@ const stream = fs.createWriteStream(common.tmpDir + '/out', {
3131} ) ;
3232const err = new Error ( 'BAM' ) ;
3333
34- const write = fs . write ;
34+ const writeBuffer = process . binding ( 'fs' ) . writeBuffer ;
3535let writeCalls = 0 ;
36- fs . write = function ( ) {
36+ process . binding ( 'fs' ) . writeBuffer = common . mustCall ( function ( ) {
3737 switch ( writeCalls ++ ) {
3838 case 0 :
39- console . error ( 'first write' ) ;
4039 // first time is ok.
41- return write . apply ( fs , arguments ) ;
40+ return writeBuffer . apply ( null , arguments ) ;
4241 case 1 :
4342 // then it breaks
44- console . error ( 'second write' ) ;
45- const cb = arguments [ arguments . length - 1 ] ;
43+ const req = arguments [ arguments . length - 1 ] ;
4644 return process . nextTick ( function ( ) {
47- cb ( err ) ;
45+ req . oncomplete ( err ) ;
4846 } ) ;
49- default :
50- // and should not be called again!
51- throw new Error ( 'BOOM!' ) ;
5247 }
53- } ;
48+ } , 2 ) ;
5449
55- fs . close = common . mustCall ( function ( fd_ , cb ) {
56- console . error ( 'fs.close' , fd_ , stream . fd ) ;
57- assert . strictEqual ( fd_ , stream . fd ) ;
58- process . nextTick ( cb ) ;
50+ process . binding ( 'fs' ) . close = common . mustCall ( function ( fd , req ) {
51+ assert . strictEqual ( fd , stream . fd ) ;
52+ process . nextTick ( req . oncomplete . bind ( req ) ) ;
5953} ) ;
6054
6155stream . on ( 'error' , common . mustCall ( function ( err_ ) {
62- console . error ( 'error handler' ) ;
6356 assert . strictEqual ( stream . fd , null ) ;
6457 assert . strictEqual ( err_ , err ) ;
6558} ) ) ;
6659
6760
6861stream . write ( Buffer . allocUnsafe ( 256 ) , function ( ) {
69- console . error ( 'first cb' ) ;
7062 stream . write ( Buffer . allocUnsafe ( 256 ) , common . mustCall ( function ( err_ ) {
71- console . error ( 'second cb' ) ;
7263 assert . strictEqual ( err_ , err ) ;
7364 } ) ) ;
7465} ) ;
0 commit comments