diff --git a/src/node.js b/src/node.js index a874bd55c73..403c618307a 100644 --- a/src/node.js +++ b/src/node.js @@ -192,6 +192,9 @@ for (var i = 0; i < l; i++) q[i](); } catch (e) { + if (i + 1 < l) { + nextTickQueue = q.slice(i + 1).concat(nextTickQueue); + } if (nextTickQueue.length) { process._needTickCallback(); } diff --git a/test/simple/test-process-next-tick.js b/test/simple/test-process-next-tick.js new file mode 100644 index 00000000000..bef7bccf076 --- /dev/null +++ b/test/simple/test-process-next-tick.js @@ -0,0 +1,23 @@ +var assert = require('assert'); +var N = 2; +var tickCount = 0; +var exceptionCount = 0; + +function cb() { + ++tickCount; + throw new Error(); +} + +for (var i = 0; i < N; ++i) { + process.nextTick(cb); +} + +process.on('uncaughtException', function() { + ++exceptionCount; +}); + +process.on('exit', function() { + process.removeAllListeners('uncaughtException'); + assert.equal(tickCount, N); + assert.equal(exceptionCount, N); +});