Skip to content

Commit cab32e7

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 jquerygh-483
1 parent 5845951 commit cab32e7

File tree

7 files changed

+352
-5
lines changed

7 files changed

+352
-5
lines changed

build/tasks/npmcopy.js

Lines changed: 4 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 140 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
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 ) {
@@ -63,4 +67,30 @@ migratePatchFunc( jQuery, "Deferred", function( func ) {
6367
// Preserve handler of uncaught exceptions in promise chains
6468
jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
6569

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

test/index.html

Lines changed: 1 addition & 0 deletions
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)