Skip to content

Event: Patch jQuery.event.global #574

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/jquery/event.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
migrateWarn,
migrateWarnProp,
migratePatchAndInfoFunc,
migratePatchFunc
} from "../main.js";
Expand Down Expand Up @@ -41,3 +42,6 @@ migratePatchAndInfoFunc( jQuery.fn, "undelegate", jQuery.fn.undelegate,

migratePatchAndInfoFunc( jQuery.fn, "hover", jQuery.fn.hover,
"hover", "jQuery.fn.hover() is deprecated" );

migrateWarnProp( jQuery.event, "global", {}, "event-global",
"jQuery.event.global is removed" );
9 changes: 9 additions & 0 deletions test/unit/jquery/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@ TestManager.runIframeTest( "Load within a ready handler", "event-lateload.html",
JSON.stringify( jQuery.migrateMessages ) );
assert.ok( /load/.test( jQuery.migrateMessages[ 0 ] ), "message ok" );
} );

QUnit.test( "jQuery.event.global", function( assert ) {
assert.expect( 3 );

expectMessage( assert, "jQuery.event.global", 2, function() {
assert.ok( jQuery.isPlainObject( jQuery.event.global ), "is a plain object" );
assert.deepEqual( jQuery.event.global, {}, "is an empty object" );
} );
} );
30 changes: 26 additions & 4 deletions test/unit/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QUnit.test( "jQuery.migrateDeduplicateMessages", function( assert ) {
} );

QUnit.test( "disabling/enabling patches", function( assert ) {
assert.expect( 27 );
assert.expect( 32 );

var elem = jQuery( "<div></div>" );

Expand All @@ -56,17 +56,28 @@ QUnit.test( "disabling/enabling patches", function( assert ) {
// existing warnings. If the ones we rely on here get removed,
// replace them with ones that still exist.

// A few APIs that are not slated for removal to make these tests more stable:
assert.strictEqual( jQuery.migrateIsPatchEnabled( "pre-on-methods" ),
true, "patch enabled by default (pre-on-methods)" );
assert.strictEqual( jQuery.migrateIsPatchEnabled( "proxy" ),
true, "patch enabled by default (proxy)" );
assert.strictEqual( jQuery.migrateIsPatchEnabled( "shorthand-deprecated-v3" ),
true, "patch enabled by default (shorthand-deprecated-v3)" );

// APIs patched via `migratePatchAndWarnFunc` or `migratePatchAndInfoFunc`;
// we're testing that:
// * they don't warn on access but only when called
// * they don't exist (access evaluates to `undefined`) if patch is disabled
assert.strictEqual( jQuery.migrateIsPatchEnabled( "push" ),
true, "patch enabled by default (push)" );
assert.strictEqual( jQuery.migrateIsPatchEnabled( "isArray" ),
true, "patch enabled by default (isArray)" );

// APIs patched via `migrateWarnProp` or `migrateInfoProp`; we're testing that:
// * they don't exist (access evaluates to `undefined`) if patch is disabled
assert.strictEqual( jQuery.migrateIsPatchEnabled( "event-global" ),
true, "patch enabled by default (event-global)" );

expectMessage( assert, "pre-on-methods (default)", function() {
jQuery().bind();
} );
Expand All @@ -82,6 +93,11 @@ QUnit.test( "disabling/enabling patches", function( assert ) {
expectMessage( assert, "isArray (default)", function() {
jQuery.isArray();
} );
expectMessage( assert, "event-global (default)", function() {

// eslint-disable-next-line no-unused-expressions
jQuery.event.global;
} );

expectNoMessage( assert, "push access without calling (default)", function() {
assert.strictEqual( typeof jQuery().push, "function",
Expand All @@ -92,7 +108,7 @@ QUnit.test( "disabling/enabling patches", function( assert ) {
"access check doesn't trigger a message (isArray)" );
} );

jQuery.migrateDisablePatches( "pre-on-methods", "proxy", "push", "isArray" );
jQuery.migrateDisablePatches( "pre-on-methods", "proxy", "push", "isArray", "event-global" );
assert.strictEqual( jQuery.migrateIsPatchEnabled( "pre-on-methods" ),
false, "patch disabled (pre-on-methods)" );
assert.strictEqual( jQuery.migrateIsPatchEnabled( "proxy" ),
Expand All @@ -101,6 +117,8 @@ QUnit.test( "disabling/enabling patches", function( assert ) {
true, "patch still enabled (shorthand-deprecated-v3)" );
assert.strictEqual( jQuery.migrateIsPatchEnabled( "push" ),
false, "patch disabled (push)" );
assert.strictEqual( jQuery.migrateIsPatchEnabled( "event-global" ),
false, "patch disabled (event-global)" );

expectNoMessage( assert, "pre-on-methods (disabled)", function() {
jQuery().bind();
Expand All @@ -112,10 +130,14 @@ QUnit.test( "disabling/enabling patches", function( assert ) {
jQuery().click();
} );
expectNoMessage( assert, "push (disabled)", function() {
assert.strictEqual( jQuery().push, undefined, "`push` patch no longer defined" );
assert.strictEqual( jQuery().push, undefined, "`jQuery.fn.push` no longer defined" );
} );
expectNoMessage( assert, "isArray (disabled)", function() {
assert.strictEqual( jQuery.isArray, undefined, "`jQuery.isArray` patch no longer defined" );
assert.strictEqual( jQuery.isArray, undefined, "`jQuery.isArray` no longer defined" );
} );
expectNoMessage( assert, "event-global (disabled)", function() {
assert.strictEqual( jQuery.event.global, undefined,
"`jQuery.event.global` no longer defined" );
} );

jQuery.migrateDisablePatches( "shorthand-deprecated-v3" );
Expand Down
10 changes: 8 additions & 2 deletions warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,22 @@ This is _not_ a warning, but a console log message the plugin shows when it firs

### \[jsonp-promotion\] JQMIGRATE: JSON-to-JSONP auto-promotion is removed

**Cause:** `jQuery.ajax` calls with `dataType: 'json'` with a provided callback are automatically converted by jQuery to JSONP requests unless the options also specify `jsonp: false`. Auto-promoting JSON requests to JSONP introduces a security risk as the developer may be unaware they're not just downloading data but executing code from a remote domain. This auto-promoting behavior is deprecated and will be removed in jQuery 4.0.0.
**Cause:** `jQuery.ajax` calls with `dataType: 'json'` with a provided callback are automatically converted by jQuery to JSONP requests unless the options also specify `jsonp: false`. Auto-promoting JSON requests to JSONP introduces a security risk as the developer may be unaware they're not just downloading data but executing code from a remote domain. This auto-promoting behavior is removed in jQuery 4.0.0.

**Solution:** To trigger a JSONP request, specify the `dataType: "jsonp"` option.

### \[deferred-getStackHook\] JQMIGRATE: jQuery.Deferred.getStackHook is removed; use jQuery.Deferred.getErrorHook

**Cause:** `jQuery.Deferred.getStackHook` was originally created to pass the stack trace from before an async barrier to report when a user error (like calling a non-existing function) causes a promise to be rejected. However, passing a stack trace doesn't take source maps into account, so we started advising to pass the whole error object. To make it clearer, we also renamed the API to `jQuery.Deferred.getErrorHook`. The legacy alias will be removed in jQuery 4.0.0
**Cause:** `jQuery.Deferred.getStackHook` was originally created to pass the stack trace from before an async barrier to report when a user error (like calling a non-existing function) causes a promise to be rejected. However, passing a stack trace doesn't take source maps into account, so we started advising to pass the whole error object. To make it clearer, we also renamed the API to `jQuery.Deferred.getErrorHook`. The legacy alias is removed in jQuery 4.0.0.

**Solution:** Rename all usage of `jQuery.Deferred.getStackHook` to `jQuery.Deferred.getErrorHook`. If you previously assigned a function returning an error stack to `jQuery.Deferred.getStackHook` or `jQuery.Deferred.getErrorHook`, change it to return a full error object.

### \[event-global\] JQMIGRATE: jQuery.Deferred.getStackHook is removed; use jQuery.Deferred.getErrorHook

**Cause:** `jQuery.event.global` was an object with keys being event names for which event listeners have ever been added. Originally, it was needed for performance reasons and to fix memory leaks in old IE, but since jQuery 1.9.0, the library has only been recording the events, but it was not using that information anywhere. jQuery 4.0.0 removes the API.

**Solution:** Remove all usage of `jQuery.event.global`; it's unlikely any existing usage is needed.


## Deprecated APIs

Expand Down
Loading