mediawiki.api: Don't hold references to finished requests forever
[lhc/web/wiklou.git] / resources / src / mediawiki / api.js
index 481bd89..5f82b18 100644 (file)
@@ -67,7 +67,6 @@
         *  each individual request by passing them to #get or #post (or directly #ajax) later on.
         */
        mw.Api = function ( options ) {
-               // TODO: Share API objects with exact same config.
                options = options || {};
 
                // Force a string if we got a mw.Uri object
@@ -90,7 +89,9 @@
                 */
                abort: function () {
                        $.each( this.requests, function ( index, request ) {
-                               request.abort();
+                               if ( request ) {
+                                       request.abort();
+                               }
                        } );
                },
 
                 *  Fail: Error code
                 */
                ajax: function ( parameters, ajaxOptions ) {
-                       var token,
+                       var token, requestIndex,
+                               api = this,
                                apiDeferred = $.Deferred(),
                                xhr, key, formData;
 
                                        }
                                } );
 
+                       requestIndex = this.requests.length;
                        this.requests.push( xhr );
+                       xhr.always( function () {
+                               api.requests[ requestIndex ] = null;
+                       } );
                        // Return the Promise
                        return apiDeferred.promise( { abort: xhr.abort } ).fail( function ( code, details ) {
                                if ( !( code === 'http' && details && details.textStatus === 'abort' ) ) {