]> source.dussan.org Git - jquery.git/commitdiff
Callbacks: Prevent add() from unlocking with-memory lists
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 9 Jan 2017 19:33:39 +0000 (11:33 -0800)
committerGitHub <noreply@github.com>
Mon, 9 Jan 2017 19:33:39 +0000 (11:33 -0800)
Fixes gh-3469
Closes gh-3470

src/callbacks.js
test/unit/callbacks.js

index a6d4df03fbbcecf6493e588a6ecb6bc4916396b0..8831e531af8f3b9f85341ef456af8e6256cba5ac 100644 (file)
@@ -69,7 +69,7 @@ jQuery.Callbacks = function( options ) {
                fire = function() {
 
                        // Enforce single-firing
-                       locked = options.once;
+                       locked = locked || options.once;
 
                        // Execute callbacks for all pending executions,
                        // respecting firingIndex overrides and runtime changes
index c6c379dede88552d4fcac5697fee38e0f29aff98..04d44443d274b33cea25a59f0659ae7b457c288b 100644 (file)
@@ -366,3 +366,24 @@ QUnit.test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", fun
        cb.fire();
        assert.ok( !fired, "Disabled callback function didn't fire" );
 } );
+
+QUnit.test( "jQuery.Callbacks() - list with memory stays locked (gh-3469)", function( assert ) {
+
+       assert.expect( 3 );
+
+       var cb = jQuery.Callbacks( "memory" ),
+               fired = 0,
+               count1 = function() { fired += 1; },
+               count2 = function() { fired += 10; };
+
+       cb.add( count1 );
+       cb.fire();
+       assert.equal( fired, 1, "Pre-lock() fire" );
+
+       cb.lock();
+       cb.add( count2 );
+       assert.equal( fired, 11, "Post-lock() add" );
+
+       cb.fire();
+       assert.equal( fired, 11, "Post-lock() fire ignored" );
+} );