-
Notifications
You must be signed in to change notification settings - Fork 25k
Fix crash when passing null to clearImmediate #6192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
By analyzing the blame information on this pull request, we identified @spicyj, @vjeux and @nicklockwood to be potential reviewers. |
|
@facebook-github-bot shipit Good catch! |
|
@vjeux I think the bot is sleeping :( |
| JSTimersExecution.immediates.indexOf(timerID), | ||
| 1 | ||
| ); | ||
| if (timerID != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be !== ? @vjeux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want != here so it works will null and undefined. It's the same check the is used in other places in this file.
|
Actually, it would still crash if you clearImmediate a value that has already been removed. Could you do |
|
@janicduplessis updated the pull request. |
|
why do you still check for timer != null? Index === -1 check should catch this no? |
|
I wasn't sure if there could be null values in the immediates array since there was a check for it for the timerID array (https://github.com/janicduplessis/react-native/blob/clear-immediate/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js#L120). I double checked if it was possible and it is not so you are right I can remove the null check. |
|
@janicduplessis updated the pull request. |
|
@facebook-github-bot shipit |
|
Thanks for importing. If you are an FB employee go to Phabricator to review. |
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 facebook#6192 Differential Revision: D2987778 Pulled By: vjeux fb-gh-sync-id: 6fd38cfa3c10012caa2afb27cbdab95df696a769 shipit-source-id: 6fd38cfa3c10012caa2afb27cbdab95df696a769
Passing
undefinedornulltoclearImmediatecaused 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
clearImmediatewithundefinedornullshould do nothing.