]> source.dussan.org Git - jquery.git/commitdiff
Fixes #9104. Returning null or undefined in a pipe callback shouldn't end up throwing...
authorjaubourg <j@ubourg.net>
Mon, 9 May 2011 08:01:20 +0000 (10:01 +0200)
committerjaubourg <j@ubourg.net>
Mon, 9 May 2011 08:01:20 +0000 (10:01 +0200)
src/deferred.js
test/unit/deferred.js

index 02f92b26ce0dbfe1118ddc01913dfb3f9c84c57f..5cc5fb5be951dfbf346637b8b13fa6da9ff67cf9 100644 (file)
@@ -119,7 +119,7 @@ jQuery.extend({
                                                if ( jQuery.isFunction( fn ) ) {
                                                        deferred[ handler ](function() {
                                                                returned = fn.apply( this, arguments );
-                                                               if ( jQuery.isFunction( returned.promise ) ) {
+                                                               if ( returned && jQuery.isFunction( returned.promise ) ) {
                                                                        returned.promise().then( newDefer.resolve, newDefer.reject );
                                                                } else {
                                                                        newDefer[ action ]( returned );
index c71fbdbe7c31abd4060fdce3b7bdfebb386d057e..89c9c612d931b1f966bade3e22df28d41243f7d0 100644 (file)
@@ -145,7 +145,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
 
 test( "jQuery.Deferred.pipe - filtering (done)", function() {
 
-       expect(3);
+       expect(4);
 
        var defer = jQuery.Deferred(),
                piped = defer.pipe(function( a, b ) {
@@ -173,11 +173,15 @@ test( "jQuery.Deferred.pipe - filtering (done)", function() {
        jQuery.Deferred().reject().pipe(function() {
                ok( false, "pipe should not be called on reject" );
        });
+
+       jQuery.Deferred().resolve().pipe( jQuery.noop ).done(function( value ) {
+               strictEqual( value, undefined, "pipe done callback can return undefined/null" );
+       });
 });
 
 test( "jQuery.Deferred.pipe - filtering (fail)", function() {
 
-       expect(3);
+       expect(4);
 
        var defer = jQuery.Deferred(),
                piped = defer.pipe( null, function( a, b ) {
@@ -205,6 +209,10 @@ test( "jQuery.Deferred.pipe - filtering (fail)", function() {
        jQuery.Deferred().resolve().pipe( null, function() {
                ok( false, "pipe should not be called on resolve" );
        } );
+
+       jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail(function( value ) {
+               strictEqual( value, undefined, "pipe fail callback can return undefined/null" );
+       });
 });
 
 test( "jQuery.Deferred.pipe - deferred (done)", function() {