Skip to content

Calling .empty() on a disabled callbacks object re-enables it #1790

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

Closed
mgol opened this issue Oct 21, 2014 · 2 comments
Closed

Calling .empty() on a disabled callbacks object re-enables it #1790

mgol opened this issue Oct 21, 2014 · 2 comments

Comments

@mgol
Copy link
Member

mgol commented Oct 21, 2014

Originally reported by TheDistantSea at: http://bugs.jquery.com/ticket/15213

Earlier today I answered  this StackOverflow question, wherein this behavior is shown:

var c = $.Callbacks();
var f = /\* some function */;
c.disable();
c.empty();
c.add(f);
c.disabled(); // of course true
c.fire(); // invokes f!

This behavior occurs in all versions of jQuery I tested (latest 1.9, 1.10, 1.11, 2.0, 2.1) -- here's a  fiddle to easily reproduce it.

The problem is that .disable() relies on setting internal variables of the callbacks object to undefined, and while most other methods such as .add() test and this condition and abort if true, .empty() itself does not. Instead it resets some of those variables, which causes the abort test in the other methods to erroneously pass and ultimately for callbacks to be added to and invoked by a disabled object.

Issue reported for jQuery 1.11.1

@mgol
Copy link
Member Author

mgol commented Oct 21, 2014

Comment author: TheDistantSea

I also made a PR on GitHub:  https://github.com/jquery/jquery/pull/1643

@dmethvin
Copy link
Member

dmethvin commented Dec 3, 2014

@jaubourg can you review?

@dmethvin dmethvin added the Bug label Dec 5, 2014
dmethvin added a commit that referenced this issue Dec 8, 2014
Thanks to @TheDistantSea for the report!

Fixes gh-1790
Closes gh-1643
(cherry picked from commit bc1cb12)
@dmethvin dmethvin added this to the 3.0.0 milestone Dec 8, 2014
dmethvin added a commit that referenced this issue Nov 10, 2015
@dmethvin dmethvin modified the milestones: 1.12/2.2, 3.0.0 Jan 7, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants