]> source.dussan.org Git - jquery.git/commit
Event: Increase robustness of an inner native event in leverageNative
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 20 May 2024 16:05:19 +0000 (18:05 +0200)
committerGitHub <noreply@github.com>
Mon, 20 May 2024 16:05:19 +0000 (18:05 +0200)
commit527fb3dcf0dcde69302a741dfc61cbfa58e99eb0
tree1e3a6845a1c5cb3f70cc80584579c19f992149be
parent5880e02707dcefc4ec527bd1c56f64b8b0eba391
Event: Increase robustness of an inner native event in leverageNative

In Firefox, alert displayed just before blurring an element dispatches
the native blur event twice which tripped the jQuery logic if a jQuery blur
handler was not attached before the trigger call.

This was because the `leverageNative` logic part for triggering first checked if
setup was done before (which, for example, is done if a jQuery handler was
registered before for this element+event pair) and - if it was not - added
a dummy handler that just returned `true`. The `leverageNative` logic made that
`true` then saved into private data, replacing the previous `saved` array. Since
`true` passed the truthy check, the second native inner handler treated `true`
as an array, crashing on the `slice` call.

The same issue could happen if a handler returning `true` is attached before
triggering. A bare `length` check would not be enough as the user handler may
return an array-like as well. To remove this potential data shape clash, capture
the inner result in an object with a `value` property instead of saving it
directly.

Since it's impossible to call `alert()` in unit tests, simulate the issue by
replacing the `addEventListener` method on a test button with a version that
calls attached blur handlers twice.

Fixes gh-5459
Closes gh-5466
Ref gh-5236
src/event.js
test/unit/event.js