mirror of
https://github.com/jquery/jquery.git
synced 2026-02-07 22:15:30 -05:00
Ajax: Protect against exceptions thrown synchronously by xhr.send
When xhr.send throws an exception synchronously, the onerror handler may have been called already which, unchecked, makes the exception bubble up outside of jQuery.ajax. We now catch the exception pre-emptively and only rethrow if we know it hasn't already been notified through the onerror handler. Fixes #14683
This commit is contained in:
@@ -1544,6 +1544,36 @@ module( "ajax", {
|
||||
});
|
||||
}
|
||||
|
||||
ajaxTest( "#14683 - jQuery.ajax() - Exceptions thrown synchronously by xhr.send should be caught", 4, [
|
||||
{
|
||||
url: "data/params_html.php",
|
||||
method: "POST",
|
||||
data: {
|
||||
toString: function() {
|
||||
throw "Can't parse";
|
||||
}
|
||||
},
|
||||
processData: false,
|
||||
done: function( data ) {
|
||||
ok( false, "done: " + data );
|
||||
},
|
||||
fail: function( jqXHR, status, error ) {
|
||||
ok( true, "exception caught: " + error );
|
||||
strictEqual( jqXHR.status, 0, "proper status code" );
|
||||
strictEqual( status, "error", "proper status" );
|
||||
}
|
||||
},
|
||||
{
|
||||
url: "http://domain.org:80d",
|
||||
done: function( data ) {
|
||||
ok( false, "done: " + data );
|
||||
},
|
||||
fail: function( _, status, error ) {
|
||||
ok( true, "fail: " + status + " - " + error );
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
//----------- jQuery.ajaxPrefilter()
|
||||
|
||||
ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, {
|
||||
|
||||
Reference in New Issue
Block a user