process: fix process.nextTick() error case regression
authorBen Noordhuis <info@bnoordhuis.nl>
Tue, 1 Nov 2011 15:30:41 +0000 (16:30 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Tue, 1 Nov 2011 15:30:43 +0000 (16:30 +0100)
Patch and test by Koichi Kobayashi.

src/node.js
test/simple/test-process-next-tick.js [new file with mode: 0644]

index a874bd5..403c618 100644 (file)
         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 (file)
index 0000000..bef7bcc
--- /dev/null
@@ -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);
+});