mediawiki.api: Fix getToken() incompat with jQuery 3.0
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 23 Nov 2016 20:13:06 +0000 (12:13 -0800)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 29 Nov 2016 03:14:26 +0000 (19:14 -0800)
* getToken()'s fail() handler deletes property from promiseGroup.
  However sometimes this doesn't exist yet for the current api url.
  Move the block that creates this object higher up.

* Deferred.then() used to have an undocumented 'this' context.
  No longer exists in jQuery 3.0, but we weren't supposed to be
  using returning it as-is anyway.
  Return a new Deferred instead, like we do elsewhere.

Bug: T124742
Change-Id: I52c6bb779c5e79161e38a5d0c7c2cb3b458be9ba

resources/src/mediawiki/api.js

index b9e05c3..0c08ca4 100644 (file)
                                                        } );
                                                }
 
-                                               // Different error, pass on to let caller handle the error code
-                                               return this;
+                                               // Let caller handle the error code
+                                               return $.Deferred().rejectWith( this, arguments );
                                        }
                                );
                        } ).promise( { abort: function () {
                        promiseGroup = promises[ this.defaults.ajax.url ];
                        d = promiseGroup && promiseGroup[ type + 'Token' ];
 
+                       if ( !promiseGroup ) {
+                               promiseGroup = promises[ this.defaults.ajax.url ] = {};
+                       }
+
                        if ( !d ) {
                                apiPromise = this.get( {
                                        action: 'query',
                                                // Clear promise. Do not cache errors.
                                                delete promiseGroup[ type + 'Token' ];
 
-                                               // Pass on to allow the caller to handle the error
-                                               return this;
+                                               // Let caller handle the error code
+                                               return $.Deferred().rejectWith( this, arguments );
                                        } )
                                        // Attach abort handler
                                        .promise( { abort: apiPromise.abort } );
 
                                // Store deferred now so that we can use it again even if it isn't ready yet
-                               if ( !promiseGroup ) {
-                                       promiseGroup = promises[ this.defaults.ajax.url ] = {};
-                               }
                                promiseGroup[ type + 'Token' ] = d;
                        }