From f203ea939385be8db88bf63f64df6c37b37bcf52 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Wed, 10 Jun 2020 01:11:48 +0200 Subject: [PATCH 1/7] use typeof validation for numbers --- lib/kill.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/kill.js b/lib/kill.js index a684e2c043..cd07d3909d 100644 --- a/lib/kill.js +++ b/lib/kill.js @@ -44,7 +44,7 @@ const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => { return DEFAULT_FORCE_KILL_TIMEOUT; } - if (!Number.isInteger(forceKillAfterTimeout) || forceKillAfterTimeout < 0) { + if (typeof forceKillAfterTimeout !== 'number' || forceKillAfterTimeout < 0) { throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`); } @@ -71,7 +71,7 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise return spawnedPromise; } - if (!Number.isInteger(timeout) || timeout < 0) { + if (typeof timeout !== 'number' || timeout < 0) { throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`); } From 76464ebd5fa0a6ad9758d659cbabfceac8fe9449 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Wed, 10 Jun 2020 14:15:53 +0200 Subject: [PATCH 2/7] use Number.isFinite over typeof --- lib/kill.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/kill.js b/lib/kill.js index cd07d3909d..dc63743604 100644 --- a/lib/kill.js +++ b/lib/kill.js @@ -44,7 +44,7 @@ const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => { return DEFAULT_FORCE_KILL_TIMEOUT; } - if (typeof forceKillAfterTimeout !== 'number' || forceKillAfterTimeout < 0) { + if (Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) { throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`); } @@ -71,7 +71,7 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise return spawnedPromise; } - if (typeof timeout !== 'number' || timeout < 0) { + if (Number.isFinite(number) || timeout < 0) { throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`); } From 88d61a1a944a6e4a837bac81279b0f2153c9153a Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 11 Jun 2020 10:39:44 +0200 Subject: [PATCH 3/7] Update lib/kill.js Co-authored-by: Sindre Sorhus --- lib/kill.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kill.js b/lib/kill.js index dc63743604..478d11afd5 100644 --- a/lib/kill.js +++ b/lib/kill.js @@ -44,7 +44,7 @@ const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => { return DEFAULT_FORCE_KILL_TIMEOUT; } - if (Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) { + if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) { throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`); } From 5509301ca7d1af1961e82d1121b9af5bb300a5e0 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 11 Jun 2020 14:13:38 +0200 Subject: [PATCH 4/7] Update lib/kill.js Co-authored-by: ehmicky --- lib/kill.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kill.js b/lib/kill.js index 478d11afd5..3890079b1a 100644 --- a/lib/kill.js +++ b/lib/kill.js @@ -71,7 +71,7 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise return spawnedPromise; } - if (Number.isFinite(number) || timeout < 0) { + if (!Number.isFinite(number) || timeout < 0) { throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`); } From 8a133cda0fb1bdb68dc2d71f9c66240607495d0b Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 11 Jun 2020 22:50:19 +0200 Subject: [PATCH 5/7] Update lib/kill.js Co-authored-by: ehmicky --- lib/kill.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kill.js b/lib/kill.js index 3890079b1a..7f6f8dd7f2 100644 --- a/lib/kill.js +++ b/lib/kill.js @@ -71,7 +71,7 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise return spawnedPromise; } - if (!Number.isFinite(number) || timeout < 0) { + if (!Number.isFinite(timeout) || timeout < 0) { throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`); } From fb6452676eb468ea8e45dbd4098f44d072d3751e Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Sun, 14 Jun 2020 23:03:05 +0200 Subject: [PATCH 6/7] test: update --- test/kill.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/kill.js b/test/kill.js index b402c42d12..203995109d 100644 --- a/test/kill.js +++ b/test/kill.js @@ -61,15 +61,9 @@ if (process.platform !== 'win32') { t.is(signal, 'SIGKILL'); }); - test('`forceKillAfterTimeout` should not be a float', t => { + test('`forceKillAfterTimeout` should not be NaN', t => { t.throws(() => { - execa('noop').kill('SIGTERM', {forceKillAfterTimeout: 0.5}); - }, {instanceOf: TypeError, message: /non-negative integer/}); - }); - - test('`forceKillAfterTimeout` should not be negative', t => { - t.throws(() => { - execa('noop').kill('SIGTERM', {forceKillAfterTimeout: -1}); + execa('noop').kill('SIGTERM', {forceKillAfterTimeout: NaN}); }, {instanceOf: TypeError, message: /non-negative integer/}); }); } From 61221c6fcd27219c88cb0933f3788ea11e1c4c6b Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Mon, 15 Jun 2020 13:08:16 +0200 Subject: [PATCH 7/7] Update kill.js --- test/kill.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/kill.js b/test/kill.js index 203995109d..6ca54a4a56 100644 --- a/test/kill.js +++ b/test/kill.js @@ -66,6 +66,12 @@ if (process.platform !== 'win32') { execa('noop').kill('SIGTERM', {forceKillAfterTimeout: NaN}); }, {instanceOf: TypeError, message: /non-negative integer/}); }); + + test('`forceKillAfterTimeout` should not be negative', t => { + t.throws(() => { + execa('noop').kill('SIGTERM', {forceKillAfterTimeout: -1}); + }, {instanceOf: TypeError, message: /non-negative integer/}); + }); } test('execa() returns a promise with kill()', t => {