Skip to content

Commit

Permalink
Manipulation: Fill in & warn jQuery.Deferred.getStackHook
Browse files Browse the repository at this point in the history
The API has been replaced by `jQuery.Deferred.getErrorHook`; the legacy
name will be removed in jQuery 4.0.0.

Fixes jquerygh-483
  • Loading branch information
mgol committed Sep 14, 2024
1 parent 5845951 commit e66e17c
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 6 deletions.
5 changes: 4 additions & 1 deletion build/tasks/npmcopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const files = {

"qunit/qunit.js": "qunit/qunit/qunit.js",
"qunit/qunit.css": "qunit/qunit/qunit.css",
"qunit/LICENSE.txt": "qunit/LICENSE.txt"
"qunit/LICENSE.txt": "qunit/LICENSE.txt",

"sinon/sinon.js": "sinon/pkg/sinon.js",
"sinon/LICENSE.txt": "sinon/LICENSE"
};

async function npmcopy() {
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default [
...globals.browser,
jQuery: false,
QUnit: false,
sinon: false,
url: false,
expectWarning: false,
expectNoWarning: false,
Expand Down
142 changes: 140 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"qunit": "2.21.0",
"rollup": "4.18.0",
"selenium-webdriver": "4.21.0",
"sinon": "9.2.4",
"uglify-js": "3.9.4",
"yargs": "17.7.2"
},
Expand Down
39 changes: 37 additions & 2 deletions src/jquery/deferred.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { migratePatchFunc, migratePatchAndWarnFunc } from "../main.js";
import {
migratePatchFunc,
migratePatchAndWarnFunc,
migrateWarn
} from "../main.js";

// Support jQuery slim which excludes the deferred module in jQuery 4.0+
if ( jQuery.Deferred ) {
Expand All @@ -13,7 +17,8 @@ var oldDeferred = jQuery.Deferred,
jQuery.Callbacks( "once memory" ), "rejected" ],
[ "notify", "progress", jQuery.Callbacks( "memory" ),
jQuery.Callbacks( "memory" ) ]
];
],
unpatchedGetStackHookValue;

migratePatchFunc( jQuery, "Deferred", function( func ) {
var deferred = oldDeferred(),
Expand Down Expand Up @@ -63,4 +68,34 @@ migratePatchFunc( jQuery, "Deferred", function( func ) {
// Preserve handler of uncaught exceptions in promise chains
jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;

// Preserve the optional hook to record the error, if defined
jQuery.Deferred.getErrorHook = oldDeferred.getErrorHook;

// We want to mirror jQuery.Deferred.getErrorHook here, so we cannot use
// existing Migrate utils.
Object.defineProperty( jQuery.Deferred, "getStackHook", {
configurable: true,
enumerable: true,
get: function() {
if ( jQuery.migrateIsPatchEnabled( "deferred-getStackHook" ) ) {
migrateWarn( "deferred-getStackHook",
"jQuery.Deferred.getStackHook is deprecated; " +
"use jQuery.Deferred.getErrorHook" );
return jQuery.Deferred.getErrorHook;
} else {
return unpatchedGetStackHookValue;
}
},
set: function( newValue ) {
if ( jQuery.migrateIsPatchEnabled( "deferred-getStackHook" ) ) {
migrateWarn( "deferred-getStackHook",
"jQuery.Deferred.getStackHook is deprecated; " +
"use jQuery.Deferred.getErrorHook" );
jQuery.Deferred.getErrorHook = newValue;
} else {
unpatchedGetStackHookValue = newValue;
}
}
} );

}
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<!-- QUnit -->
<link rel="stylesheet" href="../external/qunit/qunit.css" media="screen">
<script src="../external/qunit/qunit.js"></script>
<script src="../external/sinon/sinon.js"></script>

<!-- A promise polyfill -->
<script src="../external/npo/npo.js"></script>
Expand Down
Loading

0 comments on commit e66e17c

Please sign in to comment.