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

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

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

Comments

Projects
None yet
3 participants
@mgol
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

This comment has been minimized.

Show comment
Hide comment
@mgol

mgol Oct 21, 2014

Member

Comment author: TheDistantSea

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

Member

mgol commented Oct 21, 2014

Comment author: TheDistantSea

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

@dmethvin

This comment has been minimized.

Show comment
Hide comment
@dmethvin

dmethvin Dec 3, 2014

Member

@jaubourg can you review?

Member

dmethvin commented Dec 3, 2014

@jaubourg can you review?

@dmethvin dmethvin added the Bug label Dec 5, 2014

@dmethvin dmethvin closed this in bc1cb12 Dec 8, 2014

dmethvin added a commit that referenced this issue Dec 8, 2014

Callbacks: Disabling a callback should prevent firing
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

@cssmagic cssmagic referenced this issue May 18, 2016

Open

jQuery #5

@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.