summaryrefslogtreecommitdiff
path: root/test/simple/test-next-tick-errors.js
blob: 9188548c6d2f465b16d9ce3666d4490e912ccdc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var common = require('../common');
var assert = require('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);
});