Bug 1368202 - convert uses of "defer" to "new Promise" in client/inspector r=tromey

MozReview-Commit-ID: lXAVyomDlV

--HG--
extra : rebase_source : 351d82404ec42169e24c7fc1b8a9aa6b2af02dc5
This commit is contained in:
Nicolas Ouellet-Payeur 2017-08-03 00:28:05 -07:00
Родитель 561885f375
Коммит bb9bd5010d
23 изменённых файлов: 283 добавлений и 298 удалений

Просмотреть файл

@ -10,7 +10,6 @@ const ToolDefinitions = require("devtools/client/definitions").Tools;
const CssLogic = require("devtools/shared/inspector/css-logic");
const {ELEMENT_STYLE} = require("devtools/shared/specs/styles");
const promise = require("promise");
const defer = require("devtools/shared/defer");
const Services = require("Services");
const OutputParser = require("devtools/client/shared/output-parser");
const {PrefObserver} = require("devtools/client/shared/prefs");
@ -402,40 +401,40 @@ CssComputedView.prototype = {
return this._createViewsPromise;
}
let deferred = defer();
this._createViewsPromise = deferred.promise;
this.refreshSourceFilter();
this.numVisibleProperties = 0;
let fragment = this.styleDocument.createDocumentFragment();
this._createViewsProcess = new UpdateProcess(
this.styleWindow, CssComputedView.propertyNames, {
onItem: (propertyName) => {
// Per-item callback.
let propView = new PropertyView(this, propertyName);
fragment.appendChild(propView.buildMain());
fragment.appendChild(propView.buildSelectorContainer());
this._createViewsPromise = new Promise((resolve, reject) => {
this._createViewsProcess = new UpdateProcess(
this.styleWindow, CssComputedView.propertyNames, {
onItem: (propertyName) => {
// Per-item callback.
let propView = new PropertyView(this, propertyName);
fragment.appendChild(propView.buildMain());
fragment.appendChild(propView.buildSelectorContainer());
if (propView.visible) {
this.numVisibleProperties++;
if (propView.visible) {
this.numVisibleProperties++;
}
this.propertyViews.push(propView);
},
onCancel: () => {
reject("_createPropertyViews cancelled");
},
onDone: () => {
// Completed callback.
this.element.appendChild(fragment);
this.noResults.hidden = this.numVisibleProperties > 0;
resolve(undefined);
}
this.propertyViews.push(propView);
},
onCancel: () => {
deferred.reject("_createPropertyViews cancelled");
},
onDone: () => {
// Completed callback.
this.element.appendChild(fragment);
this.noResults.hidden = this.numVisibleProperties > 0;
deferred.resolve(undefined);
}
}
);
);
});
this._createViewsProcess.schedule();
return deferred.promise;
return this._createViewsPromise;
},
/**
@ -482,35 +481,35 @@ CssComputedView.prototype = {
// Reset zebra striping.
this._darkStripe = true;
let deferred = defer();
this._refreshProcess = new UpdateProcess(
this.styleWindow, this.propertyViews, {
onItem: (propView) => {
propView.refresh();
},
onCancel: () => {
deferred.reject("_refreshProcess of computed view cancelled");
},
onDone: () => {
this._refreshProcess = null;
this.noResults.hidden = this.numVisibleProperties > 0;
return new Promise((resolve, reject) => {
this._refreshProcess = new UpdateProcess(
this.styleWindow, this.propertyViews, {
onItem: (propView) => {
propView.refresh();
},
onCancel: () => {
reject("_refreshProcess of computed view cancelled");
},
onDone: () => {
this._refreshProcess = null;
this.noResults.hidden = this.numVisibleProperties > 0;
if (this.searchField.value.length > 0 &&
!this.numVisibleProperties) {
this.searchField.classList
.add("devtools-style-searchbox-no-match");
} else {
this.searchField.classList
.remove("devtools-style-searchbox-no-match");
if (this.searchField.value.length > 0 &&
!this.numVisibleProperties) {
this.searchField.classList
.add("devtools-style-searchbox-no-match");
} else {
this.searchField.classList
.remove("devtools-style-searchbox-no-match");
}
this.inspector.emit("computed-view-refreshed");
resolve(undefined);
}
this.inspector.emit("computed-view-refreshed");
deferred.resolve(undefined);
}
}
);
this._refreshProcess.schedule();
return deferred.promise;
);
this._refreshProcess.schedule();
});
}).catch((err) => console.error(err));
},
@ -1379,18 +1378,14 @@ SelectorView.prototype = {
let showOrig = Services.prefs.getBoolPref(PREF_ORIG_SOURCES);
if (showOrig && rule.type !== ELEMENT_STYLE) {
let deferred = defer();
// set as this first so we show something while we're fetching
this.source = CssLogic.shortSource(this.sheet) + ":" + rule.line;
rule.getOriginalLocation().then(({href, line}) => {
return rule.getOriginalLocation().then(({href, line}) => {
let oldSource = this.source;
this.source = CssLogic.shortSource({href: href}) + ":" + line;
deferred.resolve(oldSource);
return oldSource;
});
return deferred.promise;
}
let oldSource = this.source;

Просмотреть файл

@ -70,14 +70,12 @@ function* checkToggleKeyBinding(win, key, rulesTable, inspector) {
function checkHelpLinkKeybinding(view) {
info("Check that MDN link is opened on \"F1\"");
let def = defer();
let propView = getFirstVisiblePropertyView(view);
propView.mdnLinkClick = function (event) {
ok(true, "Pressing F1 opened the MDN link");
def.resolve();
};
EventUtils.synthesizeKey("VK_F1", {}, view.styleWindow);
return def.promise;
return new Promise(resolve => {
propView.mdnLinkClick = function (event) {
ok(true, "Pressing F1 opened the MDN link");
resolve();
};
EventUtils.synthesizeKey("VK_F1", {}, view.styleWindow);
});
}

Просмотреть файл

@ -10,7 +10,6 @@
var Services = require("Services");
var promise = require("promise");
var defer = require("devtools/shared/defer");
var EventEmitter = require("devtools/shared/event-emitter");
const {executeSoon} = require("devtools/shared/DevToolsUtils");
var KeyShortcuts = require("devtools/client/shared/key-shortcuts");
@ -237,8 +236,6 @@ Inspector.prototype = {
},
_deferredOpen: function (defaultSelection) {
let deferred = defer();
this.breadcrumbs = new HTMLBreadcrumbs(this);
this.walker.on("new-root", this.onNewRoot);
@ -278,26 +275,26 @@ Inspector.prototype = {
this._initMarkup();
this.isReady = false;
this.once("markuploaded", () => {
this.isReady = true;
return new Promise(resolve => {
this.once("markuploaded", () => {
this.isReady = true;
// All the components are initialized. Let's select a node.
if (defaultSelection) {
this.selection.setNodeFront(defaultSelection, "inspector-open");
this.markup.expandNode(this.selection.nodeFront);
}
// All the components are initialized. Let's select a node.
if (defaultSelection) {
this.selection.setNodeFront(defaultSelection, "inspector-open");
this.markup.expandNode(this.selection.nodeFront);
}
// And setup the toolbar only now because it may depend on the document.
this.setupToolbar();
// And setup the toolbar only now because it may depend on the document.
this.setupToolbar();
this.emit("ready");
deferred.resolve(this);
this.emit("ready");
resolve(this);
});
this.setupSearchBox();
this.setupSidebar();
});
this.setupSearchBox();
this.setupSidebar();
return deferred.promise;
},
_onBeforeNavigate: function () {

Просмотреть файл

@ -6,7 +6,6 @@
const promise = require("promise");
const Services = require("Services");
const defer = require("devtools/shared/defer");
const {Task} = require("devtools/shared/task");
const nodeConstants = require("devtools/shared/dom-node-constants");
const nodeFilterConstants = require("devtools/shared/dom-node-filter-constants");
@ -453,15 +452,17 @@ MarkupView.prototype = {
_brieflyShowBoxModel: function (nodeFront) {
this._clearBriefBoxModelTimer();
let onShown = this._showBoxModel(nodeFront);
this._briefBoxModelPromise = defer();
this._briefBoxModelTimer = setTimeout(() => {
this._hideBoxModel()
.then(this._briefBoxModelPromise.resolve,
this._briefBoxModelPromise.resolve);
}, NEW_SELECTION_HIGHLIGHTER_TIMER);
let _resolve;
this._briefBoxModelPromise = new Promise(resolve => {
_resolve = resolve;
this._briefBoxModelTimer = setTimeout(() => {
this._hideBoxModel().then(resolve, resolve);
}, NEW_SELECTION_HIGHLIGHTER_TIMER);
});
this._briefBoxModelPromise.resolve = _resolve;
return promise.all([onShown, this._briefBoxModelPromise.promise]);
return promise.all([onShown, this._briefBoxModelPromise]);
},
/**
@ -1354,15 +1355,13 @@ MarkupView.prototype = {
return promise.reject();
}
let def = defer();
container.undo.do(() => {
this.walker.setInnerHTML(node, newValue).then(def.resolve, def.reject);
}, () => {
this.walker.setInnerHTML(node, oldValue);
return new Promise((resolve, reject) => {
container.undo.do(() => {
this.walker.setInnerHTML(node, newValue).then(resolve, reject);
}, () => {
this.walker.setInnerHTML(node, oldValue);
});
});
return def.promise;
},
/**
@ -1384,20 +1383,22 @@ MarkupView.prototype = {
return promise.reject();
}
let def = defer();
let injectedNodes = [];
container.undo.do(() => {
// eslint-disable-next-line no-unsanitized/method
this.walker.insertAdjacentHTML(node, position, value).then(nodeArray => {
injectedNodes = nodeArray.nodes;
return nodeArray;
}).then(def.resolve, def.reject);
}, () => {
this.walker.removeNodes(injectedNodes);
});
return def.promise;
return new Promise((resolve, reject) => {
container.undo.do(() => {
// eslint-disable-next-line no-unsanitized/method
this.walker
.insertAdjacentHTML(node, position, value)
.then(nodeArray => {
injectedNodes = nodeArray.nodes;
return nodeArray;
})
.then(resolve, reject);
}, () => {
this.walker.removeNodes(injectedNodes);
});
});
},
/**

Просмотреть файл

@ -48,20 +48,18 @@ function* assertCopyImageDataAvailable(inspector) {
}
function triggerCopyImageUrlAndWaitForClipboard(expected, inspector) {
let def = defer();
SimpleTest.waitForClipboard(expected, () => {
inspector.markup.getContainer(inspector.selection.nodeFront)
.copyImageDataUri();
}, () => {
ok(true, "The clipboard contains the expected value " +
expected.substring(0, 50) + "...");
def.resolve();
}, () => {
ok(false, "The clipboard doesn't contain the expected value " +
expected.substring(0, 50) + "...");
def.resolve();
return new Promise(resolve => {
SimpleTest.waitForClipboard(expected, () => {
inspector.markup.getContainer(inspector.selection.nodeFront)
.copyImageDataUri();
}, () => {
ok(true, "The clipboard contains the expected value " +
expected.substring(0, 50) + "...");
resolve();
}, () => {
ok(false, "The clipboard doesn't contain the expected value " +
expected.substring(0, 50) + "...");
resolve();
});
});
return def.promise;
}

Просмотреть файл

@ -36,8 +36,6 @@ add_task(function* () {
});
function registerTestActor(toolbox) {
let deferred = defer();
let options = {
prefix: "eventsFormActor",
actorClass: "EventsFormActor",
@ -46,16 +44,16 @@ function registerTestActor(toolbox) {
// Register as a tab actor
let client = toolbox.target.client;
registerTabActor(client, options).then(({registrar, form}) => {
// Attach to the registered actor
let front = EventsFormFront(client, form);
front.attach().then(() => {
deferred.resolve({
front: front,
registrar: registrar,
return new Promise(resolve => {
registerTabActor(client, options).then(({registrar, form}) => {
// Attach to the registered actor
let front = EventsFormFront(client, form);
front.attach().then(() => {
resolve({
front: front,
registrar: registrar,
});
});
});
});
return deferred.promise;
}

Просмотреть файл

@ -73,9 +73,9 @@ function* chooseWithInspectElementContextMenu(selector, tab) {
}
function waitForLinkedBrowserEvent(tab, event) {
let def = defer();
tab.linkedBrowser.addEventListener(event, function () {
def.resolve();
}, {capture: true, once: true});
return def.promise;
return new Promise(resolve => {
tab.linkedBrowser.addEventListener(event, function () {
resolve();
}, {capture: true, once: true});
});
}

Просмотреть файл

@ -317,19 +317,20 @@ add_task(function* () {
// If a test expects more than one mutation it may come through in a single
// event or possibly in multiples.
let def = defer();
let seenMutations = 0;
inspector.on("markupmutation", function onmutation(e, mutations) {
seenMutations += mutations.length;
info("Receieved " + seenMutations +
" mutations, expecting at least " + numMutations);
if (seenMutations >= numMutations) {
inspector.off("markupmutation", onmutation);
def.resolve();
}
let promise = new Promise(resolve => {
inspector.on("markupmutation", function onmutation(e, mutations) {
seenMutations += mutations.length;
info("Receieved " + seenMutations +
" mutations, expecting at least " + numMutations);
if (seenMutations >= numMutations) {
inspector.off("markupmutation", onmutation);
resolve();
}
});
});
yield test(testActor, inspector);
yield def.promise;
yield promise;
info("Expanding all markup-view nodes to make sure new nodes are imported");
yield inspector.markup.expandAll();

Просмотреть файл

@ -126,12 +126,13 @@ function* runTestData(inspector, testActor,
"The container is marked as " + (before ? "shown" : "hidden"));
info("Listening for the display-change event");
let onDisplayChanged = defer();
inspector.markup.walker.once("display-change", onDisplayChanged.resolve);
let onDisplayChanged = new Promise(resolve => {
inspector.markup.walker.once("display-change", resolve);
});
info("Making style changes");
yield changeStyle(testActor);
let nodes = yield onDisplayChanged.promise;
let nodes = yield onDisplayChanged;
info("Verifying that the list of changed nodes include our container");

Просмотреть файл

@ -1,3 +1,4 @@
/* 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/. */
@ -126,11 +127,11 @@ function* getFirstChildNodeValue(selector, testActor) {
*/
function waitForChildrenUpdated({markup}) {
info("Waiting for queued children updates to be handled");
let def = defer();
markup._waitForChildren().then(() => {
executeSoon(def.resolve);
return new Promise(resolve => {
markup._waitForChildren().then(() => {
executeSoon(resolve);
});
});
return def.promise;
}
/**
@ -353,9 +354,9 @@ function* (nodeFront, inspector, assert = true) {
* can be used with yield.
*/
function promiseNextTick() {
let deferred = defer();
executeSoon(deferred.resolve);
return deferred.promise;
return new Promise(resolve => {
executeSoon(resolve);
});
}
/**

Просмотреть файл

@ -73,16 +73,21 @@ add_task(function* () {
* not `state`.
*/
function* setBooleanPref(pref, state) {
let oncePrefChanged = defer();
let prefObserver = new PrefObserver("devtools.");
prefObserver.on(pref, oncePrefChanged.resolve);
let oncePrefChanged = new Promise(resolve => {
prefObserver.on(pref, onPrefChanged);
function onPrefChanged() {
prefObserver.off(pref, onPrefChanged);
resolve();
}
});
info("Set the pref " + pref + " to: " + state);
Services.prefs.setBoolPref(pref, state);
info("Wait for prefObserver to call back so the UI can update");
yield oncePrefChanged.promise;
prefObserver.off(pref, oncePrefChanged.resolve);
yield oncePrefChanged;
}
/**

Просмотреть файл

@ -77,16 +77,21 @@ add_task(function* () {
* not `state`.
*/
function* setBooleanPref(pref, state) {
let oncePrefChanged = defer();
let prefObserver = new PrefObserver("devtools.");
prefObserver.on(pref, oncePrefChanged.resolve);
let oncePrefChanged = new Promise(resolve => {
prefObserver.on(pref, onPrefChanged);
function onPrefChanged() {
prefObserver.off(pref, onPrefChanged);
resolve();
}
});
info("Set the pref " + pref + " to: " + state);
Services.prefs.setBoolPref(pref, state);
info("Wait for prefObserver to call back so the UI can update");
yield oncePrefChanged.promise;
prefObserver.off(pref, oncePrefChanged.resolve);
yield oncePrefChanged;
}
/**

Просмотреть файл

@ -50,20 +50,18 @@ function* testClickingLink(toolbox, view) {
}
function checkDisplayedStylesheet(toolbox) {
let def = defer();
let panel = toolbox.getCurrentPanel();
panel.UI.on("editor-selected", (event, editor) => {
// The style editor selects the first sheet at first load before
// selecting the desired sheet.
if (editor.styleSheet.href.endsWith("scss")) {
info("Original source editor selected");
editor.getSourceEditor().then(editorSelected)
.then(def.resolve, def.reject);
}
return new Promise((resolve, reject) => {
panel.UI.on("editor-selected", (event, editor) => {
// The style editor selects the first sheet at first load before
// selecting the desired sheet.
if (editor.styleSheet.href.endsWith("scss")) {
info("Original source editor selected");
editor.getSourceEditor().then(editorSelected)
.then(resolve, reject);
}
});
});
return def.promise;
}
function editorSelected(editor) {

Просмотреть файл

@ -50,20 +50,18 @@ function* testClickingLink(toolbox, view) {
}
function checkDisplayedStylesheet(toolbox) {
let def = defer();
let panel = toolbox.getCurrentPanel();
panel.UI.on("editor-selected", (event, editor) => {
// The style editor selects the first sheet at first load before
// selecting the desired sheet.
if (editor.styleSheet.href.endsWith("scss")) {
info("Original source editor selected");
editor.getSourceEditor().then(editorSelected)
.then(def.resolve, def.reject);
}
return new Promise((resolve, reject) => {
panel.UI.on("editor-selected", (event, editor) => {
// The style editor selects the first sheet at first load before
// selecting the desired sheet.
if (editor.styleSheet.href.endsWith("scss")) {
info("Original source editor selected");
editor.getSourceEditor().then(editorSelected)
.then(resolve, reject);
}
});
});
return def.promise;
}
function editorSelected(editor) {

Просмотреть файл

@ -86,12 +86,17 @@ function* setUserAgentStylesPref(val) {
// Reset the pref and wait for PrefObserver to callback so UI
// has a chance to get updated.
let oncePrefChanged = defer();
let prefObserver = new PrefObserver("devtools.");
prefObserver.on(PREF_UA_STYLES, oncePrefChanged.resolve);
let oncePrefChanged = new Promise(resolve => {
prefObserver.on(PREF_UA_STYLES, onPrefChanged);
function onPrefChanged() {
prefObserver.off(PREF_UA_STYLES, onPrefChanged);
resolve();
}
});
Services.prefs.setBoolPref(PREF_UA_STYLES, val);
yield oncePrefChanged.promise;
prefObserver.off(PREF_UA_STYLES, oncePrefChanged.resolve);
yield oncePrefChanged;
}
function* userAgentStylesVisible(inspector, view) {

Просмотреть файл

@ -16,11 +16,6 @@
//
// Some listeners do not send a response message back.
var {utils: Cu} = Components;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var defer = require("devtools/shared/defer");
/**
* Get a value for a given property name in a css rule in a stylesheet, given
* their indexes
@ -98,16 +93,14 @@ var dumpn = msg => dump(msg + "\n");
* if the timeout is reached
*/
function waitForSuccess(validatorFn) {
let def = defer();
function wait(fn) {
if (fn()) {
def.resolve();
} else {
setTimeout(() => wait(fn), 200);
return new Promise(resolve => {
function wait(fn) {
if (fn()) {
resolve();
} else {
setTimeout(() => wait(fn), 200);
}
}
}
wait(validatorFn);
return def.promise;
wait(validatorFn);
});
}

Просмотреть файл

@ -16,10 +16,6 @@
//
// Some listeners do not send a response message back.
var {utils: Cu} = Components;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var defer = require("devtools/shared/defer");
/**
* Get a value for a given property name in a css rule in a stylesheet, given
* their indexes
@ -100,16 +96,14 @@ var dumpn = msg => dump(msg + "\n");
* if the timeout is reached
*/
function waitForSuccess(validatorFn, name = "untitled") {
let def = defer();
function wait(fn) {
if (fn()) {
def.resolve();
} else {
setTimeout(() => wait(fn), 200);
return new Promise(resolve => {
function wait(fn) {
if (fn()) {
resolve();
} else {
setTimeout(() => wait(fn), 200);
}
}
}
wait(validatorFn);
return def.promise;
wait(validatorFn);
});
}

Просмотреть файл

@ -102,19 +102,17 @@ addTab = function (url) {
* if the timeout is reached
*/
function waitForSuccess(validatorFn, name = "untitled") {
let def = defer();
function wait(validator) {
if (validator()) {
ok(true, "Validator function " + name + " returned true");
def.resolve();
} else {
setTimeout(() => wait(validator), 200);
return new Promise(resolve => {
function wait(validator) {
if (validator()) {
ok(true, "Validator function " + name + " returned true");
resolve();
} else {
setTimeout(() => wait(validator), 200);
}
}
}
wait(validatorFn);
return def.promise;
wait(validatorFn);
});
}
/**

Просмотреть файл

@ -33,9 +33,9 @@ add_task(function* () {
});
function waitForTheBrieflyShowBoxModelTimeout() {
let deferred = defer();
// Note that the current timeout is 1 sec and is neither configurable nor
// exported anywhere we can access, so hard-coding the timeout
setTimeout(deferred.resolve, 1500);
return deferred.promise;
return new Promise(resolve => {
setTimeout(resolve, 1500);
});
}

Просмотреть файл

@ -80,9 +80,9 @@ add_task(function* () {
let deleteNode = allMenuItems.find(item => item.id === "node-menu-delete");
deleteNode.click();
let deferred = defer();
executeSoon(deferred.resolve);
yield deferred.promise;
yield new Promise(resolve => {
executeSoon(resolve);
});
ok((yield testActor.eval("!!content.document.documentElement")),
"Document element still alive.");

Просмотреть файл

@ -69,11 +69,11 @@ add_task(function* () {
});
function waitForLinkedBrowserEvent(tab, event) {
let def = defer();
tab.linkedBrowser.addEventListener(event, function () {
def.resolve();
}, {capture: true, once: true});
return def.promise;
return new Promise(resolve => {
tab.linkedBrowser.addEventListener(event, function () {
resolve();
}, {capture: true, once: true});
});
}
function contentReadyState(tab) {

Просмотреть файл

@ -299,16 +299,16 @@ var clickContainer = Task.async(function* (selector, inspector) {
*/
function mouseLeaveMarkupView(inspector) {
info("Leaving the markup-view area");
let def = defer();
// Find another element to mouseover over in order to leave the markup-view
let btn = inspector.toolbox.doc.querySelector("#toolbox-controls");
EventUtils.synthesizeMouseAtCenter(btn, {type: "mousemove"},
inspector.toolbox.win);
executeSoon(def.resolve);
return def.promise;
return new Promise(resolve => {
executeSoon(resolve);
});
}
/**
@ -547,11 +547,11 @@ function* waitForMultipleChildrenUpdates(inspector) {
*/
function waitForChildrenUpdated({markup}) {
info("Waiting for queued children updates to be handled");
let def = defer();
markup._waitForChildren().then(() => {
executeSoon(def.resolve);
return new Promise(resolve => {
markup._waitForChildren().then(() => {
executeSoon(resolve);
});
});
return def.promise;
}
/**
@ -566,43 +566,42 @@ function waitForChildrenUpdated({markup}) {
* ready
*/
function waitForStyleEditor(toolbox, href) {
let def = defer();
info("Waiting for the toolbox to switch to the styleeditor");
toolbox.once("styleeditor-selected").then(() => {
let panel = toolbox.getCurrentPanel();
ok(panel && panel.UI, "Styleeditor panel switched to front");
// A helper that resolves the promise once it receives an editor that
// matches the expected href. Returns false if the editor was not correct.
let gotEditor = (event, editor) => {
let currentHref = editor.styleSheet.href;
if (!href || (href && currentHref.endsWith(href))) {
info("Stylesheet editor selected");
panel.UI.off("editor-selected", gotEditor);
return new Promise(resolve => {
toolbox.once("styleeditor-selected").then(() => {
let panel = toolbox.getCurrentPanel();
ok(panel && panel.UI, "Styleeditor panel switched to front");
editor.getSourceEditor().then(sourceEditor => {
info("Stylesheet editor fully loaded");
def.resolve(sourceEditor);
});
// A helper that resolves the promise once it receives an editor that
// matches the expected href. Returns false if the editor was not correct.
let gotEditor = (event, editor) => {
let currentHref = editor.styleSheet.href;
if (!href || (href && currentHref.endsWith(href))) {
info("Stylesheet editor selected");
panel.UI.off("editor-selected", gotEditor);
return true;
editor.getSourceEditor().then(sourceEditor => {
info("Stylesheet editor fully loaded");
resolve(sourceEditor);
});
return true;
}
info("The editor was incorrect. Waiting for editor-selected event.");
return false;
};
// The expected editor may already be selected. Check the if the currently
// selected editor is the expected one and if not wait for an
// editor-selected event.
if (!gotEditor("styleeditor-selected", panel.UI.selectedEditor)) {
// The expected editor is not selected (yet). Wait for it.
panel.UI.on("editor-selected", gotEditor);
}
info("The editor was incorrect. Waiting for editor-selected event.");
return false;
};
// The expected editor may already be selected. Check the if the currently
// selected editor is the expected one and if not wait for an
// editor-selected event.
if (!gotEditor("styleeditor-selected", panel.UI.selectedEditor)) {
// The expected editor is not selected (yet). Wait for it.
panel.UI.on("editor-selected", gotEditor);
}
});
});
return def.promise;
}
/**

Просмотреть файл

@ -241,12 +241,12 @@ function waitForContentMessage(name) {
let mm = gBrowser.selectedBrowser.messageManager;
let def = defer();
mm.addMessageListener(name, function onMessage(msg) {
mm.removeMessageListener(name, onMessage);
def.resolve(msg.data);
return new Promise(resolve => {
mm.addMessageListener(name, function onMessage(msg) {
mm.removeMessageListener(name, onMessage);
resolve(msg.data);
});
});
return def.promise;
}
/**