Skip to content

Deferred: Fill in & warn jQuery.Deferred.getStackHook #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 43 additions & 2 deletions src/jquery/deferred.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { migratePatchFunc, migratePatchAndWarnFunc } from "../main.js";
import {
migratePatchFunc,
migratePatchAndWarnFunc,
migrateWarn
} from "../main.js";
import { jQueryVersionSince } from "../compareVersions.js";

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

var oldDeferred = jQuery.Deferred,
var unpatchedGetStackHookValue,
oldDeferred = jQuery.Deferred,
tuples = [

// Action, add listener, callbacks, .then handlers, final state
Expand Down Expand Up @@ -63,4 +69,39 @@ 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" ) ) {

// jQuery 3.x checks `getStackHook` if `getErrorHook` missing;
// don't warn on the getter there.
if ( jQueryVersionSince( "4.0.0" ) ) {
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