Commit fc7477f4 authored by Richard Gibson's avatar Richard Gibson

Callbacks: Don't abort execution on .lock()

Fixes gh-1990
Closes gh-1991
parent f5a8c649
...@@ -190,7 +190,7 @@ jQuery.Callbacks = function( options ) { ...@@ -190,7 +190,7 @@ jQuery.Callbacks = function( options ) {
lock: function() { lock: function() {
stack = undefined; stack = undefined;
locked = true; locked = true;
if ( !memory ) { if ( !memory && !firing ) {
self.disable(); self.disable();
} }
return this; return this;
......
...@@ -65,7 +65,7 @@ jQuery.each( tests, function( strFlags, resultString ) { ...@@ -65,7 +65,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() { test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() {
expect( 28 ); expect( 29 );
var cblist, var cblist,
results = resultString.split( /\s+/ ); results = resultString.split( /\s+/ );
...@@ -94,7 +94,7 @@ jQuery.each( tests, function( strFlags, resultString ) { ...@@ -94,7 +94,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
strictEqual( cblist.disabled(), true, ".disabled() becomes true" ); strictEqual( cblist.disabled(), true, ".disabled() becomes true" );
strictEqual( cblist.locked(), true, "disabling locks" ); strictEqual( cblist.locked(), true, "disabling locks" );
// #13517 - Emptying while firing // Emptying while firing (#13517)
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
cblist.add( cblist.empty ); cblist.add( cblist.empty );
cblist.add( function() { cblist.add( function() {
...@@ -164,6 +164,16 @@ jQuery.each( tests, function( strFlags, resultString ) { ...@@ -164,6 +164,16 @@ jQuery.each( tests, function( strFlags, resultString ) {
strictEqual( output, "X", "Lock early" ); strictEqual( output, "X", "Lock early" );
strictEqual( cblist.locked(), true, "Locking reflected in accessor" ); 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 // Ordering
output = "X"; output = "X";
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
...@@ -331,8 +341,6 @@ test( "jQuery.Callbacks.has", function() { ...@@ -331,8 +341,6 @@ test( "jQuery.Callbacks.has", function() {
strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" ); strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" );
cb.lock(); cb.lock();
strictEqual( cb.has(), false, "locked() list is empty and returns false" ); strictEqual( cb.has(), false, "locked() list is empty and returns false" );
}); });
test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() { test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment