Skip to content

Commit 2223605

Browse files
committed
Event: Patch jQuery.event.global
The API has been write-only since 1.9.0 and is going to be removed in jQuery 4.0.0. Also: * make it more explicit why certain patches are tested in the context of `jQuery.migrateDisablePatches` & related APIs * fix an erroneous future tense in a few warnings
1 parent 0ea1015 commit 2223605

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

src/jquery/event.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
migrateWarn,
3+
migrateWarnProp,
34
migratePatchAndInfoFunc,
45
migratePatchFunc
56
} from "../main.js";
@@ -41,3 +42,6 @@ migratePatchAndInfoFunc( jQuery.fn, "undelegate", jQuery.fn.undelegate,
4142

4243
migratePatchAndInfoFunc( jQuery.fn, "hover", jQuery.fn.hover,
4344
"hover", "jQuery.fn.hover() is deprecated" );
45+
46+
migrateWarnProp( jQuery.event, "global", {}, "event-global",
47+
"jQuery.event.global is removed" );

test/unit/jquery/event.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,12 @@ TestManager.runIframeTest( "Load within a ready handler", "event-lateload.html",
8484
JSON.stringify( jQuery.migrateMessages ) );
8585
assert.ok( /load/.test( jQuery.migrateMessages[ 0 ] ), "message ok" );
8686
} );
87+
88+
QUnit.test( "jQuery.event.global", function( assert ) {
89+
assert.expect( 3 );
90+
91+
expectMessage( assert, "jQuery.event.global", 2, function() {
92+
assert.ok( jQuery.isPlainObject( jQuery.event.global ), "is a plain object" );
93+
assert.deepEqual( jQuery.event.global, {}, "is an empty object" );
94+
} );
95+
} );

test/unit/migrate.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ QUnit.test( "jQuery.migrateDeduplicateMessages", function( assert ) {
4646
} );
4747

4848
QUnit.test( "disabling/enabling patches", function( assert ) {
49-
assert.expect( 27 );
49+
assert.expect( 32 );
5050

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

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

59+
// A few APIs that are not slated for removal to make these tests more stable:
5960
assert.strictEqual( jQuery.migrateIsPatchEnabled( "pre-on-methods" ),
6061
true, "patch enabled by default (pre-on-methods)" );
6162
assert.strictEqual( jQuery.migrateIsPatchEnabled( "proxy" ),
6263
true, "patch enabled by default (proxy)" );
6364
assert.strictEqual( jQuery.migrateIsPatchEnabled( "shorthand-deprecated-v3" ),
6465
true, "patch enabled by default (shorthand-deprecated-v3)" );
66+
67+
// APIs patched via `migratePatchAndWarnFunc` or `migratePatchAndInfoFunc`;
68+
// we're testing that:
69+
// * they don't warn on access but only when called
70+
// * they don't exist (access evaluates to `undefined`) if patch is disabled
6571
assert.strictEqual( jQuery.migrateIsPatchEnabled( "push" ),
6672
true, "patch enabled by default (push)" );
6773
assert.strictEqual( jQuery.migrateIsPatchEnabled( "isArray" ),
6874
true, "patch enabled by default (isArray)" );
6975

76+
// APIs patched via `migrateWarnProp` or `migrateInfoProp`; we're testing that:
77+
// * they don't exist (access evaluates to `undefined`) if patch is disabled
78+
assert.strictEqual( jQuery.migrateIsPatchEnabled( "event-global" ),
79+
true, "patch enabled by default (event-global)" );
80+
7081
expectMessage( assert, "pre-on-methods (default)", function() {
7182
jQuery().bind();
7283
} );
@@ -82,6 +93,11 @@ QUnit.test( "disabling/enabling patches", function( assert ) {
8293
expectMessage( assert, "isArray (default)", function() {
8394
jQuery.isArray();
8495
} );
96+
expectMessage( assert, "event-global (default)", function() {
97+
98+
// eslint-disable-next-line no-unused-expressions
99+
jQuery.event.global;
100+
} );
85101

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

95-
jQuery.migrateDisablePatches( "pre-on-methods", "proxy", "push", "isArray" );
111+
jQuery.migrateDisablePatches( "pre-on-methods", "proxy", "push", "isArray", "event-global" );
96112
assert.strictEqual( jQuery.migrateIsPatchEnabled( "pre-on-methods" ),
97113
false, "patch disabled (pre-on-methods)" );
98114
assert.strictEqual( jQuery.migrateIsPatchEnabled( "proxy" ),
@@ -101,6 +117,8 @@ QUnit.test( "disabling/enabling patches", function( assert ) {
101117
true, "patch still enabled (shorthand-deprecated-v3)" );
102118
assert.strictEqual( jQuery.migrateIsPatchEnabled( "push" ),
103119
false, "patch disabled (push)" );
120+
assert.strictEqual( jQuery.migrateIsPatchEnabled( "event-global" ),
121+
false, "patch disabled (event-global)" );
104122

105123
expectNoMessage( assert, "pre-on-methods (disabled)", function() {
106124
jQuery().bind();
@@ -112,10 +130,14 @@ QUnit.test( "disabling/enabling patches", function( assert ) {
112130
jQuery().click();
113131
} );
114132
expectNoMessage( assert, "push (disabled)", function() {
115-
assert.strictEqual( jQuery().push, undefined, "`push` patch no longer defined" );
133+
assert.strictEqual( jQuery().push, undefined, "`jQuery.fn.push` no longer defined" );
116134
} );
117135
expectNoMessage( assert, "isArray (disabled)", function() {
118-
assert.strictEqual( jQuery.isArray, undefined, "`jQuery.isArray` patch no longer defined" );
136+
assert.strictEqual( jQuery.isArray, undefined, "`jQuery.isArray` no longer defined" );
137+
} );
138+
expectNoMessage( assert, "event-global (disabled)", function() {
139+
assert.strictEqual( jQuery.event.global, undefined,
140+
"`jQuery.event.global` no longer defined" );
119141
} );
120142

121143
jQuery.migrateDisablePatches( "shorthand-deprecated-v3" );

warnings.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,22 @@ This is _not_ a warning, but a console log message the plugin shows when it firs
161161

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

164-
**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.
164+
**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.
165165

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

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

170-
**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
170+
**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.
171171

172172
**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.
173173

174+
### \[event-global\] JQMIGRATE: jQuery.Deferred.getStackHook is removed; use jQuery.Deferred.getErrorHook
175+
176+
**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.
177+
178+
**Solution:** Remove all usage of `jQuery.event.global`; it's unlikely any existing usage is needed.
179+
174180

175181
## Deprecated APIs
176182

0 commit comments

Comments
 (0)