Bug 1387122 - Remove all useless Promise = require("promise"). r=tromey
Promise with a capital 'P' is already available in all DevTools sandboxes.
Still a couple of letfovers:
* Modules still using `Promise.defer()` (will be handled in
bug 1387123)
* devtools/shared/defer, which introduces changes in Promise unhandled exception and stacks (
bug 1388054)
MozReview-Commit-ID: PBaliHFa7u
--- a/devtools/client/webaudioeditor/panel.js
+++ b/devtools/client/webaudioeditor/panel.js
@@ -3,17 +3,16 @@
/* 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 { Cc, Ci, Cu, Cr } = require("chrome");
const EventEmitter = require("devtools/shared/event-emitter");
const { WebAudioFront } = require("devtools/shared/fronts/webaudio");
-var Promise = require("promise");
function WebAudioEditorPanel(iframeWindow, toolbox) {
this.panelWin = iframeWindow;
this._toolbox = toolbox;
this._destroyer = null;
EventEmitter.decorate(this);
}
--- a/devtools/server/main.js
+++ b/devtools/server/main.js
@@ -13,17 +13,16 @@ var Services = require("Services");
var { ActorPool, OriginalLocation, RegisteredActorFactory,
ObservedActorFactory } = require("devtools/server/actors/common");
var { LocalDebuggerTransport, ChildDebuggerTransport, WorkerDebuggerTransport } =
require("devtools/shared/transport/transport");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { dumpn, dumpv } = DevToolsUtils;
var flags = require("devtools/shared/flags");
var EventEmitter = require("devtools/shared/event-emitter");
-var Promise = require("promise");
var SyncPromise = require("devtools/shared/deprecated-sync-thenables");
DevToolsUtils.defineLazyGetter(this, "DebuggerSocket", () => {
let { DebuggerSocket } = require("devtools/shared/security/socket");
return DebuggerSocket;
});
DevToolsUtils.defineLazyGetter(this, "Authentication", () => {
return require("devtools/shared/security/auth");
@@ -960,52 +959,51 @@ var DebuggerServer = {
* @param waitForEval (optional)
* If true, the returned promise only resolves once code in child
* is evaluated
*/
setupInChild({ module, setupChild, args, waitForEval }) {
if (this._childMessageManagers.size == 0) {
return Promise.resolve();
}
- let deferred = Promise.defer();
-
- // If waitForEval is set, pass a unique id and expect child.js to send
- // a message back once the code in child is evaluated.
- if (typeof (waitForEval) != "boolean") {
- waitForEval = false;
- }
- let count = this._childMessageManagers.size;
- let id = waitForEval ? generateUUID().toString() : null;
+ return new Promise(done => {
+ // If waitForEval is set, pass a unique id and expect child.js to send
+ // a message back once the code in child is evaluated.
+ if (typeof (waitForEval) != "boolean") {
+ waitForEval = false;
+ }
+ let count = this._childMessageManagers.size;
+ let id = waitForEval ? generateUUID().toString() : null;
- this._childMessageManagers.forEach(mm => {
- if (waitForEval) {
- // Listen for the end of each child execution
- let evalListener = msg => {
- if (msg.data.id !== id) {
- return;
- }
- mm.removeMessageListener("debug:setup-in-child-response", evalListener);
- if (--count === 0) {
- deferred.resolve();
- }
- };
- mm.addMessageListener("debug:setup-in-child-response", evalListener);
+ this._childMessageManagers.forEach(mm => {
+ if (waitForEval) {
+ // Listen for the end of each child execution
+ let evalListener = msg => {
+ if (msg.data.id !== id) {
+ return;
+ }
+ mm.removeMessageListener("debug:setup-in-child-response", evalListener);
+ if (--count === 0) {
+ done();
+ }
+ };
+ mm.addMessageListener("debug:setup-in-child-response", evalListener);
+ }
+ mm.sendAsyncMessage("debug:setup-in-child", {
+ module: module,
+ setupChild: setupChild,
+ args: args,
+ id: id,
+ });
+ });
+
+ if (!waitForEval) {
+ done();
}
- mm.sendAsyncMessage("debug:setup-in-child", {
- module: module,
- setupChild: setupChild,
- args: args,
- id: id,
- });
});
-
- if (waitForEval) {
- return deferred.promise;
- }
- return Promise.resolve();
},
/**
* Live list of all currenctly attached child's message managers.
*/
_childMessageManagers: new Set(),
/**
--- a/devtools/server/websocket-server.js
+++ b/devtools/server/websocket-server.js
@@ -1,16 +1,15 @@
/* 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 { Cc, CC } = require("chrome");
-const Promise = require("promise");
const { Task } = require("devtools/shared/task");
const { executeSoon } = require("devtools/shared/DevToolsUtils");
const { delimitedRead } = require("devtools/shared/transport/stream-utils");
const CryptoHash = CC("@mozilla.org/security/hash;1", "nsICryptoHash", "initWithString");
const threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
// Limit the header size to put an upper bound on allocated memory
const HEADER_MAX_LEN = 8000;
--- a/devtools/shared/async-storage.js
+++ b/devtools/shared/async-storage.js
@@ -37,18 +37,16 @@
* retrieve them together, in a single asynchronous operation, just group the
* values into a single object. The properties of this object may not include
* DOM elements, but they may include things like Blobs and typed arrays.
*
*/
"use strict";
-const Promise = require("promise");
-
const DBNAME = "devtools-async-storage";
const DBVERSION = 1;
const STORENAME = "keyvaluepairs";
var db = null;
function withStore(type, onsuccess, onerror) {
if (db) {
let transaction = db.transaction(STORENAME, type);
--- a/devtools/shared/async-utils.js
+++ b/devtools/shared/async-utils.js
@@ -9,17 +9,16 @@
* run by Tasks. An async function returns a Promise for the resolution of the
* function. When the function returns, the promise is resolved with the
* returned value. If it throws the promise rejects with the thrown error.
*
* See Task documentation at https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Task.jsm.
*/
var {Task} = require("devtools/shared/task");
-var Promise = require("promise");
/**
* Create an async function that only executes once per instance of an object.
* Once called on a given object, the same promise will be returned for any
* future calls for that object.
*
* @param Function func
* The generator function that to wrap as an async function.
--- a/devtools/shared/task.js
+++ b/devtools/shared/task.js
@@ -82,17 +82,16 @@
* spawn a task from it, regardless of whether it is an asynchronous generator
* or a synchronous function. This comes in handy when iterating over
* function lists where some items have been converted to tasks and some not.
*/
////////////////////////////////////////////////////////////////////////////////
//// Globals
-const Promise = require("promise");
const defer = require("devtools/shared/defer");
// The following error types are considered programmer errors, which should be
// reported (possibly redundantly) so as to let programmers fix their code.
const ERRORS_TO_REPORT = ["EvalError", "RangeError", "ReferenceError",
"TypeError"];
/**