- Notifications
You must be signed in to change notification settings - Fork20.6k
Description
Description
Running Chrome 73.0.3683.86 on Windows 7 with jQuery 3.4.1.
jQuery tries to read a property of an undefined, causing an exception. This occurs when an element is removed when it loses focus, during a focusout handler, responding to a jQuery triggered blur() event. The three key operations are all performed via jQuery:
The exception occurs on line 5467; here is the code up to that line:
dataPriv.set(this,type,saved);// Trigger the native event and capture its result// Support: IE <=9 - 11+// focus() and blur() are asynchronousnotAsync=expectSync(this,type);this[type]();result=dataPriv.get(this,type);if(saved!==result||notAsync){dataPriv.set(this,type,false);}else{result={};}if(saved!==result){// Cancel the outer synthetic eventevent.stopImmediatePropagation();event.preventDefault();returnresult.value;}
In the last line, result is undefined. That is because duringthis[ type ]()
(which issues the event), the element is removed, causing jQuery to remove its saved information from dataPriv in cleanData() line 6046:
elem[ dataPriv.expando ] = undefined;
Thus, afterthis[ type ]()
, result is undefined, it does not equal saved, so thedataPriv.set()
of the conditional is executed and result is left undefined. Presumably,result = ()
needs to be set outside the conditional. This problem is also timing-sensitive -- with the certain break points it may not occur.
This didn't happen in 3.3.1. Note also that jQuery'sblur()
must be used, rather than normal JSblur()
, in order to go through this code path.
Link to test case
jsfiddle uses 3.3.1, so I didn't set up a test case.
*EDIT by@mgol: I wrapped code pieces in backticks to fix Markdown formatting