Skip to content
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

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

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
@@ -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() {
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -95,6 +95,7 @@ export default [
...globals.browser,
jQuery: false,
QUnit: false,
sinon: false,
url: false,
expectWarning: false,
expectNoWarning: false,
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
@@ -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"
},
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
@@ -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
@@ -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>
Loading