Bug 1260718 - use plain promise in CustomizableUI.jsm and ScrollbarSampler.jsm; r=Gijs
authorgasolin <gasolin@gmail.com>
Wed, 06 Apr 2016 14:29:37 +0800
changeset 330433 b26c9c90617b0a2f366afee79223b64b203625b1
parent 330432 8a367c93f87d97adbc8a88e97bb723f552023e8c
child 330434 02a6023f95ceb20beb3f996608c26cf8f5f5753a
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1260718
milestone48.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 1260718 - use plain promise in CustomizableUI.jsm and ScrollbarSampler.jsm; r=Gijs MozReview-Commit-ID: 25XS1MEgpe5
browser/components/customizableui/CustomizableUI.jsm
browser/components/customizableui/ScrollbarSampler.jsm
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -14,18 +14,16 @@ Cu.import("resource://gre/modules/AppCon
 XPCOMUtils.defineLazyModuleGetter(this, "PanelWideWidgetTracker",
   "resource:///modules/PanelWideWidgetTracker.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "CustomizableWidgets",
   "resource:///modules/CustomizableWidgets.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask",
   "resource://gre/modules/DeferredTask.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
   "resource://gre/modules/PrivateBrowsingUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
-  "resource://gre/modules/Promise.jsm");
 XPCOMUtils.defineLazyGetter(this, "gWidgetsBundle", function() {
   const kUrl = "chrome://browser/locale/customizableui/customizableWidgets.properties";
   return Services.strings.createBundle(kUrl);
 });
 XPCOMUtils.defineLazyModuleGetter(this, "ShortcutUtils",
   "resource://gre/modules/ShortcutUtils.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "gELS",
   "@mozilla.org/eventlistenerservice;1", "nsIEventListenerService");
@@ -4106,38 +4104,36 @@ OverflowableToolbar.prototype = {
         this._onPanelHiding(aEvent);
         break;
       case "resize":
         this._onResize(aEvent);
     }
   },
 
   show: function() {
-    let deferred = Promise.defer();
     if (this._panel.state == "open") {
-      deferred.resolve();
-      return deferred.promise;
-    }
-    let doc = this._panel.ownerDocument;
-    this._panel.hidden = false;
-    let contextMenu = doc.getElementById(this._panel.getAttribute("context"));
-    gELS.addSystemEventListener(contextMenu, 'command', this, true);
-    let anchor = doc.getAnonymousElementByAttribute(this._chevron, "class", "toolbarbutton-icon");
-    this._panel.openPopup(anchor || this._chevron);
-    this._chevron.open = true;
-
-    let overflowableToolbarInstance = this;
-    this._panel.addEventListener("popupshown", function onPopupShown(aEvent) {
-      this.removeEventListener("popupshown", onPopupShown);
-      this.addEventListener("dragover", overflowableToolbarInstance);
-      this.addEventListener("dragend", overflowableToolbarInstance);
-      deferred.resolve();
+      return Promise.resolve();
+    }
+    return new Promise(resolve => {
+      let doc = this._panel.ownerDocument;
+      this._panel.hidden = false;
+      let contextMenu = doc.getElementById(this._panel.getAttribute("context"));
+      gELS.addSystemEventListener(contextMenu, 'command', this, true);
+      let anchor = doc.getAnonymousElementByAttribute(this._chevron, "class", "toolbarbutton-icon");
+      this._panel.openPopup(anchor || this._chevron);
+      this._chevron.open = true;
+
+      let overflowableToolbarInstance = this;
+      this._panel.addEventListener("popupshown", function onPopupShown(aEvent) {
+        this.removeEventListener("popupshown", onPopupShown);
+        this.addEventListener("dragover", overflowableToolbarInstance);
+        this.addEventListener("dragend", overflowableToolbarInstance);
+        resolve();
+      });
     });
-
-    return deferred.promise;
   },
 
   _onClickChevron: function(aEvent) {
     if (this._chevron.open) {
       this._panel.hidePopup();
       this._chevron.open = false;
     } else {
       this.show();
--- a/browser/components/customizableui/ScrollbarSampler.jsm
+++ b/browser/components/customizableui/ScrollbarSampler.jsm
@@ -5,66 +5,61 @@
 "use strict";
 
 this.EXPORTED_SYMBOLS = ["ScrollbarSampler"];
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
-                                  "resource://gre/modules/Promise.jsm");
 
 var gSystemScrollbarWidth = null;
 
 this.ScrollbarSampler = {
   getSystemScrollbarWidth: function() {
-    let deferred = Promise.defer();
-
     if (gSystemScrollbarWidth !== null) {
-      deferred.resolve(gSystemScrollbarWidth);
-      return deferred.promise;
+      return Promise.resolve(gSystemScrollbarWidth);
     }
 
-    this._sampleSystemScrollbarWidth().then(function(systemScrollbarWidth) {
-      gSystemScrollbarWidth = systemScrollbarWidth;
-      deferred.resolve(gSystemScrollbarWidth);
+    return new Promise(resolve => {
+      this._sampleSystemScrollbarWidth().then(function(systemScrollbarWidth) {
+        gSystemScrollbarWidth = systemScrollbarWidth;
+        resolve(gSystemScrollbarWidth);
+      });
     });
-    return deferred.promise;
   },
 
   resetSystemScrollbarWidth: function() {
     gSystemScrollbarWidth = null;
   },
 
   _sampleSystemScrollbarWidth: function() {
-    let deferred = Promise.defer();
     let hwin = Services.appShell.hiddenDOMWindow;
     let hdoc = hwin.document.documentElement;
     let iframe = hwin.document.createElementNS("http://www.w3.org/1999/xhtml",
                                                "html:iframe");
     iframe.setAttribute("srcdoc", '<body style="overflow-y: scroll"></body>');
     hdoc.appendChild(iframe);
 
     let cwindow = iframe.contentWindow;
     let utils = cwindow.QueryInterface(Ci.nsIInterfaceRequestor)
                        .getInterface(Ci.nsIDOMWindowUtils);
 
-    cwindow.addEventListener("load", function onLoad(aEvent) {
-      cwindow.removeEventListener("load", onLoad);
-      let sbWidth = {};
-      try {
-        utils.getScrollbarSize(true, sbWidth, {});
-      } catch(e) {
-        Cu.reportError("Could not sample scrollbar size: " + e + " -- " +
-                       e.stack);
-        sbWidth.value = 0;
-      }
-      // Minimum width of 10 so that we have enough padding:
-      sbWidth.value = Math.max(sbWidth.value, 10);
-      deferred.resolve(sbWidth.value);
-      iframe.remove();
+    return new Promise(resolve => {
+      cwindow.addEventListener("load", function onLoad(aEvent) {
+        cwindow.removeEventListener("load", onLoad);
+        let sbWidth = {};
+        try {
+          utils.getScrollbarSize(true, sbWidth, {});
+        } catch(e) {
+          Cu.reportError("Could not sample scrollbar size: " + e + " -- " +
+                         e.stack);
+          sbWidth.value = 0;
+        }
+        // Minimum width of 10 so that we have enough padding:
+        sbWidth.value = Math.max(sbWidth.value, 10);
+        resolve(sbWidth.value);
+        iframe.remove();
+      });
     });
-
-    return deferred.promise;
   }
 };
 Object.freeze(this.ScrollbarSampler);