aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/deferred.js13
-rw-r--r--src/deferred/exceptionHook.js19
-rw-r--r--src/jquery.js1
3 files changed, 32 insertions, 1 deletions
diff --git a/src/deferred.js b/src/deferred.js
index ff12ac3e0..6a1ef3b43 100644
--- a/src/deferred.js
+++ b/src/deferred.js
@@ -157,12 +157,17 @@ jQuery.extend( {
mightThrow();
} catch ( e ) {
+ if ( jQuery.Deferred.exceptionHook ) {
+ jQuery.Deferred.exceptionHook( e,
+ process.stackTrace );
+ }
+
// Support: Promises/A+ section 2.3.3.3.4.1
// https://promisesaplus.com/#point-61
// Ignore post-resolution exceptions
if ( depth + 1 >= maxDepth ) {
- // Only substitue handlers pass on context
+ // Only substitute handlers pass on context
// and multiple values (non-spec behavior)
if ( handler !== Thrower ) {
that = undefined;
@@ -182,6 +187,12 @@ jQuery.extend( {
if ( depth ) {
process();
} else {
+
+ // Call an optional hook to record the stack, in case of exception
+ // since it's otherwise lost when execution goes async
+ if ( jQuery.Deferred.getStackHook ) {
+ process.stackTrace = jQuery.Deferred.getStackHook();
+ }
window.setTimeout( process );
}
};
diff --git a/src/deferred/exceptionHook.js b/src/deferred/exceptionHook.js
new file mode 100644
index 000000000..b9955063a
--- /dev/null
+++ b/src/deferred/exceptionHook.js
@@ -0,0 +1,19 @@
+define( [
+ "../core",
+ "../deferred"
+], function( jQuery ) {
+
+// These usually indicate a programmer mistake during development,
+// warn about them ASAP rather than swallowing them by default.
+var rerrorNames = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;
+
+jQuery.Deferred.exceptionHook = function( error, stack ) {
+
+ // Support: IE9
+ // Console exists when dev tools are open, which can happen at any time
+ if ( window.console && window.console.warn && error && rerrorNames.test( error.name ) ) {
+ window.console.warn( "jQuery.Deferred exception: " + error.message, stack );
+ }
+};
+
+} );
diff --git a/src/jquery.js b/src/jquery.js
index 2faa9c3cd..4cc9c8a90 100644
--- a/src/jquery.js
+++ b/src/jquery.js
@@ -4,6 +4,7 @@ define( [
"./traversing",
"./callbacks",
"./deferred",
+ "./deferred/exceptionHook",
"./core/ready",
"./data",
"./queue",