Skip to content

Commit 07c54e6

Browse files
committed
Manipulation: Fill in & warn jQuery.Deferred.getStackHook
The API has been replaced by `jQuery.Deferred.getErrorHook`; the legacy name will be removed in jQuery 4.0.0. Fixes gh-483
1 parent 5845951 commit 07c54e6

File tree

7 files changed

+407
-6
lines changed

7 files changed

+407
-6
lines changed

build/tasks/npmcopy.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const files = {
88

99
"qunit/qunit.js": "qunit/qunit/qunit.js",
1010
"qunit/qunit.css": "qunit/qunit/qunit.css",
11-
"qunit/LICENSE.txt": "qunit/LICENSE.txt"
11+
"qunit/LICENSE.txt": "qunit/LICENSE.txt",
12+
13+
"sinon/sinon.js": "sinon/pkg/sinon.js",
14+
"sinon/LICENSE.txt": "sinon/LICENSE"
1215
};
1316

1417
async function npmcopy() {

eslint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export default [
9595
...globals.browser,
9696
jQuery: false,
9797
QUnit: false,
98+
sinon: false,
9899
url: false,
99100
expectWarning: false,
100101
expectNoWarning: false,

package-lock.json

+140-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"qunit": "2.21.0",
5858
"rollup": "4.18.0",
5959
"selenium-webdriver": "4.21.0",
60+
"sinon": "9.2.4",
6061
"uglify-js": "3.9.4",
6162
"yargs": "17.7.2"
6263
},

src/jquery/deferred.js

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import { migratePatchFunc, migratePatchAndWarnFunc } from "../main.js";
1+
import {
2+
migratePatchFunc,
3+
migratePatchAndWarnFunc,
4+
migrateWarn
5+
} from "../main.js";
26

37
// Support jQuery slim which excludes the deferred module in jQuery 4.0+
48
if ( jQuery.Deferred ) {
59

6-
var oldDeferred = jQuery.Deferred,
10+
var unpatchedGetStackHookValue,
11+
oldDeferred = jQuery.Deferred,
712
tuples = [
813

914
// Action, add listener, callbacks, .then handlers, final state
@@ -63,4 +68,34 @@ migratePatchFunc( jQuery, "Deferred", function( func ) {
6368
// Preserve handler of uncaught exceptions in promise chains
6469
jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
6570

71+
// Preserve the optional hook to record the error, if defined
72+
jQuery.Deferred.getErrorHook = oldDeferred.getErrorHook;
73+
74+
// We want to mirror jQuery.Deferred.getErrorHook here, so we cannot use
75+
// existing Migrate utils.
76+
Object.defineProperty( jQuery.Deferred, "getStackHook", {
77+
configurable: true,
78+
enumerable: true,
79+
get: function() {
80+
if ( jQuery.migrateIsPatchEnabled( "deferred-getStackHook" ) ) {
81+
migrateWarn( "deferred-getStackHook",
82+
"jQuery.Deferred.getStackHook is deprecated; " +
83+
"use jQuery.Deferred.getErrorHook" );
84+
return jQuery.Deferred.getErrorHook;
85+
} else {
86+
return unpatchedGetStackHookValue;
87+
}
88+
},
89+
set: function( newValue ) {
90+
if ( jQuery.migrateIsPatchEnabled( "deferred-getStackHook" ) ) {
91+
migrateWarn( "deferred-getStackHook",
92+
"jQuery.Deferred.getStackHook is deprecated; " +
93+
"use jQuery.Deferred.getErrorHook" );
94+
jQuery.Deferred.getErrorHook = newValue;
95+
} else {
96+
unpatchedGetStackHookValue = newValue;
97+
}
98+
}
99+
} );
100+
66101
}

test/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<!-- QUnit -->
1111
<link rel="stylesheet" href="../external/qunit/qunit.css" media="screen">
1212
<script src="../external/qunit/qunit.js"></script>
13+
<script src="../external/sinon/sinon.js"></script>
1314

1415
<!-- A promise polyfill -->
1516
<script src="../external/npo/npo.js"></script>

0 commit comments

Comments
 (0)