Skip to content

Commit

Permalink
process: throw on non-function to nextTick()
Browse files Browse the repository at this point in the history
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 18, 2015
1 parent 339d384 commit 72e3dd9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-next-tick-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 72e3dd9

Please sign in to comment.