Browse Source

process: throw on non-function to nextTick()

This commit causes process.nextTick() to throw when its callback
argument is not a function.

PR-URL: https://github.com/nodejs/node/pull/3860
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
process-exit-stdio-flushing
yorkie 9 years ago
committed by cjihrig
parent
commit
72e3dd9f43
  1. 2
      src/node.js
  2. 16
      test/parallel/test-next-tick-errors.js

2
src/node.js

@ -486,6 +486,8 @@
}
function nextTick(callback) {
if (typeof callback !== 'function')
throw new TypeError('callback is not a function');
// on the way out, don't bother. it won't get fired anyway.
if (process._exiting)
return;

16
test/parallel/test-next-tick-errors.js

@ -20,6 +20,22 @@ process.nextTick(function() {
order.push('C');
});
function testNextTickWith(val) {
assert.throws(
function() {
process.nextTick(val);
},
TypeError
);
}
testNextTickWith(false);
testNextTickWith(true);
testNextTickWith(1);
testNextTickWith('str');
testNextTickWith({});
testNextTickWith([]);
process.on('uncaughtException', function() {
if (!exceptionHandled) {
exceptionHandled = true;

Loading…
Cancel
Save