mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
cda1a38426
Change process._tickCallback so that if a callback throws an error but there are other callbacks after it, we indicate that process._tickCallback needs to be ran again. Currently, if a callback in process._tickCallback throws an error, and that error is caught by an uncaughtException handler and process.nextTick is never called again, then any other callbacks already added to the nextTickQueue won't be called again. Updated the next-tick-errors test to catch this scenario.
37 lines
907 B
JavaScript
37 lines
907 B
JavaScript
common = require("../common");
|
|
assert = common.assert
|
|
|
|
var order = [],
|
|
exceptionHandled = false;
|
|
|
|
// This nextTick function will throw an error. It should only be called once.
|
|
// When it throws an error, it should still get removed from the queue.
|
|
process.nextTick(function() {
|
|
order.push('A');
|
|
// cause an error
|
|
what();
|
|
});
|
|
|
|
// This nextTick function should remain in the queue when the first one
|
|
// is removed. It should be called if the error in the first one is
|
|
// caught (which we do in this test).
|
|
process.nextTick(function() {
|
|
order.push('C');
|
|
});
|
|
|
|
process.addListener('uncaughtException', function() {
|
|
if (!exceptionHandled) {
|
|
exceptionHandled = true;
|
|
order.push('B');
|
|
}
|
|
else {
|
|
// If we get here then the first process.nextTick got called twice
|
|
order.push('OOPS!');
|
|
}
|
|
});
|
|
|
|
process.addListener('exit', function() {
|
|
assert.deepEqual(['A','B','C'], order);
|
|
});
|
|
|