Skip to content

Event: Patch jQuery.event.special's prototype #572

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: 3.x-stable
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
9 changes: 9 additions & 0 deletions src/jquery/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
migrateWarnProp
} from "../main.js";
import "../disablePatches.js";
import { patchProto } from "../utils.js";

var oldLoad = jQuery.fn.load,
oldEventAdd = jQuery.event.add,
Expand Down Expand Up @@ -136,3 +137,11 @@ migratePatchAndWarnFunc( jQuery.fn, "undelegate", function( selector, types, fn
migratePatchAndWarnFunc( jQuery.fn, "hover", function( fnOver, fnOut ) {
return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
}, "pre-on-methods", "jQuery.fn.hover() is deprecated" );

// We can apply the patch unconditionally here as in the `3.x` line the API
// inherits from `Object.prototype` even without a patch and `migrateWarn`
// inside `patchProto` will already silence warnings if the patch gets disabled.
patchProto( jQuery.event.special, {
warningId: "event-special-null-proto",
apiName: "jQuery.event.special"
} );
24 changes: 24 additions & 0 deletions test/unit/jquery/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,27 @@ TestManager.runIframeTest( "Load within a ready handler", "event-lateload.html",
JSON.stringify( jQuery.migrateWarnings ) );
assert.ok( /load/.test( jQuery.migrateWarnings[ 0 ] ), "message ok" );
} );

QUnit.test( "jQuery.event.special: properties from Object.prototype", function( assert ) {
assert.expect( 4 );

try {
expectNoWarning( assert, "Regular properties", function() {
jQuery.event.special.fakeevent = {};

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

(
Object.setPrototypeOf ? expectWarning : expectNoWarning
)( assert, "Properties from Object.prototype", 2, function() {
assert.ok( jQuery.event.special.hasOwnProperty( "fakeevent" ),
"hasOwnProperty works (property present)" );
assert.ok( !jQuery.event.special.hasOwnProperty( "fakeevent2" ),
"hasOwnProperty works (property missing)" );
} );
} finally {
delete jQuery.event.special.fakeevent;
}
} );
Loading