From 29d8578be0ca831f641fdd9d87c70850bca39f52 Mon Sep 17 00:00:00 2001 From: yorkie Date: Tue, 17 Nov 2015 02:54:04 +0800 Subject: [PATCH 1/4] process: nextTick should not be handled lazily --- src/node.js | 2 ++ test/parallel/test-next-tick-errors.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/node.js b/src/node.js index 57a803cfc44312..afca45214cf877 100644 --- a/src/node.js +++ b/src/node.js @@ -489,6 +489,8 @@ // on the way out, don't bother. it won't get fired anyway. if (process._exiting) return; + if (typeof callback !== 'function') + throw new Error('callback is not a function'); var args; if (arguments.length > 1) { diff --git a/test/parallel/test-next-tick-errors.js b/test/parallel/test-next-tick-errors.js index eccd7a43a0825f..6647dc1241624a 100644 --- a/test/parallel/test-next-tick-errors.js +++ b/test/parallel/test-next-tick-errors.js @@ -20,6 +20,15 @@ process.nextTick(function() { order.push('C'); }); +try { + process.nextTick(); +} catch (e) { + // should handle this error at try...catch + if (!e) { + assert.fail(); + } +} + process.on('uncaughtException', function() { if (!exceptionHandled) { exceptionHandled = true; From 250e4a1faf5301ffb43aab756120ae26a3bd62f3 Mon Sep 17 00:00:00 2001 From: yorkie Date: Tue, 17 Nov 2015 12:43:00 +0800 Subject: [PATCH 2/4] fix nits --- src/node.js | 2 +- test/parallel/test-next-tick-errors.js | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/node.js b/src/node.js index afca45214cf877..06e8cda4922d5a 100644 --- a/src/node.js +++ b/src/node.js @@ -490,7 +490,7 @@ if (process._exiting) return; if (typeof callback !== 'function') - throw new Error('callback is not a function'); + throw new TypeError('callback is not a function'); var args; if (arguments.length > 1) { diff --git a/test/parallel/test-next-tick-errors.js b/test/parallel/test-next-tick-errors.js index 6647dc1241624a..74633901aacb41 100644 --- a/test/parallel/test-next-tick-errors.js +++ b/test/parallel/test-next-tick-errors.js @@ -20,15 +20,28 @@ process.nextTick(function() { order.push('C'); }); -try { - process.nextTick(); -} catch (e) { - // should handle this error at try...catch - if (!e) { - assert.fail(); +assert.throws( + function () { + process.nextTick } +); + +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; From c3961dbfe23cf3edf015b12d500bf666ab331ba5 Mon Sep 17 00:00:00 2001 From: yorkie Date: Tue, 17 Nov 2015 12:44:46 +0800 Subject: [PATCH 3/4] fix nits --- src/node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node.js b/src/node.js index 06e8cda4922d5a..ad8f27e499afa5 100644 --- a/src/node.js +++ b/src/node.js @@ -486,11 +486,11 @@ } 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; - if (typeof callback !== 'function') - throw new TypeError('callback is not a function'); var args; if (arguments.length > 1) { From 3a4b6afb04925030caa999c4fc0750698ee7a189 Mon Sep 17 00:00:00 2001 From: yorkie Date: Tue, 17 Nov 2015 13:09:02 +0800 Subject: [PATCH 4/4] fix nits --- test/parallel/test-next-tick-errors.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/parallel/test-next-tick-errors.js b/test/parallel/test-next-tick-errors.js index 74633901aacb41..8e1bc52decea7c 100644 --- a/test/parallel/test-next-tick-errors.js +++ b/test/parallel/test-next-tick-errors.js @@ -20,12 +20,6 @@ process.nextTick(function() { order.push('C'); }); -assert.throws( - function () { - process.nextTick - } -); - function testNextTickWith(val) { assert.throws( function() {