Core: Re-throw errors that happened in callbacks wrapped in jQuery ready

Also, expose jQuery.readyException that allows to overwrite the default
ready error handler.

Fixes gh-3174
Closes gh-3210
This commit is contained in:
Michał Gołębiowski
2016-06-29 14:19:04 +02:00
parent 25d8ccd111
commit ad6a94c3f1
3 changed files with 74 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
define( [
"../core",
"../var/document",
"../core/readyException",
"../deferred"
], function( jQuery, document ) {
@@ -11,7 +12,15 @@ var readyList = jQuery.Deferred();
jQuery.fn.ready = function( fn ) {
readyList.then( fn );
readyList
.then( fn )
// Wrap jQuery.readyException in a function so that the lookup
// happens at the time of error handling instead of callback
// registration.
.catch( function( error ) {
jQuery.readyException( error );
} );
return this;
};

View File

@@ -0,0 +1,13 @@
define( [
"../core"
], function( jQuery ) {
"use strict";
jQuery.readyException = function( error ) {
window.setTimeout( function() {
throw error;
} );
};
} );