mirror of https://github.com/lukechilds/node.git
Browse Source
Change var to const/let. Simplify test-timers-uncaught-exception. Backport-PR-URL: https://github.com/nodejs/node/pull/12401 PR-URL: https://github.com/nodejs/node/pull/10524 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>v6.x
committed by
Myles Borins
4 changed files with 13 additions and 36 deletions
@ -1,40 +1,19 @@ |
|||||
'use strict'; |
'use strict'; |
||||
require('../common'); |
const common = require('../common'); |
||||
const assert = require('assert'); |
const assert = require('assert'); |
||||
|
|
||||
let exceptions = 0; |
const errorMsg = 'BAM!'; |
||||
let timer1 = 0; |
|
||||
let timer2 = 0; |
|
||||
|
|
||||
// the first timer throws...
|
// the first timer throws...
|
||||
console.error('set first timer'); |
setTimeout(common.mustCall(function() { |
||||
setTimeout(function() { |
throw new Error(errorMsg); |
||||
console.error('first timer'); |
}), 1); |
||||
timer1++; |
|
||||
throw new Error('BAM!'); |
|
||||
}, 100); |
|
||||
|
|
||||
// ...but the second one should still run
|
// ...but the second one should still run
|
||||
console.error('set second timer'); |
setTimeout(common.mustCall(function() {}), 1); |
||||
setTimeout(function() { |
|
||||
console.error('second timer'); |
|
||||
assert.strictEqual(timer1, 1); |
|
||||
timer2++; |
|
||||
}, 100); |
|
||||
|
|
||||
function uncaughtException(err) { |
function uncaughtException(err) { |
||||
console.error('uncaught handler'); |
assert.strictEqual(err.message, errorMsg); |
||||
assert.strictEqual(err.message, 'BAM!'); |
|
||||
exceptions++; |
|
||||
} |
} |
||||
process.on('uncaughtException', uncaughtException); |
|
||||
|
|
||||
let exited = false; |
process.on('uncaughtException', common.mustCall(uncaughtException)); |
||||
process.on('exit', function() { |
|
||||
assert(!exited); |
|
||||
exited = true; |
|
||||
process.removeListener('uncaughtException', uncaughtException); |
|
||||
assert.strictEqual(exceptions, 1); |
|
||||
assert.strictEqual(timer1, 1); |
|
||||
assert.strictEqual(timer2, 1); |
|
||||
}); |
|
||||
|
Loading…
Reference in new issue