From 44fcf22074ca32e5f6869b88f7b6c00ea990cb08 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sun, 28 Feb 2016 11:40:50 -0800 Subject: [PATCH] Fix crash when passing null to clearImmediate Summary:Passing `undefined` or `null` to `clearImmediate` caused apps to crash. It it caused because we try to find the index of the null/undefined timer when we should just do nothing when passed these values. It is already handled properly in the other Timer functions. **Test plan** Calling `clearImmediate` with `undefined` or `null` should do nothing. Closes https://github.com/facebook/react-native/pull/6192 Differential Revision: D2987778 Pulled By: vjeux fb-gh-sync-id: 6fd38cfa3c10012caa2afb27cbdab95df696a769 shipit-source-id: 6fd38cfa3c10012caa2afb27cbdab95df696a769 --- Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js index f6a8bddc7..0ec0a4c08 100644 --- a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js +++ b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js @@ -106,10 +106,10 @@ var JSTimers = { clearImmediate: function(timerID) { JSTimers._clearTimerID(timerID); - JSTimersExecution.immediates.splice( - JSTimersExecution.immediates.indexOf(timerID), - 1 - ); + var index = JSTimersExecution.immediates.indexOf(timerID); + if (index !== -1) { + JSTimersExecution.immediates.splice(index, 1); + } }, cancelAnimationFrame: function(timerID) {