Bug 1366532 - Replaced uses of 'defer' with 'new Promise' in the devtools/client/performance directory.
MozReview-Commit-ID: LniNQt7Jo6Z
--- a/devtools/client/performance/components/test/head.js
+++ b/devtools/client/performance/components/test/head.js
@@ -4,17 +4,16 @@
"use strict";
/* global window, document, SimpleTest, requestAnimationFrame, is, ok */
/* exported Cc, Ci, Cu, Cr, Assert, Task, TargetFactory, Toolbox, browserRequire,
forceRender, setProps, dumpn, checkOptimizationHeader, checkOptimizationTree */
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
let { Assert } = require("resource://testing-common/Assert.jsm");
const { BrowserLoader } = ChromeUtils.import("resource://devtools/client/shared/browser-loader.js", {});
-const defer = require("devtools/shared/defer");
const flags = require("devtools/shared/flags");
let { TargetFactory } = require("devtools/client/framework/target");
let { Toolbox } = require("devtools/client/framework/toolbox");
let { require: browserRequire } = BrowserLoader({
baseURI: "resource://devtools/client/performance/",
window
});
@@ -32,25 +31,25 @@ SimpleTest.waitForExplicitFinish();
function onNextAnimationFrame(fn) {
return () =>
requestAnimationFrame(() =>
requestAnimationFrame(fn));
}
function setState(component, newState) {
- const deferred = defer();
- component.setState(newState, onNextAnimationFrame(deferred.resolve));
- return deferred.promise;
+ return new Promise(resolve => {
+ component.setState(newState, onNextAnimationFrame(resolve));
+ });
}
function setProps(component, newState) {
- const deferred = defer();
- component.setProps(newState, onNextAnimationFrame(deferred.resolve));
- return deferred.promise;
+ return new Promise(resolve => {
+ component.setProps(newState, onNextAnimationFrame(resolve));
+ });
}
function dumpn(msg) {
dump(`PERFORMANCE-COMPONENT-TEST: ${msg}\n`);
}
/**
* Default opts data for testing. First site has a simple IonType,
--- a/devtools/client/performance/modules/widgets/graphs.js
+++ b/devtools/client/performance/modules/widgets/graphs.js
@@ -7,17 +7,16 @@
* This file contains the base line graph that all Performance line graphs use.
*/
const { extend } = require("devtools/shared/extend");
const LineGraphWidget = require("devtools/client/shared/widgets/LineGraphWidget");
const MountainGraphWidget = require("devtools/client/shared/widgets/MountainGraphWidget");
const { CanvasGraphUtils } = require("devtools/client/shared/widgets/Graphs");
-const defer = require("devtools/shared/defer");
const EventEmitter = require("devtools/shared/event-emitter");
const { colorUtils } = require("devtools/shared/css/color");
const { getColor } = require("devtools/client/shared/theme");
const ProfilerGlobal = require("devtools/client/performance/modules/global");
const { MarkersOverview } = require("devtools/client/performance/modules/widgets/markers-overview");
const { createTierGraphDataFromFrameNode } = require("devtools/client/performance/modules/logic/jit");
@@ -205,30 +204,32 @@ GraphsController.prototype = {
* Saves rendering progress as a promise to be consumed by `destroy`,
* to wait for cleaning up rendering during destruction.
*/
async render(recordingData, resolution) {
// Get the previous render promise so we don't start rendering
// until the previous render cycle completes, which can occur
// especially when a recording is finished, and triggers a
// fresh rendering at a higher rate
- await (this._rendering && this._rendering.promise);
+ await this._rendering;
// Check after yielding to ensure we're not tearing down,
// as this can create a race condition in tests
if (this._destroyed) {
return;
}
- this._rendering = defer();
- for (const graph of (await this._getEnabled())) {
- await graph.setPerformanceData(recordingData, resolution);
- this.emit("rendered", graph.graphName);
- }
- this._rendering.resolve();
+ this._rendering = new Promise(async (resolve) => {
+ for (const graph of (await this._getEnabled())) {
+ await graph.setPerformanceData(recordingData, resolution);
+ this.emit("rendered", graph.graphName);
+ }
+ resolve();
+ });
+ await this._rendering;
},
/**
* Destroys the underlying graphs.
*/
async destroy() {
const primary = this._getPrimaryLink();
@@ -236,17 +237,17 @@ GraphsController.prototype = {
if (primary) {
primary.off("selecting", this._onSelecting);
}
// If there was rendering, wait until the most recent render cycle
// has finished
if (this._rendering) {
- await this._rendering.promise;
+ await this._rendering;
}
for (const graph of this.getWidgets()) {
await graph.destroy();
}
},
/**
--- a/devtools/client/performance/panel.js
+++ b/devtools/client/performance/panel.js
@@ -1,17 +1,15 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 defer = require("devtools/shared/defer");
-
loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
function PerformancePanel(iframeWindow, toolbox) {
this.panelWin = iframeWindow;
this.toolbox = toolbox;
EventEmitter.decorate(this);
}
@@ -25,18 +23,16 @@ PerformancePanel.prototype = {
* @return object
* A promise that is resolved when the Performance tool
* completes opening.
*/
async open() {
if (this._opening) {
return this._opening;
}
- const deferred = defer();
- this._opening = deferred.promise;
this.panelWin.gToolbox = this.toolbox;
this.panelWin.gTarget = this.target;
this._checkRecordingStatus = this._checkRecordingStatus.bind(this);
// Actor is already created in the toolbox; reuse
// the same front, and the toolbox will also initialize the front,
// but redo it here so we can hook into the same event to prevent race conditions
@@ -59,17 +55,19 @@ PerformancePanel.prototype = {
// Fire this once incase we have an in-progress recording (console profile)
// that caused this start up, and no state change yet, so we can highlight the
// tab if we need.
this._checkRecordingStatus();
this.isReady = true;
this.emit("ready");
- deferred.resolve(this);
+ this._opening = new Promise(resolve => {
+ resolve(this);
+ });
return this._opening;
},
// DevToolPanel API
get target() {
return this.toolbox.target;
},
--- a/devtools/client/performance/performance-controller.js
+++ b/devtools/client/performance/performance-controller.js
@@ -38,17 +38,16 @@ var Waterfall = React.createFactory(requ
var JITOptimizationsView = React.createFactory(require("devtools/client/performance/components/jit-optimizations"));
var RecordingControls = React.createFactory(require("devtools/client/performance/components/recording-controls"));
var RecordingButton = React.createFactory(require("devtools/client/performance/components/recording-button"));
var RecordingList = React.createFactory(require("devtools/client/performance/components/recording-list"));
var RecordingListItem = React.createFactory(require("devtools/client/performance/components/recording-list-item"));
var Services = require("Services");
var promise = require("promise");
-const defer = require("devtools/shared/defer");
var EventEmitter = require("devtools/shared/event-emitter");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var flags = require("devtools/shared/flags");
var system = require("devtools/shared/system");
// Logic modules
/* exported L10N, PerformanceTelemetry, TIMELINE_BLUEPRINT, RecordingUtils,
PerformanceUtils, OptimizationsGraph, GraphsController,
@@ -537,24 +536,24 @@ var PerformanceController = {
* Takes a PerformanceRecording and a state, and waits for
* the event to be emitted from the front for that recording.
*
* @param {PerformanceRecordingFront} recording
* @param {string} expectedState
* @return {Promise}
*/
async waitForStateChangeOnRecording(recording, expectedState) {
- const deferred = defer();
- this.on(EVENTS.RECORDING_STATE_CHANGE, function handler(state, model) {
- if (state === expectedState && model === recording) {
- this.off(EVENTS.RECORDING_STATE_CHANGE, handler);
- deferred.resolve();
- }
+ await new Promise(resolve => {
+ this.on(EVENTS.RECORDING_STATE_CHANGE, function handler(state, model) {
+ if (state === expectedState && model === recording) {
+ this.off(EVENTS.RECORDING_STATE_CHANGE, handler);
+ resolve();
+ }
+ });
});
- await deferred.promise;
},
/**
* Called on init, sets an `e10s` attribute on the main view container with
* "disabled" if e10s is possible on the platform and just not on, or "unsupported"
* if e10s is not possible on the platform. If e10s is on, no attribute is set.
*/
_setMultiprocessAttributes: function() {
--- a/devtools/client/performance/test/browser_perf-recordings-io-03.js
+++ b/devtools/client/performance/test/browser_perf-recordings-io-03.js
@@ -33,24 +33,22 @@ var test = async function () {
function getUnicodeConverter() {
let className = "@mozilla.org/intl/scriptableunicodeconverter";
let converter = Cc[className].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
return converter;
}
function asyncCopy(data, file) {
- let deferred = defer();
-
let string = JSON.stringify(data);
let inputStream = getUnicodeConverter().convertToInputStream(string);
let outputStream = FileUtils.openSafeFileOutputStream(file);
- NetUtil.asyncCopy(inputStream, outputStream, status => {
- if (!Components.isSuccessCode(status)) {
- deferred.reject(new Error("Could not save data to file."));
- }
- deferred.resolve();
+ return new Promise((resolve, reject) => {
+ NetUtil.asyncCopy(inputStream, outputStream, status => {
+ if (!Components.isSuccessCode(status)) {
+ reject(new Error("Could not save data to file."));
+ }
+ resolve();
+ });
});
-
- return deferred.promise;
}
/* eslint-enable */
--- a/devtools/client/performance/test/browser_perf-recordings-io-04.js
+++ b/devtools/client/performance/test/browser_perf-recordings-io-04.js
@@ -155,24 +155,22 @@ var test = async function () {
function getUnicodeConverter() {
let className = "@mozilla.org/intl/scriptableunicodeconverter";
let converter = Cc[className].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
return converter;
}
function asyncCopy(data, file) {
- let deferred = defer();
-
let string = JSON.stringify(data);
let inputStream = getUnicodeConverter().convertToInputStream(string);
let outputStream = FileUtils.openSafeFileOutputStream(file);
- NetUtil.asyncCopy(inputStream, outputStream, status => {
- if (!Components.isSuccessCode(status)) {
- deferred.reject(new Error("Could not save data to file."));
- }
- deferred.resolve();
+ return new Promise((resolve, reject) => {
+ NetUtil.asyncCopy(inputStream, outputStream, status => {
+ if (!Components.isSuccessCode(status)) {
+ reject(new Error("Could not save data to file."));
+ }
+ resolve();
+ });
});
-
- return deferred.promise;
}
/* eslint-enable */
--- a/devtools/client/performance/test/browser_perf-recordings-io-06.js
+++ b/devtools/client/performance/test/browser_perf-recordings-io-06.js
@@ -119,24 +119,22 @@ var test = async function () {
function getUnicodeConverter() {
let className = "@mozilla.org/intl/scriptableunicodeconverter";
let converter = Cc[className].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
return converter;
}
function asyncCopy(data, file) {
- let deferred = defer();
-
let string = JSON.stringify(data);
let inputStream = getUnicodeConverter().convertToInputStream(string);
let outputStream = FileUtils.openSafeFileOutputStream(file);
- NetUtil.asyncCopy(inputStream, outputStream, status => {
- if (!Components.isSuccessCode(status)) {
- deferred.reject(new Error("Could not save data to file."));
- }
- deferred.resolve();
+ return new Promise((resolve, reject) => {
+ NetUtil.asyncCopy(inputStream, outputStream, status => {
+ if (!Components.isSuccessCode(status)) {
+ reject(new Error("Could not save data to file."));
+ }
+ resolve();
+ });
});
-
- return deferred.promise;
}
/* eslint-enable */
--- a/devtools/client/performance/test/browser_timeline-waterfall-workers.js
+++ b/devtools/client/performance/test/browser_timeline-waterfall-workers.js
@@ -68,30 +68,28 @@ function testWorkerMarkerUI(node) {
}
/**
* Takes a string `script` and evaluates it directly in the content
* in potentially a different process.
*/
function evalInDebuggee(script) {
let { generateUUID } = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
- let deferred = defer();
if (!mm) {
throw new Error("`loadFrameScripts()` must be called when using MessageManager.");
}
-
- let id = generateUUID().toString();
- mm.sendAsyncMessage("devtools:test:eval", { script: script, id: id });
- mm.addMessageListener("devtools:test:eval:response", handler);
+ return new Promise(resolve => {
+ let id = generateUUID().toString();
+ mm.sendAsyncMessage("devtools:test:eval", {script: script, id: id});
+ mm.addMessageListener("devtools:test:eval:response", handler);
- function handler({ data }) {
- if (id !== data.id) {
- return;
- }
+ function handler({data}) {
+ if (id !== data.id) {
+ return;
+ }
- mm.removeMessageListener("devtools:test:eval:response", handler);
- deferred.resolve(data.value);
- }
-
- return deferred.promise;
+ mm.removeMessageListener("devtools:test:eval:response", handler);
+ resolve(data.value);
+ }
+ });
}
/* eslint-enable */