Bug 1042561 - Ensure a canceled autocomplete search doesn't notify about results when aborted shortly before completion r=mak
authorTim Taubert <ttaubert@mozilla.com>
Mon, 23 Mar 2015 08:32:10 +0100
changeset 265621 8b4af50a0cb806f76c804c0e662e22a0d99d9d4d
parent 265620 0d2789cdae9170c827cc0caef1b9b109551894db
child 265622 63f55bf75ba9226c1c4cb9589b1b59c019b3f3c5
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1042561
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1042561 - Ensure a canceled autocomplete search doesn't notify about results when aborted shortly before completion r=mak
toolkit/components/satchel/nsFormAutoComplete.js
--- a/toolkit/components/satchel/nsFormAutoComplete.js
+++ b/toolkit/components/satchel/nsFormAutoComplete.js
@@ -269,24 +269,30 @@ FormAutoComplete.prototype = {
         let processResults = {
           handleResult: aResult => {
             results.push(aResult);
           },
           handleError: aError => {
             this.log("getAutocompleteValues failed: " + aError.message);
           },
           handleCompletion: aReason => {
-            this._pendingQuery = null;
-            if (!aReason) {
-              callback(results);
+            // Check that the current query is still the one we created. Our
+            // query might have been canceled shortly before completing, in
+            // that case we don't want to call the callback anymore.
+            if (query == this._pendingQuery) {
+              this._pendingQuery = null;
+              if (!aReason) {
+                callback(results);
+              }
             }
           }
         };
 
-        this._pendingQuery = FormHistory.getAutoCompleteResults(searchString, params, processResults);
+        let query = FormHistory.getAutoCompleteResults(searchString, params, processResults);
+        this._pendingQuery = query;
     },
 
     /*
      * _calculateScore
      *
      * entry    -- an nsIAutoCompleteResult entry
      * aSearchString -- current value of the input (lowercase)
      * searchTokens -- array of tokens of the search string