From ff7b7cfd1d754f6daf20541dc71c84ad690d3708 Mon Sep 17 00:00:00 2001 From: Nikita Govorov Date: Sun, 19 Aug 2012 20:19:44 -0400 Subject: [PATCH] Fix #12149. Avoid memory leak on oldIE change events. Close gh-878. --- AUTHORS.txt | 1 + src/event.js | 2 +- test/unit/event.js | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 51200abaf..01c8d76b0 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -130,3 +130,4 @@ Uri Gilad Chris Faulkner Elijah Manor Daniel Chatfield +Nikita Govorov \ No newline at end of file diff --git a/src/event.js b/src/event.js index 2a2ea24aa..797f1aaee 100644 --- a/src/event.js +++ b/src/event.js @@ -832,7 +832,7 @@ if ( !jQuery.support.changeBubbles ) { teardown: function() { jQuery.event.remove( this, "._change" ); - return rformElems.test( this.nodeName ); + return !rformElems.test( this.nodeName ); } }; } diff --git a/test/unit/event.js b/test/unit/event.js index 16a9ff0fc..c1981623d 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2985,6 +2985,29 @@ if ( hasPHP ) { })(); +test("change handler should be detached from element", function() { + expect( 2 ); + + var $fixture = jQuery( "" ).appendTo( "body" ); + + var originRemoveEvent = jQuery.removeEvent; + + var wrapperRemoveEvent = function(elem, type, handle){ + equal("change", type, "Event handler for 'change' event should be removed"); + equal("change-ie-leak", jQuery(elem).attr("id"), "Event handler for 'change' event should be removed from appropriate element"); + originRemoveEvent(elem, type, handle); + }; + + jQuery.removeEvent = wrapperRemoveEvent ; + + $fixture.bind( "change", function( event ) {}); + $fixture.unbind( "change" ); + + $fixture.remove(); + + jQuery.removeEvent = originRemoveEvent; +}); + asyncTest("trigger click on checkbox, fires change event", function() { expect(1); -- 2.39.5