Skip to content
Permalink
Browse files

process: throw on non-function to nextTick()

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

PR-URL: #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>
  • Loading branch information...
yorkie authored and cjihrig committed Nov 16, 2015
1 parent 339d384 commit 72e3dd9f43c1d7ad1ea31db9a985901d902a9cfb
Showing with 18 additions and 0 deletions.
  1. +2 −0 src/node.js
  2. +16 −0 test/parallel/test-next-tick-errors.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;
@@ -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;

0 comments on commit 72e3dd9

Please sign in to comment.
You can’t perform that action at this time.