Bug 1353542 - pre-script hand-written cleanup patch, r=Mossop.
authorFlorian Quèze <florian@queze.net>
Fri, 12 May 2017 14:41:20 +0200
changeset 406186 eac6de13a9e7665668fa1fa346107bd4d41a6619
parent 406185 030c0a7c878192d8dc1b04c182575c2f7858cdd0
child 406187 7970ea0858614c4de33e32fb59738ddc9c3efc23
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1353542
milestone55.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 1353542 - pre-script hand-written cleanup patch, r=Mossop.
browser/components/customizableui/PanelMultiView.jsm
browser/experiments/test/xpcshell/test_cache.js
toolkit/components/extensions/ExtensionStorageSync.jsm
toolkit/components/places/PlacesSyncUtils.jsm
toolkit/components/places/PlacesTransactions.jsm
toolkit/content/tests/chrome/test_popup_keys.xul
toolkit/modules/AsyncPrefs.jsm
toolkit/modules/Sqlite.jsm
--- a/browser/components/customizableui/PanelMultiView.jsm
+++ b/browser/components/customizableui/PanelMultiView.jsm
@@ -355,17 +355,17 @@ this.PanelMultiView = class {
       }
 
       this._shiftMainView();
     }
   }
 
   showSubView(aViewId, aAnchor, aPreviousView, aAdopted = false) {
     const {document, window} = this;
-    return window.Task.spawn(function*() {
+    return Task.spawn(function*() {
       // Support passing in the node directly.
       let viewNode = typeof aViewId == "string" ? this.node.querySelector("#" + aViewId) : aViewId;
       if (!viewNode) {
         viewNode = document.getElementById(aViewId);
         if (viewNode) {
           if (this.panelViews) {
             this._viewStack.appendChild(viewNode);
             this.panelViews.push(viewNode);
@@ -412,17 +412,17 @@ this.PanelMultiView = class {
       viewNode.setAttribute("current", true);
 
       let evt = new window.CustomEvent("ViewShowing", { bubbles: true, cancelable: true, detail });
       viewNode.dispatchEvent(evt);
 
       let cancel = evt.defaultPrevented;
       if (detail.blockers.size) {
         try {
-          let results = yield window.Promise.all(detail.blockers);
+          let results = yield Promise.all(detail.blockers);
           cancel = cancel || results.some(val => val === false);
         } catch (e) {
           Cu.reportError(e);
           cancel = true;
         }
       }
 
       if (cancel) {
--- a/browser/experiments/test/xpcshell/test_cache.js
+++ b/browser/experiments/test/xpcshell/test_cache.js
@@ -314,17 +314,17 @@ add_task(function* test_expiration() {
     endDates .push(futureDate(startDates[i], 50 * MS_IN_ONE_DAY));
     experiment.startTime = dateToSeconds(startDates[i]);
     experiment.endTime   = dateToSeconds(endDates[i]);
   }
 
   let now = null;
   let experiments = null;
 
-  let setDateAndRestartExperiments = new Task.async(function* (newDate) {
+  let setDateAndRestartExperiments = Task.async(function* (newDate) {
     now = newDate;
     defineNow(gPolicy, now);
 
     yield promiseRestartManager();
     experiments = new Experiments.Experiments(gPolicy);
     yield experiments._run();
   });
 
--- a/toolkit/components/extensions/ExtensionStorageSync.jsm
+++ b/toolkit/components/extensions/ExtensionStorageSync.jsm
@@ -729,16 +729,17 @@ function cleanUpForContext(extension, co
     // Nobody else is using this collection. Clean up.
     extensionContexts.delete(extension);
   }
 }
 
 /**
  * Generate a promise that produces the Collection for an extension.
  *
+ * @param {CryptoCollection} cryptoCollection
  * @param {Extension} extension
  *                    The extension whose collection needs to
  *                    be opened.
  * @param {Context} context
  *                  The context for this extension. The Collection
  *                  will shut down automatically when all contexts
  *                  close.
  * @returns {Promise<Collection>}
--- a/toolkit/components/places/PlacesSyncUtils.jsm
+++ b/toolkit/components/places/PlacesSyncUtils.jsm
@@ -1065,17 +1065,17 @@ var insertBookmarkMetadata = Task.async(
     PlacesUtils.annotations.setItemAnnotation(itemId,
       BookmarkSyncUtils.SMART_BOOKMARKS_ANNO, insertInfo.query, 0,
       PlacesUtils.annotations.EXPIRE_NEVER,
       SOURCE_SYNC);
     newItem.query = insertInfo.query;
   }
 
   try {
-    newItem.tags = yield tagItem(bookmarkItem, insertInfo.tags);
+    newItem.tags = tagItem(bookmarkItem, insertInfo.tags);
   } catch (ex) {
     BookmarkSyncLog.warn(`insertBookmarkMetadata: Error tagging item ${
       insertInfo.syncId}`, ex);
   }
 
   if (insertInfo.keyword) {
     yield removeConflictingKeywords(bookmarkItem.url, insertInfo.keyword);
     yield PlacesUtils.keywords.insert({
@@ -1290,17 +1290,17 @@ var updateSyncBookmark = Task.async(func
 // Sync bookmark object.
 var updateBookmarkMetadata = Task.async(function* (oldBookmarkItem,
                                                    newBookmarkItem,
                                                    updateInfo) {
   let itemId = yield PlacesUtils.promiseItemId(newBookmarkItem.guid);
   let newItem = yield placesBookmarkToSyncBookmark(newBookmarkItem);
 
   try {
-    newItem.tags = yield tagItem(newBookmarkItem, updateInfo.tags);
+    newItem.tags = tagItem(newBookmarkItem, updateInfo.tags);
   } catch (ex) {
     BookmarkSyncLog.warn(`updateBookmarkMetadata: Error tagging item ${
       updateInfo.syncId}`, ex);
   }
 
   if (updateInfo.hasOwnProperty("keyword")) {
     // Unconditionally remove the old keyword.
     yield removeConflictingKeywords(oldBookmarkItem.url, updateInfo.keyword);
@@ -1405,17 +1405,17 @@ var getAnno = Task.async(function* (guid
     JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id
     JOIN moz_bookmarks b ON b.id = a.item_id
     WHERE b.guid = :guid AND
           n.name = :anno`,
     { guid, anno });
   return rows.length ? rows[0].getResultByName("content") : null;
 });
 
-var tagItem = Task.async(function(item, tags) {
+function tagItem(item, tags) {
   if (!item.url) {
     return [];
   }
 
   // Remove leading and trailing whitespace, then filter out empty tags.
   let newTags = tags ? tags.map(tag => tag.trim()).filter(Boolean) : [];
 
   // Removing the last tagged item will also remove the tag. To preserve
@@ -1423,17 +1423,17 @@ var tagItem = Task.async(function(item, 
   let dummyURI = PlacesUtils.toURI("about:weave#BStore_tagURI");
   let bookmarkURI = PlacesUtils.toURI(item.url.href);
   PlacesUtils.tagging.tagURI(dummyURI, newTags, SOURCE_SYNC);
   PlacesUtils.tagging.untagURI(bookmarkURI, null, SOURCE_SYNC);
   PlacesUtils.tagging.tagURI(bookmarkURI, newTags, SOURCE_SYNC);
   PlacesUtils.tagging.untagURI(dummyURI, null, SOURCE_SYNC);
 
   return newTags;
-});
+}
 
 // `PlacesUtils.bookmarks.update` checks if we've supplied enough properties,
 // but doesn't know about additional livemark properties. We check this to avoid
 // having it throw in case we only pass properties like `{ guid, feedURI }`.
 function shouldUpdateBookmark(bookmarkInfo) {
   return bookmarkInfo.hasOwnProperty("parentGuid") ||
          bookmarkInfo.hasOwnProperty("title") ||
          bookmarkInfo.hasOwnProperty("url");
--- a/toolkit/components/places/PlacesTransactions.jsm
+++ b/toolkit/components/places/PlacesTransactions.jsm
@@ -445,22 +445,22 @@ function Enqueuer() {
   this._promise = Promise.resolve();
 }
 Enqueuer.prototype = {
   /**
    * Spawn a functions once all previous functions enqueued are done running,
    * and all promises passed to alsoWaitFor are no longer pending.
    *
    * @param   aFunc
-   *          @see Task.spawn.
+   *          a function returning a promise.
    * @return  a promise that resolves once aFunc is done running. The promise
    *          "mirrors" the promise returned by aFunc.
    */
   enqueue(aFunc) {
-    let promise = this._promise.then(Task.async(aFunc));
+    let promise = this._promise.then(aFunc);
 
     // Propagate exceptions to the caller, but dismiss them internally.
     this._promise = promise.catch(console.error);
     return promise;
   },
 
   /**
    * Same as above, but for a promise returned by a function that already run.
--- a/toolkit/content/tests/chrome/test_popup_keys.xul
+++ b/toolkit/content/tests/chrome/test_popup_keys.xul
@@ -42,17 +42,17 @@ function waitForEvent(target, eventName)
       target.removeEventListener(eventName, eventOccurred, false);
       resolve();
     }, false);
   });
 }
 
 function runTests()
 {
-  Task.async(function* () {
+  Task.spawn(function* () {
     var popup = $("popup");
     popup.enableKeyboardNavigator(false);
     is(popup.getAttribute("ignorekeys"), "true", "keys disabled");
     popup.enableKeyboardNavigator(true);
     is(popup.hasAttribute("ignorekeys"), false, "keys enabled");
 
     let popupShownPromise = waitForEvent(popup, "popupshown");
     popup.openPopup(null, "after_start");
@@ -101,17 +101,17 @@ function runTests()
     synthesizeKey("t", { accelKey: true });
     is(gKeyPressCount, 2, "keypresses after accel+t pressed with ignorekeys='shortcuts'");
 
     popupHiddenPromise = waitForEvent(popup, "popuphidden");
     popup.hidePopup();
     yield popupHiddenPromise;
 
     SimpleTest.finish();
-  })();
+  });
 }
 
 function attrModified(event)
 {
   if (gIgnoreAttrChange || event.attrName != "_moz-menuactive")
     return;
 
   // the attribute should not be changed when ignorekeys is enabled
--- a/toolkit/modules/AsyncPrefs.jsm
+++ b/toolkit/modules/AsyncPrefs.jsm
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 this.EXPORTED_SYMBOLS = ["AsyncPrefs"];
 
 const {interfaces: Ci, utils: Cu, classes: Cc} = Components;
 Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/Task.jsm");
 
 const kInChildProcess = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
 
 const kAllowedPrefs = new Set([
   // NB: please leave the testing prefs at the top, and sort the rest alphabetically if you add
   // anything.
   "testing.allowed-prefs.some-bool-pref",
   "testing.allowed-prefs.some-char-pref",
@@ -60,41 +59,41 @@ function maybeReturnErrorForSet(pref, va
 }
 
 var AsyncPrefs;
 if (kInChildProcess) {
   let gUniqueId = 0;
   let gMsgMap = new Map();
 
   AsyncPrefs = {
-    set: Task.async(function(pref, value) {
+    set(pref, value) {
       let error = maybeReturnErrorForSet(pref, value);
       if (error) {
         return Promise.reject(error);
       }
 
       let msgId = ++gUniqueId;
       return new Promise((resolve, reject) => {
         gMsgMap.set(msgId, {resolve, reject});
         Services.cpmm.sendAsyncMessage("AsyncPrefs:SetPref", {pref, value, msgId});
       });
-    }),
+    },
 
-    reset: Task.async(function(pref) {
+    reset(pref) {
       let error = maybeReturnErrorForReset(pref);
       if (error) {
         return Promise.reject(error);
       }
 
       let msgId = ++gUniqueId;
       return new Promise((resolve, reject) => {
         gMsgMap.set(msgId, {resolve, reject});
         Services.cpmm.sendAsyncMessage("AsyncPrefs:ResetPref", {pref, msgId});
       });
-    }),
+    },
 
     receiveMessage(msg) {
       let promiseRef = gMsgMap.get(msg.data.msgId);
       if (promiseRef) {
         gMsgMap.delete(msg.data.msgId);
         if (msg.data.success) {
           promiseRef.resolve();
         } else {
@@ -111,45 +110,45 @@ if (kInChildProcess) {
 } else {
   AsyncPrefs = {
     methodForType: {
       number: "setIntPref",
       boolean: "setBoolPref",
       string: "setCharPref",
     },
 
-    set: Task.async(function(pref, value) {
+    set(pref, value) {
       let error = maybeReturnErrorForSet(pref, value);
       if (error) {
         return Promise.reject(error);
       }
       let methodToUse = this.methodForType[typeof value];
       try {
         Services.prefs[methodToUse](pref, value);
         return Promise.resolve(value);
       } catch (ex) {
         Cu.reportError(ex);
         return Promise.reject(ex.message);
       }
-    }),
+    },
 
-    reset: Task.async(function(pref) {
+    reset(pref) {
       let error = maybeReturnErrorForReset(pref);
       if (error) {
         return Promise.reject(error);
       }
 
       try {
         Services.prefs.clearUserPref(pref);
         return Promise.resolve();
       } catch (ex) {
         Cu.reportError(ex);
         return Promise.reject(ex.message);
       }
-    }),
+    },
 
     receiveMessage(msg) {
       if (msg.name == "AsyncPrefs:SetPref") {
         this.onPrefSet(msg);
       } else {
         this.onPrefReset(msg);
       }
     },
--- a/toolkit/modules/Sqlite.jsm
+++ b/toolkit/modules/Sqlite.jsm
@@ -332,47 +332,47 @@ ConnectionData.prototype = Object.freeze
     };
 
     // An object with the same API as `this` but with
     // additional logging. To keep logging simple, we
     // assume that `task` is not running several queries
     // concurrently.
     let loggedDb = Object.create(parent, {
       execute: {
-        value: Task.async(function*(sql, ...rest) {
+        value: async (sql, ...rest) => {
           status.isPending = true;
           status.command = sql;
           try {
-            return (yield this.execute(sql, ...rest));
+            return (await this.execute(sql, ...rest));
           } finally {
             status.isPending = false;
           }
-        }.bind(this))
+        }
       },
       close: {
-        value: Task.async(function*() {
+        value: async () => {
           status.isPending = false;
           status.command = "<close>";
           try {
-            return (yield this.close());
+            return (await this.close());
           } finally {
             status.isPending = false;
           }
-        }.bind(this))
+        }
       },
       executeCached: {
-        value: Task.async(function*(sql, ...rest) {
+        value: async (sql, ...rest) => {
           status.isPending = false;
           status.command = sql;
           try {
-            return (yield this.executeCached(sql, ...rest));
+            return (await this.executeCached(sql, ...rest));
           } finally {
             status.isPending = false;
           }
-        }.bind(this))
+        }
       },
     });
 
     let promiseResult = task(loggedDb);
     if (!promiseResult || typeof promiseResult != "object" || !("then" in promiseResult)) {
       throw new TypeError("Expected a Promise");
     }
     let key = `${this._identifier}: ${name} (${this._getOperationId()})`;