2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-12-23 16:02:12 -08:00
|
|
|
require('../common');
|
2012-01-29 23:30:13 +01:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
var exceptions = 0;
|
|
|
|
var timer1 = 0;
|
|
|
|
var timer2 = 0;
|
|
|
|
|
|
|
|
// the first timer throws...
|
2013-02-06 17:26:18 -08:00
|
|
|
console.error('set first timer');
|
2012-01-29 23:30:13 +01:00
|
|
|
setTimeout(function() {
|
2013-02-06 17:26:18 -08:00
|
|
|
console.error('first timer');
|
2012-01-29 23:30:13 +01:00
|
|
|
timer1++;
|
|
|
|
throw new Error('BAM!');
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
// ...but the second one should still run
|
2013-02-06 17:26:18 -08:00
|
|
|
console.error('set second timer');
|
2012-01-29 23:30:13 +01:00
|
|
|
setTimeout(function() {
|
2013-02-06 17:26:18 -08:00
|
|
|
console.error('second timer');
|
2012-01-29 23:30:13 +01:00
|
|
|
assert.equal(timer1, 1);
|
|
|
|
timer2++;
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
function uncaughtException(err) {
|
2013-02-06 17:26:18 -08:00
|
|
|
console.error('uncaught handler');
|
2012-01-29 23:30:13 +01:00
|
|
|
assert.equal(err.message, 'BAM!');
|
|
|
|
exceptions++;
|
|
|
|
}
|
|
|
|
process.on('uncaughtException', uncaughtException);
|
|
|
|
|
2013-02-06 17:26:18 -08:00
|
|
|
var exited = false;
|
2012-01-29 23:30:13 +01:00
|
|
|
process.on('exit', function() {
|
2013-02-06 17:26:18 -08:00
|
|
|
assert(!exited);
|
|
|
|
exited = true;
|
2012-01-29 23:30:13 +01:00
|
|
|
process.removeListener('uncaughtException', uncaughtException);
|
|
|
|
assert.equal(exceptions, 1);
|
|
|
|
assert.equal(timer1, 1);
|
|
|
|
assert.equal(timer2, 1);
|
|
|
|
});
|