Skip to content

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Nov 21, 2024

Rather than using try/catch to detect when document is missing we explicitly check for it. This is the same pattern used in the other version of findEventTarget on line 336.

This avoids casting a wide net and hiding errors in the rest of the code in this function. Its also more consistent with the other version of findEventTarget.

@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 21, 2024

I noticed this while reviewing #22959

@sbc100 sbc100 requested a review from kripken November 21, 2024 20:25
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but maybe the last paragraph in the PR description is worth a changelog entry?

@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 21, 2024

lgtm but maybe the last paragraph in the PR description is worth a changelog entry?

I don't think it could have any material effect. findEventTarget should always be returning a DOM object.

@sbc100 sbc100 force-pushed the findEventTarget branch 2 times, most recently from 803d02b to 8fec0e9 Compare November 21, 2024 21:29
@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 21, 2024

lgtm but maybe the last paragraph in the PR description is worth a changelog entry?

I don't think it could have any material effect. findEventTarget should always be returning a DOM object.

I updated the change so there should be change at all there..

Rather than using try/catch to detect when `document` is missing
we explicitly check for it.  This is the same pattern used in the other
version of `findEventTarget` on line 336.

This avoids casting a wide net and hiding errors in the rest of the code
in this function.  Its also more consistent with the other version of
`findEventTarget`.

One change here is that the fallback for when `querySelector` fails is
now the same as the fallback for when `document` is missing.  In this
case we return `undefined`.  Returning a string from findEventTarget
is never correct.  Its always supposed to return a DOM element AFAICT.
@sbc100 sbc100 enabled auto-merge (squash) November 21, 2024 21:52
@sbc100 sbc100 merged commit 8dc5d05 into emscripten-core:main Nov 21, 2024
28 checks passed
@sbc100 sbc100 deleted the findEventTarget branch November 21, 2024 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants