Permalink
Browse files

Callbacks: Disabling a callback should prevent firing

Thanks to @TheDistantSea for the report!

Fixes gh-1790
Closes gh-1643
  • Loading branch information...
dmethvin committed Dec 8, 2014
1 parent 906caeb commit bc1cb122db30be034b3da84ee2546c86e2a5268f
Showing with 19 additions and 2 deletions.
  1. +4 −2 src/callbacks.js
  2. +15 −0 test/unit/callbacks.js
View
@@ -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
View
@@ -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" );
+});

0 comments on commit bc1cb12

Please sign in to comment.