Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5c2d087

Browse files
authored
Event: Don't crash if an element is removed on blur
In Chrome, if an element having a `focusout` handler is blurred byclicking outside of it, it invokes the handler synchronously. Ifthat handler calls `.remove()` on the element, the data is cleared,leaving private data undefined. We're reading a property from thatdata so we need to guard against this.Fixesgh-4417Closesgh-4799
1 parenta503c69 commit5c2d087

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

‎src/event.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,13 @@ function leverageNative( el, type, expectSync ) {
558558
// Cancel the outer synthetic event
559559
event.stopImmediatePropagation();
560560
event.preventDefault();
561-
returnresult.value;
561+
562+
// Support: Chrome 86+
563+
// In Chrome, if an element having a focusout handler is blurred by
564+
// clicking outside of it, it invokes the handler synchronously. If
565+
// that handler calls `.remove()` on the element, the data is cleared,
566+
// leaving `result` undefined. We need to guard against this.
567+
returnresult&&result.value;
562568
}
563569

564570
// If this is an inner synthetic event for an event with a bubbling surrogate

‎test/unit/event.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,33 @@ QUnit.test( "focusin on document & window", function( assert ) {
26302630
jQuery(document).off("focusout",increment);
26312631
});
26322632

2633+
QUnit.test("element removed during focusout (gh-4417)",function(assert){
2634+
assert.expect(1);
2635+
2636+
varbutton=jQuery("<button>Click me</button>");
2637+
2638+
button.appendTo("#qunit-fixture");
2639+
2640+
button.on("click",function(){
2641+
button.trigger("blur");
2642+
assert.ok(true,"Removing the element didn't crash");
2643+
});
2644+
2645+
// Support: Chrome 86+
2646+
// In Chrome, if an element having a focusout handler is blurred by
2647+
// clicking outside of it, it invokes the handler synchronously. However,
2648+
// if the click happens programmatically, the invocation is asynchronous.
2649+
// As we have no way to simulate real user input in unit tests, simulate
2650+
// this behavior by calling `jQuery.cleanData` & removing the element using
2651+
// native APIs.
2652+
button[0].blur=function(){
2653+
jQuery.cleanData([this]);
2654+
this.parentNode.removeChild(this);
2655+
};
2656+
2657+
button[0].click();
2658+
});
2659+
26332660
testIframe(
26342661
"jQuery.ready promise",
26352662
"event/promiseReady.html",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp