Bug 1368204 - convert uses of 'defer' to 'new Promise' in client/responsive.html; r=tromey

MozReview-Commit-ID: HnjT6j9yjW3

--HG--
extra : rebase_source : 7c1eedaaec2b5f9ac05517a3a0e2210cdbd80002
This commit is contained in:
Matt R 2017-05-27 17:32:06 +01:00
parent dede65c36c
commit 1f9d9f8cb7
3 changed files with 25 additions and 35 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);
});
}
/**