Skip to content

Commit bcaeb00

Browse files
authored
Event: Avoid collisions between jQuery.event.special & Object.prototype
This is a follow-up to similar changes to data & event storages from gh-4603. Closes gh-5235 Ref gh-4603
1 parent dfe212d commit bcaeb00

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/event.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ jQuery.event = {
429429
new jQuery.Event( originalEvent );
430430
},
431431

432-
special: {
432+
special: jQuery.extend( Object.create( null ), {
433433
load: {
434434

435435
// Prevent triggered image.load events from bubbling to window.load
@@ -494,7 +494,7 @@ jQuery.event = {
494494
}
495495
}
496496
}
497-
}
497+
} )
498498
};
499499

500500
// Ensure the presence of an event listener that handles manually-triggered

test/unit/event.js

+20
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,26 @@ QUnit.test( ".on and .off, selective mixed removal (trac-10705)", function( asse
24282428
.trigger( "click" ); // 0
24292429
} );
24302430

2431+
QUnit.test( "special interference with Object.prototype", function( assert ) {
2432+
assert.expect( 1 );
2433+
2434+
var triggered = false;
2435+
2436+
Object.prototype.jqfake = {
2437+
trigger: function() {
2438+
triggered = true;
2439+
}
2440+
};
2441+
2442+
jQuery( "<div></div>" )
2443+
.appendTo( "#qunit-fixture" )
2444+
.trigger( "jqfake" );
2445+
2446+
delete Object.prototype.jqfake;
2447+
2448+
assert.ok( !triggered, "Object.prototype.jqfake.trigger not called" );
2449+
} );
2450+
24312451
QUnit.test( ".on( event-map, null-selector, data ) trac-11130", function( assert ) {
24322452

24332453
assert.expect( 1 );

0 commit comments

Comments
 (0)