From 72e3dd9f43c1d7ad1ea31db9a985901d902a9cfb Mon Sep 17 00:00:00 2001 From: yorkie Date: Tue, 17 Nov 2015 02:54:04 +0800 Subject: [PATCH] process: throw on non-function to nextTick() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Brian White Reviewed-By: Trevor Norris Reviewed-By: Michaƫl Zasso --- src/node.js | 2 ++ test/parallel/test-next-tick-errors.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) 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;