|
1 | 1 | 'use strict'; |
2 | | -varcommon=require('../common'); |
3 | | -varassert=require('assert'); |
4 | | -varfs=require('fs'); |
| 2 | +constcommon=require('../common'); |
| 3 | +constassert=require('assert'); |
| 4 | +constfs=require('fs'); |
5 | 5 |
|
6 | | -varstream=fs.createReadStream(__filename,{ |
| 6 | +conststream=fs.createReadStream(__filename,{ |
7 | 7 | bufferSize: 64 |
8 | 8 | }); |
9 | | -varerr=newError('BAM'); |
| 9 | +consterr=newError('BAM'); |
10 | 10 |
|
11 | | -stream.on('error',common.mustCall(functionerrorHandler(err_){ |
12 | | -console.error('error event'); |
13 | | -process.nextTick(function(){ |
14 | | -assert.equal(stream.fd,null); |
15 | | -assert.equal(err_,err); |
16 | | -}); |
| 11 | +stream.on('error',common.mustCall((err_)=>{ |
| 12 | +process.nextTick(common.mustCall(()=>{ |
| 13 | +assert.strictEqual(stream.fd,null); |
| 14 | +assert.strictEqual(err_,err); |
| 15 | +})); |
17 | 16 | })); |
18 | 17 |
|
19 | | -fs.close=common.mustCall(function(fd_,cb){ |
20 | | -assert.equal(fd_,stream.fd); |
| 18 | +fs.close=common.mustCall((fd_,cb)=>{ |
| 19 | +assert.strictEqual(fd_,stream.fd); |
21 | 20 | process.nextTick(cb); |
22 | 21 | }); |
23 | 22 |
|
24 | | -varread=fs.read; |
| 23 | +constread=fs.read; |
25 | 24 | fs.read=function(){ |
26 | 25 | // first time is ok. |
27 | 26 | read.apply(fs,arguments); |
28 | 27 | // then it breaks |
29 | | -fs.read=function(){ |
30 | | -varcb=arguments[arguments.length-1]; |
31 | | -process.nextTick(function(){ |
| 28 | +fs.read=common.mustCall(function(){ |
| 29 | +constcb=arguments[arguments.length-1]; |
| 30 | +process.nextTick(()=>{ |
32 | 31 | cb(err); |
33 | 32 | }); |
34 | 33 | // and should not be called again! |
35 | | -fs.read=function(){ |
| 34 | +fs.read=()=>{ |
36 | 35 | thrownewError('BOOM!'); |
37 | 36 | }; |
38 | | -}; |
| 37 | +}); |
39 | 38 | }; |
40 | 39 |
|
41 | | -stream.on('data',function(buf){ |
42 | | -stream.on('data',common.fail);// no more 'data' events should follow |
| 40 | +stream.on('data',(buf)=>{ |
| 41 | +stream.on('data',()=>common.fail("no more 'data' events should follow")); |
43 | 42 | }); |
0 commit comments