Skip to content

Commit 72e3dd9

Browse files
yorkiecjihrig
authored andcommitted
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 <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 339d384 commit 72e3dd9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/node.js

+2
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@
486486
}
487487

488488
function nextTick(callback) {
489+
if (typeof callback !== 'function')
490+
throw new TypeError('callback is not a function');
489491
// on the way out, don't bother. it won't get fired anyway.
490492
if (process._exiting)
491493
return;

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

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ process.nextTick(function() {
2020
order.push('C');
2121
});
2222

23+
function testNextTickWith(val) {
24+
assert.throws(
25+
function() {
26+
process.nextTick(val);
27+
},
28+
TypeError
29+
);
30+
}
31+
32+
testNextTickWith(false);
33+
testNextTickWith(true);
34+
testNextTickWith(1);
35+
testNextTickWith('str');
36+
testNextTickWith({});
37+
testNextTickWith([]);
38+
2339
process.on('uncaughtException', function() {
2440
if (!exceptionHandled) {
2541
exceptionHandled = true;

0 commit comments

Comments
 (0)