From 1f9d9f8cb76c25391b26796236931da29ae597db Mon Sep 17 00:00:00 2001 From: Matt R Date: Sat, 27 May 2017 17:32:06 +0100 Subject: [PATCH] Bug 1368204 - convert uses of 'defer' to 'new Promise' in client/responsive.html; r=tromey MozReview-Commit-ID: HnjT6j9yjW3 --HG-- extra : rebase_source : 7c1eedaaec2b5f9ac05517a3a0e2210cdbd80002 --- .../client/responsive.html/browser/swap.js | 22 ++++++++--------- devtools/client/responsive.html/utils/e10s.js | 14 ++++------- .../client/responsive.html/utils/message.js | 24 ++++++++----------- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/devtools/client/responsive.html/browser/swap.js b/devtools/client/responsive.html/browser/swap.js index 03f41972c0a9..3664c66d25da 100644 --- a/devtools/client/responsive.html/browser/swap.js +++ b/devtools/client/responsive.html/browser/swap.js @@ -5,7 +5,6 @@ "use strict"; const { Ci } = require("chrome"); -const promise = require("promise"); const { Task } = require("devtools/shared/task"); const { tunnelToInnerBrowser } = require("./tunnel"); @@ -329,19 +328,18 @@ function addXULBrowserDecorations(browser) { } 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; diff --git a/devtools/client/responsive.html/utils/e10s.js b/devtools/client/responsive.html/utils/e10s.js index f45add6b039f..ace3466eb447 100644 --- a/devtools/client/responsive.html/utils/e10s.js +++ b/devtools/client/responsive.html/utils/e10s.js @@ -4,8 +4,6 @@ "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:"; @@ -52,14 +50,12 @@ exports.off = off; * 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; diff --git a/devtools/client/responsive.html/utils/message.js b/devtools/client/responsive.html/utils/message.js index 3c730a86baaa..a4cf49dc1a19 100644 --- a/devtools/client/responsive.html/utils/message.js +++ b/devtools/client/responsive.html/utils/message.js @@ -4,23 +4,19 @@ "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); + }); } /**