Bug 1368204 - convert uses of 'defer' to 'new Promise' in client/responsive.html; r=tromey
authorMatt R <matthieu.rigolot@gmail.com>
Sat, 27 May 2017 17:32:06 +0100
changeset 361364 c1351451c0d652a8e215adcb2f3ee0e43b8bcd10
parent 361363 821fcba2308102ad8ab603ad1dd5f906559c82d9
child 361377 9c16db40f56dd542f8756df2dcdf664580adf2f6
push id43741
push userttromey@mozilla.com
push dateTue, 30 May 2017 20:06:40 +0000
treeherderautoland@c1351451c0d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1368204
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 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