-
Notifications
You must be signed in to change notification settings - Fork 28
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
guard parentNode being null when walking DOM #54
Conversation
Good catch 👍 |
Can you add a test for this? |
May be tricky to add a test for this, perhaps detach the DOM node then trigger the event? |
|
||
while target != document && (typeof target != "undefined") | ||
while target != document && (typeof target != "undefined") && (target != 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.
This line could be reduced to
while target != document && target?
which will compile to
while (target !== document && target != 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.
My rationale was that target != null
will cause an error is target is not defined, whereas (I think anyways) that typeof target != "undefined"
will return false even if target is not defined. Therefore, if target was undefined, or null, the checked would be false, an not in an error state. That being said, in this context I don't see how target would be undefined, so I agree with your solution. Updated in latest commit, thanks!
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.
Just for the future, typeof undefined == 'undefined'
and typeof something_never_declared == 'undefined'
and undefined == null
@tylermercier @qq99 I'm going to have to refresh my memory after the holidays, but I'll work on getting a test for this. |
Can we ship this as is? |
I would |
|
||
while target != document && (typeof target != "undefined") | ||
while target != document && target? |
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.
wonder if this can be just target
and not target?
guard parentNode being null when walking DOM
While walking the DOM it is possible that parentNode can become null. As a result, the not null check at line 53 may not guard against all null cases. This can be fixed by moving the check into the while loop conditions.
@tylermercier @celsodantas @nsimmons @patrickdonovan @kurtfunai @qq99