diff --git a/src/node.js b/src/node.js index 57a803cfc4..ad8f27e499 100644 --- a/src/node.js +++ b/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; diff --git a/test/parallel/test-next-tick-errors.js b/test/parallel/test-next-tick-errors.js index eccd7a43a0..8e1bc52dec 100644 --- a/test/parallel/test-next-tick-errors.js +++ b/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;