Bug 1436978 - Stop using Promise.jsm in devtools/server in favor of DOM Promises. r=jdescottes

MozReview-Commit-ID: Hv7uYZKZGIO

--HG--
extra : rebase_source : 95455a3c13b608d96f9a1f3c4a3071c04c7480f8
This commit is contained in:
Alexandre Poirot 2018-02-13 02:31:14 -08:00
parent af62574162
commit 793ced87e6
26 changed files with 60 additions and 80 deletions

View File

@ -26,7 +26,6 @@
*/
const {Cu, Ci} = require("chrome");
const promise = require("promise");
const protocol = require("devtools/shared/protocol");
const {Actor} = protocol;
const {animationPlayerSpec, animationsSpec} = require("devtools/shared/specs/animation");
@ -813,7 +812,7 @@ exports.AnimationsActor = protocol.ActorClassWithSpec(animationsSpec, {
readyPromises.push(player.ready);
}
this.allAnimationsPaused = true;
return promise.all(readyPromises);
return Promise.all(readyPromises);
},
/**
@ -830,7 +829,7 @@ exports.AnimationsActor = protocol.ActorClassWithSpec(animationsSpec, {
readyPromises.push(player.ready);
}
this.allAnimationsPaused = false;
return promise.all(readyPromises);
return Promise.all(readyPromises);
},
toggleAll: function () {
@ -847,7 +846,7 @@ exports.AnimationsActor = protocol.ActorClassWithSpec(animationsSpec, {
* otherwise they will be played.
*/
toggleSeveral: function (players, shouldPause) {
return promise.all(players.map(player => {
return Promise.all(players.map(player => {
return shouldPause ? player.pause() : player.play();
}));
},
@ -859,8 +858,8 @@ exports.AnimationsActor = protocol.ActorClassWithSpec(animationsSpec, {
* @param {Boolean} shouldPause Should the players be paused too.
*/
setCurrentTimes: function (players, time, shouldPause) {
return promise.all(players.map(player => {
let pause = shouldPause ? player.pause() : promise.resolve();
return Promise.all(players.map(player => {
let pause = shouldPause ? player.pause() : Promise.resolve();
return pause.then(() => player.setCurrentTime(time));
}));
},

View File

@ -6,7 +6,6 @@
"use strict";
const promise = require("promise");
const { method } = require("devtools/shared/protocol");
/**
@ -487,7 +486,7 @@ function expectState(expectedState, methodFunc, activity) {
const msg = `Wrong state while ${activity}:` +
`Expected '${expectedState}', ` +
`but current state is '${this.state}'.`;
return promise.reject(new Error(msg));
return Promise.reject(new Error(msg));
}
return methodFunc.apply(this, args);

View File

@ -6,7 +6,6 @@
const {Ci, Cu} = require("chrome");
const promise = require("promise");
const {Task} = require("devtools/shared/task");
loader.lazyRequireGetter(this, "AsyncUtils", "devtools/shared/async-utils");
@ -140,12 +139,12 @@ function nodeHasSize(node) {
function ensureImageLoaded(image, timeout) {
let { HTMLImageElement } = image.ownerGlobal;
if (!(image instanceof HTMLImageElement)) {
return promise.reject("image must be an HTMLImageELement");
return Promise.reject("image must be an HTMLImageELement");
}
if (image.complete) {
// The image has already finished loading.
return promise.resolve();
return Promise.resolve();
}
// This image is still loading.
@ -153,7 +152,7 @@ function ensureImageLoaded(image, timeout) {
// Reject if loading fails.
let onError = AsyncUtils.listenOnce(image, "error").then(() => {
return promise.reject("Image '" + image.src + "' failed to load.");
return Promise.reject("Image '" + image.src + "' failed to load.");
});
// Don't timeout when testing. This is never settled.
@ -162,12 +161,12 @@ function ensureImageLoaded(image, timeout) {
if (!flags.testing) {
// Tests are not running. Reject the promise after given timeout.
onAbort = DevToolsUtils.waitForTime(timeout).then(() => {
return promise.reject("Image '" + image.src + "' took too long to load.");
return Promise.reject("Image '" + image.src + "' took too long to load.");
});
}
// See which happens first.
return promise.race([onLoad, onError, onAbort]);
return Promise.race([onLoad, onError, onAbort]);
}
/**

View File

@ -15,7 +15,6 @@ const { ActorClassWithSpec } = require("devtools/shared/protocol");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const { assert, fetch } = DevToolsUtils;
const { joinURI } = require("devtools/shared/path");
const promise = require("promise");
const { sourceSpec } = require("devtools/shared/specs/source");
loader.lazyRequireGetter(this, "SourceMapConsumer", "source-map", true);
@ -479,7 +478,7 @@ let SourceActor = ActorClassWithSpec(sourceSpec, {
* Handler for the "source" packet.
*/
onSource: function () {
return promise.resolve(this._init)
return Promise.resolve(this._init)
.then(this._getSourceText)
.then(({ content, contentType }) => {
if (typeof content === "object" && content && content.constructor &&
@ -788,7 +787,7 @@ let SourceActor = ActorClassWithSpec(sourceSpec, {
// GCed as well, and no scripts will exist on those lines
// anymore. We will never slide through a GCed script.
if (originalLocation.originalColumn || scripts.length === 0) {
return promise.resolve(actor);
return Promise.resolve(actor);
}
// Find the script that spans the largest amount of code to
@ -814,7 +813,7 @@ let SourceActor = ActorClassWithSpec(sourceSpec, {
// which means there must be valid entry points somewhere
// within those scripts.
if (actualLine > maxLine) {
return promise.reject({
return Promise.reject({
error: "noCodeAtLineColumn",
message:
"Could not find any entry points to set a breakpoint on, " +
@ -837,7 +836,7 @@ let SourceActor = ActorClassWithSpec(sourceSpec, {
}
}
return promise.resolve(actor);
return Promise.resolve(actor);
}
return this.sources.getAllGeneratedLocations(originalLocation)
.then((generatedLocations) => {

View File

@ -9,7 +9,6 @@ const protocol = require("devtools/shared/protocol");
const {LongStringActor} = require("devtools/server/actors/string");
const {DebuggerServer} = require("devtools/server/main");
const Services = require("Services");
const promise = require("promise");
const defer = require("devtools/shared/defer");
const {isWindowIncluded} = require("devtools/shared/layout/utils");
const specs = require("devtools/shared/specs/storage");
@ -1454,7 +1453,7 @@ StorageActors.createActor({
const cache = cacheMap.get(cacheName);
if (cache) {
let keys = yield cache.keys();
yield promise.all(keys.map(key => cache.delete(key)));
yield Promise.all(keys.map(key => cache.delete(key)));
this.onItemUpdated("cleared", host, [ cacheName ]);
}
}

View File

@ -6,8 +6,6 @@
var {DebuggerServer} = require("devtools/server/main");
var promise = require("promise");
var protocol = require("devtools/shared/protocol");
const {longStringSpec} = require("devtools/shared/specs/string");
@ -36,7 +34,7 @@ exports.LongStringActor = protocol.ActorClassWithSpec(longStringSpec, {
},
substring: function (start, end) {
return promise.resolve(this.str.substring(start, end));
return Promise.resolve(this.str.substring(start, end));
},
release: function () { }

View File

@ -5,7 +5,6 @@
"use strict";
const {Ci} = require("chrome");
const promise = require("promise");
const protocol = require("devtools/shared/protocol");
const {LongStringActor} = require("devtools/server/actors/string");
const {Task} = require("devtools/shared/task");
@ -1237,11 +1236,11 @@ var StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
if (!this.canSetRuleText ||
(this.type !== CSSRule.STYLE_RULE &&
this.type !== CSSRule.KEYFRAME_RULE)) {
return promise.resolve("");
return Promise.resolve("");
}
if (typeof this.authoredText === "string") {
return promise.resolve(this.authoredText);
return Promise.resolve(this.authoredText);
}
let parentStyleSheet =

View File

@ -6,7 +6,6 @@
const {Ci} = require("chrome");
const Services = require("Services");
const promise = require("promise");
const defer = require("devtools/shared/defer");
const {Task} = require("devtools/shared/task");
const protocol = require("devtools/shared/protocol");
@ -259,11 +258,11 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
}
if (rules) {
return promise.resolve(rules);
return Promise.resolve(rules);
}
if (!this.ownerNode) {
return promise.resolve([]);
return Promise.resolve([]);
}
if (this._cssRules) {
@ -371,20 +370,20 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
*/
_getText: function () {
if (typeof this.text === "string") {
return promise.resolve(this.text);
return Promise.resolve(this.text);
}
let cssText = modifiedStyleSheets.get(this.rawSheet);
if (cssText !== undefined) {
this.text = cssText;
return promise.resolve(cssText);
return Promise.resolve(cssText);
}
if (!this.href) {
// this is an inline <style> sheet
let content = this.ownerNode.textContent;
this.text = content;
return promise.resolve(content);
return Promise.resolve(content);
}
return this.fetchStylesheet(this.href).then(({ content }) => {

View File

@ -14,12 +14,9 @@ const { ActorClassWithSpec } = require("devtools/shared/protocol");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const flags = require("devtools/shared/flags");
const { assert, dumpn } = DevToolsUtils;
const promise = require("promise");
const { DevToolsWorker } = require("devtools/shared/worker/worker");
const { threadSpec } = require("devtools/shared/specs/script");
const { resolve, reject, all } = promise;
loader.lazyGetter(this, "Debugger", () => {
let Debugger = require("Debugger");
hackDebugger(Debugger);
@ -380,7 +377,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
line: originalLocation.originalLine,
column: originalLocation.originalColumn
};
resolve(onPacket(packet))
Promise.resolve(onPacket(packet))
.catch(error => {
reportError(error);
return {
@ -565,8 +562,8 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
_handleResumeLimit: function (request) {
let steppingType = request.resumeLimit.type;
if (!["break", "step", "next", "finish"].includes(steppingType)) {
return reject({ error: "badParameterType",
message: "Unknown resumeLimit type" });
return Promise.reject({ error: "badParameterType",
message: "Unknown resumeLimit type" });
}
const generatedLocation = this.sources.getFrameLocation(this.youngestFrame);
@ -676,7 +673,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
resumeLimitHandled = this._handleResumeLimit(request);
} else {
this._clearSteppingHooks(this.youngestFrame);
resumeLimitHandled = resolve(true);
resumeLimitHandled = Promise.resolve(true);
}
return resumeLimitHandled.then(() => {
@ -947,7 +944,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
promises.push(framePromise);
}
return all(promises).then(function (frames) {
return Promise.all(promises).then(function (frames) {
// Filter null values because sourcemapping may have failed.
return { frames: frames.filter(x => !!x) };
});
@ -989,7 +986,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
}
}
return all([...sourcesToScripts.values()].map(script => {
return Promise.all([...sourcesToScripts.values()].map(script => {
return this.sources.createSourceActors(script.source);
}));
},
@ -1644,7 +1641,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
}
if (promises.length > 0) {
this.unsafeSynchronize(promise.all(promises));
this.unsafeSynchronize(Promise.all(promises));
}
} else {
// Bug 1225160: If addSource is called in response to a new script

View File

@ -8,7 +8,6 @@ const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const { assert, fetch } = DevToolsUtils;
const EventEmitter = require("devtools/shared/old-event-emitter");
const { OriginalLocation, GeneratedLocation } = require("devtools/server/actors/common");
const { resolve } = require("promise");
const { joinURI } = require("devtools/shared/path");
loader.lazyRequireGetter(this, "SourceActor", "devtools/server/actors/source", true);
@ -372,7 +371,7 @@ TabSources.prototype = {
*/
_createSourceMappedActors: function (source) {
if (!this._useSourceMaps || !source.sourceMapURL) {
return resolve(null);
return Promise.resolve(null);
}
return this.fetchSourceMap(source)
@ -415,11 +414,11 @@ TabSources.prototype = {
*/
fetchSourceMap: function (source) {
if (!this._useSourceMaps) {
return resolve(null);
return Promise.resolve(null);
} else if (this._sourceMaps.has(source)) {
return this._sourceMaps.get(source);
} else if (!source || !source.sourceMapURL) {
return resolve(null);
return Promise.resolve(null);
}
let sourceMapURL = source.sourceMapURL;
@ -446,14 +445,14 @@ TabSources.prototype = {
* have a source map or source maps are disabled.
*/
getSourceMap: function (source) {
return resolve(this._sourceMaps.get(source));
return Promise.resolve(this._sourceMaps.get(source));
},
/**
* Set a SourceMapConsumer for the source map for |source|.
*/
setSourceMap: function (source, map) {
this._sourceMaps.set(source, resolve(map));
this._sourceMaps.set(source, Promise.resolve(map));
},
/**
@ -566,7 +565,7 @@ TabSources.prototype = {
// Forcefully set the sourcemap cache. This will be used even if
// sourcemaps are disabled.
this._sourceMapCache[url] = resolve(map);
this._sourceMapCache[url] = Promise.resolve(map);
this.emit("updatedSource", this.getSourceActor(source));
},

View File

@ -8,7 +8,6 @@
var { Ci } = require("chrome");
var Services = require("Services");
var promise = require("promise");
const defer = require("devtools/shared/defer");
var { DebuggerServer } = require("devtools/server/main");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
@ -304,7 +303,7 @@ BrowserTabList.prototype.getList = function (browserActorOptions) {
this._mustNotify = true;
this._checkListening();
return promise.all(actorPromises).then(values => {
return Promise.all(actorPromises).then(values => {
// Filter out null values if we received a tabDestroyed error.
return values.filter(value => value != null);
});
@ -333,7 +332,7 @@ BrowserTabList.prototype.getTab = function ({ outerWindowID, tabId }) {
let window = Services.wm.getOuterWindowWithId(outerWindowID);
// Safety check to prevent debugging top level window via getTab
if (window && window.isChromeWindow) {
return promise.reject({
return Promise.reject({
error: "forbidden",
message: "Window with outerWindowID '" + outerWindowID + "' is chrome"
});
@ -353,7 +352,7 @@ BrowserTabList.prototype.getTab = function ({ outerWindowID, tabId }) {
return this._getActorForBrowser(browser);
}
}
return promise.reject({
return Promise.reject({
error: "noTab",
message: "Unable to find tab with outerWindowID '" + outerWindowID + "'"
});
@ -366,7 +365,7 @@ BrowserTabList.prototype.getTab = function ({ outerWindowID, tabId }) {
return this._getActorForBrowser(browser);
}
}
return promise.reject({
return Promise.reject({
error: "noTab",
message: "Unable to find tab with tabId '" + tabId + "'"
});
@ -378,7 +377,7 @@ BrowserTabList.prototype.getTab = function ({ outerWindowID, tabId }) {
let selectedBrowser = this._getSelectedBrowser(topXULWindow);
return this._getActorForBrowser(selectedBrowser);
}
return promise.reject({
return Promise.reject({
error: "noTab",
message: "Unable to find any selected browser"
});

View File

@ -7,7 +7,6 @@ const { Cu } = require("chrome");
const { Task } = require("devtools/shared/task");
loader.lazyRequireGetter(this, "Services");
loader.lazyRequireGetter(this, "promise");
loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
loader.lazyRequireGetter(this, "Memory",
@ -348,7 +347,7 @@ PerformanceRecorder.prototype = {
memoryStart = this._memory.startRecordingAllocations(recordingOptions);
}
let [profilerStartData, timelineStartData, memoryStartData] = yield promise.all([
let [profilerStartData, timelineStartData, memoryStartData] = yield Promise.all([
profilerStart, timelineStart, memoryStart
]);

View File

@ -11,7 +11,6 @@ const { Task } = require("devtools/shared/task");
const Services = require("Services");
// promise is still used in tests using this helper
const promise = require("promise"); // eslint-disable-line no-unused-vars
const defer = require("devtools/shared/defer");
const {DocumentWalker: _documentWalker} = require("devtools/server/actors/inspector/document-walker");

View File

@ -64,7 +64,7 @@ function loadSelector(selector) {
}
function loadSelectors(selectors) {
return promise.all(Array.from(selectors, (sel) => loadSelector(sel)));
return Promise.all(Array.from(selectors, (sel) => loadSelector(sel)));
}
function doMoves(moves) {

View File

@ -15,7 +15,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1222409
window.onload = function () {
const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const promise = require("promise");
const {InspectorFront} = require("devtools/shared/fronts/inspector");
SimpleTest.waitForExplicitFinish();
@ -29,7 +28,7 @@ window.onload = function () {
let url = document.getElementById("inspectorContent").href;
// eslint-disable-next-line new-cap
yield new promise(resolve => {
yield new Promise(resolve => {
attachURL(url, function (err, client, tab, doc) {
win = doc.defaultView;
inspector = InspectorFront(client, tab);
@ -49,7 +48,7 @@ window.onload = function () {
let {outerWidth, outerHeight} = win;
// eslint-disable-next-line new-cap
let onResize = new promise(resolve => {
let onResize = new Promise(resolve => {
walker.once("resize", () => {
resolve();
});

View File

@ -111,7 +111,7 @@ addTest(function testWinRace() {
let contentNode = gInspectee.querySelector("#a");
contentNode.remove();
// Now wait for that mutation and retain response to come in.
return promise.all([
return Promise.all([
gWalker.retainNode(front),
waitForMutation(gWalker, isChildList)
]);

View File

@ -14,7 +14,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=835896
window.onload = function () {
const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const promise = require("promise");
const {InspectorFront} = require("devtools/shared/fronts/inspector");
SimpleTest.waitForExplicitFinish();
@ -33,7 +32,7 @@ window.onload = function () {
let url = document.getElementById("inspectorContent").href;
// eslint-disable-next-line new-cap
yield new promise(resolve => {
yield new Promise(resolve => {
attachURL(url, function (err, client, tab, doc) {
inspector = InspectorFront(client, tab);
resolve();

View File

@ -14,7 +14,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=835896
window.onload = function () {
const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const promise = require("promise");
const {InspectorFront} = require("devtools/shared/fronts/inspector");
const {WalkerSearch, WalkerIndex} =
require("devtools/server/actors/utils/walker-search");
@ -36,7 +35,7 @@ window.onload = function () {
let url = document.getElementById("inspectorContent").href;
// eslint-disable-next-line new-cap
yield new promise(resolve => {
yield new Promise(resolve => {
attachURL(url, function (err, client, tab, doc) {
inspectee = doc;
inspector = InspectorFront(client, tab);
@ -240,7 +239,7 @@ window.onload = function () {
], "Results are updated after removal");
// eslint-disable-next-line new-cap
yield new promise(resolve => {
yield new Promise(resolve => {
info("Waiting for a mutation to happen");
let observer = new inspectee.defaultView.MutationObserver(() => {
resolve();
@ -257,7 +256,7 @@ window.onload = function () {
], "Results are updated after addition");
// eslint-disable-next-line new-cap
yield new promise(resolve => {
yield new Promise(resolve => {
info("Waiting for a mutation to happen");
let observer = new inspectee.defaultView.MutationObserver(() => {
resolve();
@ -278,7 +277,7 @@ window.onload = function () {
function mutateDocumentAndWaitForMutation(mutationFn) {
// eslint-disable-next-line new-cap
return new promise(resolve => {
return new Promise(resolve => {
info("Listening to markup mutation on the inspectee");
let observer = new inspectee.defaultView.MutationObserver(resolve);
observer.observe(inspectee, {childList: true, subtree: true});

View File

@ -337,7 +337,7 @@ addTest(function testReleaseWalker() {
promiseDone(gWalker.release().then(() => {
let promises = Array.from(checkActorIDs, (id) => checkMissing(gClient, id));
return promise.all(promises);
return Promise.all(promises);
}).then(runNextTest));
});

View File

@ -20,7 +20,6 @@ _appInfo.updateAppInfo({
const { require, loader } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const { worker } = ChromeUtils.import("resource://devtools/shared/worker/loader.js", {});
const promise = require("promise");
const defer = require("devtools/shared/defer");
const { Task } = require("devtools/shared/task");
const { console } = require("resource://gre/modules/Console.jsm");

View File

@ -24,7 +24,7 @@ function run_test() {
function (response, tabClient, threadClient) {
gThreadClient = threadClient;
promise.resolve(setup_code())
Promise.resolve(setup_code())
.then(black_box_code)
.then(run_code)
.then(test_correct_location)

View File

@ -188,7 +188,7 @@ function run_test() {
});
}));
promise.all(calls).then(() => {
Promise.all(calls).then(() => {
client.close().then(() => {
do_test_finished();
});

View File

@ -192,7 +192,7 @@ var ChildFront = protocol.FrontClassWithSpec(childSpec, {
}),
onEvent2a: preEvent("event2", function (a, b, c) {
return promise.resolve().then(() => {
return Promise.resolve().then(() => {
this.event2arg3 = c;
});
}),
@ -325,7 +325,7 @@ var RootFront = protocol.FrontClassWithSpec(rootSpec, {
clearTemporaryChildren: protocol.custom(function () {
if (!this._temporaryHolder) {
return promise.resolve(undefined);
return Promise.resolve(undefined);
}
this._temporaryHolder.destroy();
delete this._temporaryHolder;

View File

@ -118,7 +118,7 @@ var RootActor = protocol.ActorClassWithSpec(rootSpec, {
},
promiseReturn: function () {
return promise.resolve(1);
return Promise.resolve(1);
},
simpleArgs: function (a, b) {

View File

@ -22,7 +22,7 @@ function run_test() {
gClient, "test-source-map",
function (response, tabClient, threadClient) {
gThreadClient = threadClient;
promise.resolve(define_code())
Promise.resolve(define_code())
.then(run_code)
.then(test_frame_location)
.catch(error => {

View File

@ -22,7 +22,7 @@ function run_test() {
gClient, "test-source-map",
function (response, tabClient, threadClient) {
gThreadClient = threadClient;
promise.resolve(define_code())
Promise.resolve(define_code())
.then(run_code)
.then(test_frames)
.catch(error => {