Skip to content

Commit 44fcf22

Browse files
janicduplessisFacebook Github Bot 6
authored andcommitted
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 react#6192 Differential Revision: D2987778 Pulled By: vjeux fb-gh-sync-id: 6fd38cfa3c10012caa2afb27cbdab95df696a769 shipit-source-id: 6fd38cfa3c10012caa2afb27cbdab95df696a769
1 parent 3cc4f97 commit 44fcf22

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • Libraries/JavaScriptAppEngine/System/JSTimers

Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ var JSTimers = {
106106

107107
clearImmediate: function(timerID) {
108108
JSTimers._clearTimerID(timerID);
109-
JSTimersExecution.immediates.splice(
110-
JSTimersExecution.immediates.indexOf(timerID),
111-
1
112-
);
109+
var index = JSTimersExecution.immediates.indexOf(timerID);
110+
if (index !== -1) {
111+
JSTimersExecution.immediates.splice(index, 1);
112+
}
113113
},
114114

115115
cancelAnimationFrame: function(timerID) {

0 commit comments

Comments
 (0)