|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +constcommon=require('../common'); |
| 4 | +constassert=require('assert'); |
| 5 | +const{ execFile }=require('child_process'); |
| 6 | +constfixtures=require('../common/fixtures'); |
| 7 | + |
| 8 | +{ |
| 9 | +// Verify exit behavior is unchanged |
| 10 | +constfixture=fixtures.path('uncaught-exceptions','uncaught-monitor1.js'); |
| 11 | +execFile( |
| 12 | +process.execPath, |
| 13 | +[fixture], |
| 14 | +common.mustCall((err,stdout,stderr)=>{ |
| 15 | +assert.strictEqual(err.code,1); |
| 16 | +assert.strictEqual(Object.getPrototypeOf(err).name,'Error'); |
| 17 | +assert.strictEqual(stdout,'Monitored: Shall exit\n'); |
| 18 | +consterrLines=stderr.trim().split(/[\r\n]+/); |
| 19 | +consterrLine=errLines.find((l)=>/^Error/.exec(l)); |
| 20 | +assert.strictEqual(errLine,'Error: Shall exit'); |
| 21 | +}) |
| 22 | +); |
| 23 | +} |
| 24 | + |
| 25 | +{ |
| 26 | +// Verify exit behavior is unchanged |
| 27 | +constfixture=fixtures.path('uncaught-exceptions','uncaught-monitor2.js'); |
| 28 | +execFile( |
| 29 | +process.execPath, |
| 30 | +[fixture], |
| 31 | +common.mustCall((err,stdout,stderr)=>{ |
| 32 | +assert.strictEqual(err.code,7); |
| 33 | +assert.strictEqual(Object.getPrototypeOf(err).name,'Error'); |
| 34 | +assert.strictEqual(stdout,'Monitored: Shall exit, will throw now\n'); |
| 35 | +consterrLines=stderr.trim().split(/[\r\n]+/); |
| 36 | +consterrLine=errLines.find((l)=>/^ReferenceError/.exec(l)); |
| 37 | +assert.strictEqual( |
| 38 | +errLine, |
| 39 | +'ReferenceError: missingFunction is not defined' |
| 40 | +); |
| 41 | +}) |
| 42 | +); |
| 43 | +} |
| 44 | + |
| 45 | +consttheErr=newError('MyError'); |
| 46 | + |
| 47 | +process.on( |
| 48 | +'uncaughtExceptionMonitor', |
| 49 | +common.mustCall((err,origin)=>{ |
| 50 | +assert.strictEqual(err,theErr); |
| 51 | +assert.strictEqual(origin,'uncaughtException'); |
| 52 | +},2) |
| 53 | +); |
| 54 | + |
| 55 | +process.on('uncaughtException',common.mustCall((err,origin)=>{ |
| 56 | +assert.strictEqual(origin,'uncaughtException'); |
| 57 | +assert.strictEqual(err,theErr); |
| 58 | +})); |
| 59 | + |
| 60 | +process.nextTick(common.mustCall(()=>{ |
| 61 | +// Test with uncaughtExceptionCaptureCallback installed |
| 62 | +process.setUncaughtExceptionCaptureCallback(common.mustCall( |
| 63 | +(err)=>assert.strictEqual(err,theErr)) |
| 64 | +); |
| 65 | + |
| 66 | +throwtheErr; |
| 67 | +})); |
| 68 | + |
| 69 | +throwtheErr; |
0 commit comments