diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2015-01-03 19:55:31 -0500 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2015-01-10 23:07:39 -0500 |
commit | 32bf9178cace8c52a31c468a28adde9a4fdc4671 (patch) | |
tree | eab1aa14d908d5c2357910099adf0853a8d714f6 | |
parent | 0d829f0e9a177038580a59d0b5649fab76b8104f (diff) | |
download | jquery-32bf9178cace8c52a31c468a28adde9a4fdc4671.tar.gz jquery-32bf9178cace8c52a31c468a28adde9a4fdc4671.zip |
Callbacks: Don't abort execution on .lock()
Fixes gh-1990
Closes gh-1991
(cherry picked from commit fc7477f4927100f23f83c22b5142a42d1eac8502)
-rw-r--r-- | src/callbacks.js | 2 | ||||
-rw-r--r-- | test/unit/callbacks.js | 16 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/callbacks.js b/src/callbacks.js index 2c96f0c4a..4ce1bcdc5 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -190,7 +190,7 @@ jQuery.Callbacks = function( options ) { lock: function() { stack = undefined; locked = true; - if ( !memory ) { + if ( !memory && !firing ) { self.disable(); } return this; diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index 1984e578d..b8dc8ab53 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -65,7 +65,7 @@ jQuery.each( tests, function( strFlags, resultString ) { test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() { - expect( 28 ); + expect( 29 ); var cblist, results = resultString.split( /\s+/ ); @@ -94,7 +94,7 @@ jQuery.each( tests, function( strFlags, resultString ) { strictEqual( cblist.disabled(), true, ".disabled() becomes true" ); strictEqual( cblist.locked(), true, "disabling locks" ); - // #13517 - Emptying while firing + // Emptying while firing (#13517) cblist = jQuery.Callbacks( flags ); cblist.add( cblist.empty ); cblist.add( function() { @@ -164,6 +164,16 @@ jQuery.each( tests, function( strFlags, resultString ) { strictEqual( output, "X", "Lock early" ); strictEqual( cblist.locked(), true, "Locking reflected in accessor" ); + // Locking while firing (gh-1990) + output = "X"; + cblist = jQuery.Callbacks( flags ); + cblist.add( cblist.lock ); + cblist.add(function( str ) { + output += str; + }); + cblist.fire( "A" ); + strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" ); + // Ordering output = "X"; cblist = jQuery.Callbacks( flags ); @@ -331,8 +341,6 @@ test( "jQuery.Callbacks.has", function() { strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" ); cb.lock(); strictEqual( cb.has(), false, "locked() list is empty and returns false" ); - - }); test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() { |