From 793925ff3be0a185ba5d2c733252eac324fb3cd5 Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Fri, 13 Nov 2015 16:38:00 +0300 Subject: [PATCH] Revert "Callbacks: Don't abort execution on .lock()" This reverts commit 32bf9178cace8c52a31c468a28adde9a4fdc4671. --- src/callbacks.js | 2 +- test/unit/callbacks.js | 64 ++++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/callbacks.js b/src/callbacks.js index 58a9a5800..ce21571ed 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -206,7 +206,7 @@ jQuery.Callbacks = function( options ) { lock: function() { stack = undefined; locked = true; - if ( !memory && !firing ) { + if ( !memory ) { self.disable(); } return this; diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index c6c379ded..0bae02a87 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -65,7 +65,7 @@ jQuery.each( tests, function( strFlags, resultString ) { QUnit.test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function( assert ) { - assert.expect( 29 ); + assert.expect( 28 ); var cblist, results = resultString.split( /\s+/ ); @@ -76,20 +76,20 @@ jQuery.each( tests, function( strFlags, resultString ) { assert.strictEqual( cblist.locked(), false, ".locked() initially false" ); assert.strictEqual( cblist.disabled(), false, ".disabled() initially false" ); assert.strictEqual( cblist.fired(), false, ".fired() initially false" ); - cblist.add( function( str ) { + cblist.add(function( str ) { output += str; - } ); + }); assert.strictEqual( cblist.fired(), false, ".fired() still false after .add" ); cblist.fire( "A" ); assert.strictEqual( output, "XA", "Basic binding and firing" ); assert.strictEqual( cblist.fired(), true, ".fired() detects firing" ); output = "X"; cblist.disable(); - cblist.add( function( str ) { + cblist.add(function( str ) { output += str; - } ); + }); assert.strictEqual( output, "X", "Adding a callback after disabling" ); - cblist.fire( "A" ); + cblist.fire("A"); assert.strictEqual( output, "X", "Firing after disabling" ); assert.strictEqual( cblist.disabled(), true, ".disabled() becomes true" ); assert.strictEqual( cblist.locked(), true, "disabling locks" ); @@ -113,20 +113,20 @@ jQuery.each( tests, function( strFlags, resultString ) { // Basic binding and firing (context, arguments) output = "X"; cblist = jQuery.Callbacks( flags ); - cblist.add( function() { + cblist.add(function() { assert.equal( this, window, "Basic binding and firing (context)" ); output += Array.prototype.join.call( arguments, "" ); - } ); + }); cblist.fireWith( window, [ "A", "B" ] ); assert.strictEqual( output, "XAB", "Basic binding and firing (arguments)" ); // fireWith with no arguments output = ""; cblist = jQuery.Callbacks( flags ); - cblist.add( function() { + cblist.add(function() { assert.equal( this, window, "fireWith with no arguments (context is window)" ); assert.strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" ); - } ); + }); cblist.fireWith(); // Basic binding, removing and firing @@ -150,34 +150,24 @@ jQuery.each( tests, function( strFlags, resultString ) { // Locking output = "X"; cblist = jQuery.Callbacks( flags ); - cblist.add( function( str ) { + cblist.add(function( str ) { output += str; - } ); + }); cblist.lock(); - cblist.add( function( str ) { + cblist.add(function( str ) { output += str; - } ); - cblist.fire( "A" ); - cblist.add( function( str ) { + }); + cblist.fire("A"); + cblist.add(function( str ) { output += str; - } ); + }); assert.strictEqual( output, "X", "Lock early" ); assert.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" ); - assert.strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" ); - // Ordering output = "X"; cblist = jQuery.Callbacks( flags ); - cblist.add( function() { + cblist.add(function() { cblist.add( outputC ); outputA(); }, outputB ); @@ -186,7 +176,7 @@ jQuery.each( tests, function( strFlags, resultString ) { // Add and fire again output = "X"; - cblist.add( function() { + cblist.add(function() { cblist.add( outputC ); outputA(); }, outputB ); @@ -199,23 +189,23 @@ jQuery.each( tests, function( strFlags, resultString ) { // Multiple fire output = "X"; cblist = jQuery.Callbacks( flags ); - cblist.add( function( str ) { + cblist.add(function( str ) { output += str; - } ); - cblist.fire( "A" ); + }); + cblist.fire("A"); assert.strictEqual( output, "XA", "Multiple fire (first fire)" ); output = "X"; - cblist.add( function( str ) { + cblist.add(function( str ) { output += str; - } ); + }); assert.strictEqual( output, results.shift(), "Multiple fire (first new callback)" ); output = "X"; - cblist.fire( "B" ); + cblist.fire("B"); assert.strictEqual( output, results.shift(), "Multiple fire (second fire)" ); output = "X"; - cblist.add( function( str ) { + cblist.add(function( str ) { output += str; - } ); + }); assert.strictEqual( output, results.shift(), "Multiple fire (second new callback)" ); // Return false -- 2.39.5