]> source.dussan.org Git - jquery.git/commitdiff
Landing pull request 520. Unset the complete function just before calling it to avoid...
authorCorey Frang <gnarf@gnarf.net>
Wed, 28 Sep 2011 16:00:21 +0000 (12:00 -0400)
committertimmywil <timmywillisn@gmail.com>
Wed, 28 Sep 2011 16:00:21 +0000 (12:00 -0400)
More Details:
 - https://github.com/jquery/jquery/pull/520
 - http://bugs.jquery.com/ticket/5684

src/effects.js
test/unit/effects.js

index ee535e3cd8e85e5165f4b2db31fa32ed9ababcb4..e14235bc41e0ea7330ccdbca8a6367fadb721eb7 100644 (file)
@@ -481,11 +481,11 @@ jQuery.fx.prototype = {
 
        // Each step of an animation
        step: function( gotoEnd ) {
-               var t = fxNow || createFxNow(),
+               var p, n, complete,
+                       t = fxNow || createFxNow(),
                        done = true,
                        elem = this.elem,
-                       options = this.options,
-                       p, n;
+                       options = this.options;
 
                if ( gotoEnd || t >= options.duration + this.startTime ) {
                        this.now = this.end;
@@ -525,7 +525,15 @@ jQuery.fx.prototype = {
                                }
 
                                // Execute the complete function
-                               options.complete.call( elem );
+                               // in the event that the complete function throws an exception
+                               // we must ensure it won't be called twice. #5684
+
+                               complete = options.complete;
+                               if ( complete ) {
+
+                                       options.complete = false;
+                                       complete.call( elem );
+                               }
                        }
 
                        return false;
index da1dd0a623bc54a27c158dde784765841809a7a7..24f1b53f9734b589e69ee32a7b51ad948059989f 100644 (file)
@@ -1205,3 +1205,35 @@ test("callbacks should fire in correct order (#9100)", function() {
                                }
                        });
 });
+
+asyncTest( "callbacks that throw exceptions will be removed (#5684)", function() {
+       expect( 2 );
+
+       var foo = jQuery( "#foo" );
+
+       function testException() {
+       }
+
+       foo.animate({ height: 1 }, 1, function() {
+               throw new testException;
+       });
+
+       // this test thoroughly abuses undocumented methods - please feel free to update
+       // with any changes internally to these functions.
+
+       // make sure that the standard timer loop will NOT run.
+       jQuery.fx.stop();
+
+       setTimeout(function() {
+
+               // the first call to fx.tick should raise the callback exception
+               raises( jQuery.fx.tick, testException, "Exception was thrown" );
+
+               // the second call shouldn't
+               jQuery.fx.tick();
+
+               ok( true, "Test completed without throwing a second exception" );
+
+               start();
+       }, 1);
+});