From 362b5a6c401d08eafad701f4b6023e357a82f910 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 1 Nov 2011 16:30:41 +0100 Subject: [PATCH] process: fix process.nextTick() error case regression Patch and test by Koichi Kobayashi. --- src/node.js | 3 +++ test/simple/test-process-next-tick.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/simple/test-process-next-tick.js 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); +});