From 258ca1ec6a373f85f7849308c967b7e6a993e6e7 Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Tue, 14 Mar 2023 22:32:45 +0100 Subject: Deferred: Rename `getStackHook` to `getErrorHook` Rename `jQuery.Deferred.getStackHook` to `jQuery.Deferred.getErrorHook` to indicate passing an error instance is usually a better choice - it works with source maps while a raw stack generally does not. In jQuery `3.7.0`, we'll keep both names, marking the old one as deprecated. In jQuery `4.0.0` we'll just keep the new one. This change implements the `4.0.0` version; PR gh-5212 implements the `3.7.0` one. Fixes gh-5201 Closes gh-5211 Ref gh-5212 --- src/deferred.js | 8 ++++---- src/deferred/exceptionHook.js | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/deferred.js b/src/deferred.js index dc4294726..0d77ac9d6 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -188,7 +188,7 @@ jQuery.extend( { if ( jQuery.Deferred.exceptionHook ) { jQuery.Deferred.exceptionHook( e, - process.stackTrace ); + process.error ); } // Support: Promises/A+ section 2.3.3.3.4.1 @@ -216,10 +216,10 @@ jQuery.extend( { process(); } else { - // Call an optional hook to record the stack, in case of exception + // Call an optional hook to record the error, in case of exception // since it's otherwise lost when execution goes async - if ( jQuery.Deferred.getStackHook ) { - process.stackTrace = jQuery.Deferred.getStackHook(); + if ( jQuery.Deferred.getErrorHook ) { + process.error = jQuery.Deferred.getErrorHook(); } window.setTimeout( process ); } diff --git a/src/deferred/exceptionHook.js b/src/deferred/exceptionHook.js index 0315b2ecb..a5e7b5d3c 100644 --- a/src/deferred/exceptionHook.js +++ b/src/deferred/exceptionHook.js @@ -6,13 +6,16 @@ import "../deferred.js"; // 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 ) { +// If `jQuery.Deferred.getErrorHook` is defined, `asyncError` is an error +// captured before the async barrier to get the original error cause +// which may otherwise be hidden. +jQuery.Deferred.exceptionHook = function( error, asyncError ) { if ( error && rerrorNames.test( error.name ) ) { window.console.warn( "jQuery.Deferred exception", error, - stack + asyncError ); } }; -- cgit v1.2.3