diff options
author | Michał Gołębiowski <m.goleb@gmail.com> | 2016-06-29 14:19:04 +0200 |
---|---|---|
committer | Michał Gołębiowski <m.goleb@gmail.com> | 2016-07-07 10:23:06 +0200 |
commit | ad6a94c3f1747829082b85fd53ee2efbae879707 (patch) | |
tree | 2b532c0d524d7848b70b16be0a7699fe2b42daec /src/core | |
parent | 25d8ccd1112d75394b91071ff7eba13283aaf898 (diff) | |
download | jquery-ad6a94c3f1747829082b85fd53ee2efbae879707.tar.gz jquery-ad6a94c3f1747829082b85fd53ee2efbae879707.zip |
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
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ready.js | 11 | ||||
-rw-r--r-- | src/core/readyException.js | 13 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/core/ready.js b/src/core/ready.js index bb4e222d3..53b1b2da7 100644 --- a/src/core/ready.js +++ b/src/core/ready.js @@ -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; }; diff --git a/src/core/readyException.js b/src/core/readyException.js new file mode 100644 index 000000000..72bdd90b5 --- /dev/null +++ b/src/core/readyException.js @@ -0,0 +1,13 @@ +define( [ + "../core" +], function( jQuery ) { + +"use strict"; + +jQuery.readyException = function( error ) { + window.setTimeout( function() { + throw error; + } ); +}; + +} ); |