]> source.dussan.org Git - jquery.git/commitdiff
Callbacks: Disabling a callback should prevent firing
authorDave Methvin <dave.methvin@gmail.com>
Mon, 8 Dec 2014 01:51:04 +0000 (20:51 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Mon, 8 Dec 2014 01:51:04 +0000 (20:51 -0500)
Thanks to @TheDistantSea for the report!

Fixes gh-1790
Closes gh-1643

src/callbacks.js
test/unit/callbacks.js

index 30fa1a30f1667dbe344f499b497ef29d221adff3..55a9d719d655aa64417b0bbe2b6379a1d3d0cb10 100644 (file)
@@ -151,8 +151,10 @@ jQuery.Callbacks = function( options ) {
                        },
                        // Remove all callbacks from the list
                        empty: function() {
-                               list = [];
-                               firingLength = 0;
+                               if ( list ) {
+                                       list = [];
+                                       firingLength = 0;
+                               }
                                return this;
                        },
                        // Have the list do nothing anymore
index 843c958493bceeaf57d646eb335c84b93b55aee3..d997a0d9e127041f096b36b9496f391b590c3c8a 100644 (file)
@@ -340,3 +340,18 @@ test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", fun
 
        ok( true, "no stack overflow" );
 });
+
+test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function() {
+
+       expect( 1 );
+
+       var cb = jQuery.Callbacks(),
+               fired = false,
+               shot = function() { fired = true; };
+
+       cb.disable();
+       cb.empty();
+       cb.add( shot );
+       cb.fire();
+       ok( !fired, "Disabled callback function didn't fire" );
+});