Bug 1368204 - convert uses of 'defer' to 'new Promise' in client/responsive.html; r?tromey draft
authorMatt R <matthieu.rigolot@gmail.com>
Sat, 27 May 2017 17:32:06 +0100
changeset 585648 a3f3eb575a8c1c830db934e2e43a730dcf06ed5d
parent 582001 5b74bbf20e803e299790d266fc6ebf5d53b7a1b7
child 630767 8d66e0e54db7621983941ed41606a9079e274b71
push id61160
push userbmo:matthieu.rigolot@gmail.com
push dateSat, 27 May 2017 16:37:46 +0000
reviewerstromey
bugs1368204
milestone55.0a1
Bug 1368204 - convert uses of 'defer' to 'new Promise' in client/responsive.html; r?tromey MozReview-Commit-ID: HnjT6j9yjW3
devtools/client/responsive.html/browser/swap.js
devtools/client/responsive.html/utils/e10s.js
devtools/client/responsive.html/utils/message.js
--- a/devtools/client/responsive.html/browser/swap.js
+++ b/devtools/client/responsive.html/browser/swap.js
@@ -1,16 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { Ci } = require("chrome");
-const promise = require("promise");
 const { Task } = require("devtools/shared/task");
 const { tunnelToInnerBrowser } = require("./tunnel");
 
 /**
  * Swap page content from an existing tab into a new browser within a container
  * page.  Page state is preserved by using `swapFrameLoaders`, just like when
  * you move a tab to a new window.  This provides a seamless transition for the
  * user since the page is not reloaded.
@@ -324,24 +323,23 @@ function addXULBrowserDecorations(browse
   if (browser._remoteWebProgressManager == undefined) {
     browser._remoteWebProgressManager = {
       swapBrowser() {},
     };
   }
 }
 
 function tabLoaded(tab) {
-  let deferred = promise.defer();
-
-  function handle(event) {
-    if (event.originalTarget != tab.linkedBrowser.contentDocument ||
-        event.target.location.href == "about:blank") {
-      return;
+  return new Promise(resolve => {
+    function handle(event) {
+      if (event.originalTarget != tab.linkedBrowser.contentDocument ||
+          event.target.location.href == "about:blank") {
+        return;
+      }
+      tab.linkedBrowser.removeEventListener("load", handle, true);
+      resolve(event);
     }
-    tab.linkedBrowser.removeEventListener("load", handle, true);
-    deferred.resolve(event);
-  }
 
-  tab.linkedBrowser.addEventListener("load", handle, true);
-  return deferred.promise;
+    tab.linkedBrowser.addEventListener("load", handle, true);
+  });
 }
 
 exports.swapToInnerBrowser = swapToInnerBrowser;
--- a/devtools/client/responsive.html/utils/e10s.js
+++ b/devtools/client/responsive.html/utils/e10s.js
@@ -1,16 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-const { defer } = require("promise");
-
 // The prefix used for RDM messages in content.
 // see: devtools/client/responsivedesign/responsivedesign-child.js
 const MESSAGE_PREFIX = "ResponsiveMode:";
 const REQUEST_DONE_SUFFIX = ":Done";
 
 /**
  * Registers a message `listener` that is called every time messages of
  * specified `message` is emitted on the given message manager.
@@ -47,24 +45,22 @@ exports.off = off;
  * @param {nsIMessageListenerManager} mm
  *    The Message Manager
  * @param {String} message
  *    The message. It will be prefixed with the constant `MESSAGE_PREFIX`
  * @returns {Promise}
  *    A promise that is resolved when the given message is emitted.
  */
 function once(mm, message) {
-  let { resolve, promise } = defer();
-
-  on(mm, message, function onMessage({data}) {
-    off(mm, message, onMessage);
-    resolve(data);
+  return new Promise(resolve => {
+    on(mm, message, function onMessage({data}) {
+      off(mm, message, onMessage);
+      resolve(data);
+    });
   });
-
-  return promise;
 }
 exports.once = once;
 
 /**
  * Asynchronously emit a `message` to the listeners of the given message
  * manager.
  *
  * @param {nsIMessageListenerManager} mm
--- a/devtools/client/responsive.html/utils/message.js
+++ b/devtools/client/responsive.html/utils/message.js
@@ -1,31 +1,27 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-const promise = require("promise");
-
 const REQUEST_DONE_SUFFIX = ":done";
 
 function wait(win, type) {
-  let deferred = promise.defer();
-
-  let onMessage = event => {
-    if (event.data.type !== type) {
-      return;
-    }
-    win.removeEventListener("message", onMessage);
-    deferred.resolve();
-  };
-  win.addEventListener("message", onMessage);
-
-  return deferred.promise;
+  return new Promise(resolve => {
+    let onMessage = event => {
+      if (event.data.type !== type) {
+        return;
+      }
+      win.removeEventListener("message", onMessage);
+      resolve();
+    };
+    win.addEventListener("message", onMessage);
+  });
 }
 
 /**
  * Post a message to some window.
  *
  * @param win
  *        The window to post to.
  * @param typeOrMessage