2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-12-23 16:02:12 -08:00
|
|
|
require('../common');
|
2010-12-04 15:20:34 -08:00
|
|
|
var assert = require('assert');
|
2010-08-27 02:50:12 -06:00
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const order = [];
|
|
|
|
let exceptionHandled = false;
|
2010-08-27 02:50:12 -06:00
|
|
|
|
|
|
|
// 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
|
2016-04-17 23:41:59 -07:00
|
|
|
what(); // eslint-disable-line no-undef
|
2010-08-27 02:50:12 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
// This nextTick function should remain in the queue when the first one
|
2010-09-01 05:01:38 -06:00
|
|
|
// is removed. It should be called if the error in the first one is
|
|
|
|
// caught (which we do in this test).
|
2010-08-27 02:50:12 -06:00
|
|
|
process.nextTick(function() {
|
|
|
|
order.push('C');
|
|
|
|
});
|
|
|
|
|
2015-11-17 02:54:04 +08:00
|
|
|
function testNextTickWith(val) {
|
|
|
|
assert.throws(
|
|
|
|
function() {
|
|
|
|
process.nextTick(val);
|
|
|
|
},
|
|
|
|
TypeError
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
testNextTickWith(false);
|
|
|
|
testNextTickWith(true);
|
|
|
|
testNextTickWith(1);
|
|
|
|
testNextTickWith('str');
|
|
|
|
testNextTickWith({});
|
|
|
|
testNextTickWith([]);
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('uncaughtException', function() {
|
2010-08-27 02:50:12 -06:00
|
|
|
if (!exceptionHandled) {
|
|
|
|
exceptionHandled = true;
|
|
|
|
order.push('B');
|
2016-07-08 17:17:47 -07:00
|
|
|
} else {
|
2010-08-27 02:50:12 -06:00
|
|
|
// If we get here then the first process.nextTick got called twice
|
|
|
|
order.push('OOPS!');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2016-04-19 15:37:45 -07:00
|
|
|
assert.deepStrictEqual(['A', 'B', 'C'], order);
|
2010-08-27 02:50:12 -06:00
|
|
|
});
|