Bug 1366529 - convert uses of 'defer' to 'new Promise' in client/dom
MozReview-Commit-ID: JWxDHELnzti
--- a/devtools/client/dom/dom-panel.js
+++ b/devtools/client/dom/dom-panel.js
@@ -1,22 +1,19 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* 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 { Cu } = require("chrome");
-const defer = require("devtools/shared/defer");
const { ObjectClient } = require("devtools/shared/client/main");
-const promise = require("promise");
const EventEmitter = require("devtools/shared/event-emitter");
-const { Task } = require("devtools/shared/task");
/**
* This object represents DOM panel. It's responsibility is to
* render Document Object Model of the current debugger target.
*/
function DomPanel(iframeWindow, toolbox) {
this.panelWin = iframeWindow;
this._toolbox = toolbox;
@@ -32,37 +29,38 @@ function DomPanel(iframeWindow, toolbox)
DomPanel.prototype = {
/**
* Open is effectively an asynchronous constructor.
*
* @return object
* A promise that is resolved when the DOM panel completes opening.
*/
- open: Task.async(function* () {
+ open: function () {
if (this._opening) {
return this._opening;
}
- let deferred = promise.defer();
- this._opening = deferred.promise;
+ const _open = async () => {
+ // Local monitoring needs to make the target remote.
+ if (!this.target.isRemote) {
+ await this.target.makeRemote();
+ }
- // Local monitoring needs to make the target remote.
- if (!this.target.isRemote) {
- yield this.target.makeRemote();
- }
+ this.initialize();
- this.initialize();
+ this.isReady = true;
+ this.emit("ready");
+ return this;
+ };
- this.isReady = true;
- this.emit("ready");
- deferred.resolve(this);
+ this._opening = _open();
return this._opening;
- }),
+ },
// Initialization
initialize: function () {
this.panelWin.addEventListener("devtools/content/message",
this.onContentMessage, true);
this.target.on("navigate", this.onTabNavigated);
@@ -72,32 +70,22 @@ DomPanel.prototype = {
getPrototypeAndProperties: this.getPrototypeAndProperties.bind(this)
};
exportIntoContentScope(this.panelWin, provider, "DomProvider");
this.shouldRefresh = true;
},
- destroy: Task.async(function* () {
- if (this._destroying) {
- return this._destroying;
- }
-
- let deferred = promise.defer();
- this._destroying = deferred.promise;
-
+ destroy: function () {
this.target.off("navigate", this.onTabNavigated);
this._toolbox.off("select", this.onPanelVisibilityChange);
this.emit("destroyed");
-
- deferred.resolve();
- return this._destroying;
- }),
+ },
// Events
refresh: function () {
// Do not refresh if the panel isn't visible.
if (!this.isPanelVisible()) {
return;
}
@@ -136,63 +124,52 @@ DomPanel.prototype = {
/**
* Return true if the DOM panel is currently selected.
*/
isPanelVisible: function () {
return this._toolbox.currentToolId === "dom";
},
- getPrototypeAndProperties: function (grip) {
- let deferred = defer();
-
+ getPrototypeAndProperties: async function (grip) {
if (!grip.actor) {
console.error("No actor!", grip);
- deferred.reject(new Error("Failed to get actor from grip."));
- return deferred.promise;
+ return new Error("Failed to get actor from grip.");
}
// Bail out if target doesn't exist (toolbox maybe closed already).
if (!this.target) {
- return deferred.promise;
+ return true;
}
// If a request for the grips is already in progress
// use the same promise.
let request = this.pendingRequests.get(grip.actor);
if (request) {
return request;
}
let client = new ObjectClient(this.target.client, grip);
- client.getPrototypeAndProperties(response => {
- this.pendingRequests.delete(grip.actor, deferred.promise);
- deferred.resolve(response);
+ const result = await client.getPrototypeAndProperties();
+
+ this.pendingRequests.delete(grip.actor);
- // Fire an event about not having any pending requests.
- if (!this.pendingRequests.size) {
- this.emit("no-pending-requests");
- }
- });
+ // Fire an event about not having any pending requests.
+ if (!this.pendingRequests.size) {
+ this.emit("no-pending-requests");
+ }
- this.pendingRequests.set(grip.actor, deferred.promise);
-
- return deferred.promise;
+ return result;
},
- getRootGrip: function () {
- let deferred = defer();
-
+ getRootGrip: async function () {
// Attach Console. It might involve RDP communication, so wait
// asynchronously for the result
- this.target.activeConsole.evaluateJSAsync("window", res => {
- deferred.resolve(res.result);
- });
-
- return deferred.promise;
+ let response = await this.target.activeConsole.evaluateJSAsync("window");
+ return response.result;
},
postContentMessage: function (type, args) {
let data = {
type: type,
args: args,
};