mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 21:00:50 +00:00

In prevision of Promise.jsm removal, use defer helper module instead of Promise.jsm as that's the only one feature that DOM Promise don't support. PART3: Manual fixes - Go manually fix: http://searchfox.org/mozilla-central/source/devtools/client/dom/dom-panel.js which has duplicated import of defer symbol (it already used to import it) - execute eslint, see all the places where we import of 'promise' is no longer use it (there may be leftovers not covered by eslint that will be covered in bug 1387128) devtools/server/tests/mochitest/inspector-helpers.js needs to keep importing promise as it is a shared test script. - fix devtools/client/performance/panel.js and devtools/client/webconsole/console-output.js which use loader.lazyRequireGetter(this, "promise") and miss the defer import - fix devtools/server/worker.js to use 'worker.require(devtools/shared/defer")' MozReview-Commit-ID: HIOB5Et87Wc --HG-- extra : rebase_source : fe3bff8599807224fd51898e753589d4c7c1777f
121 lines
3.5 KiB
JavaScript
121 lines
3.5 KiB
JavaScript
/* 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";
|
|
|
|
/* eslint-env mozilla/chrome-worker */
|
|
/* global worker, loadSubScript, global */
|
|
|
|
// This function is used to do remote procedure calls from the worker to the
|
|
// main thread. It is exposed as a built-in global to every module by the
|
|
// worker loader. To make sure the worker loader can access it, it needs to be
|
|
// defined before loading the worker loader script below.
|
|
this.rpc = function (method, ...params) {
|
|
let id = nextId++;
|
|
|
|
postMessage(JSON.stringify({
|
|
type: "rpc",
|
|
method: method,
|
|
params: params,
|
|
id: id
|
|
}));
|
|
|
|
let deferred = defer();
|
|
rpcDeferreds[id] = deferred;
|
|
return deferred.promise;
|
|
};
|
|
|
|
loadSubScript("resource://devtools/shared/worker/loader.js");
|
|
|
|
var defer = worker.require("devtools/shared/defer");
|
|
var { ActorPool } = worker.require("devtools/server/actors/common");
|
|
var { ThreadActor } = worker.require("devtools/server/actors/script");
|
|
var { WebConsoleActor } = worker.require("devtools/server/actors/webconsole");
|
|
var { TabSources } = worker.require("devtools/server/actors/utils/TabSources");
|
|
var makeDebugger = worker.require("devtools/server/actors/utils/make-debugger");
|
|
var { DebuggerServer } = worker.require("devtools/server/main");
|
|
|
|
DebuggerServer.init();
|
|
DebuggerServer.createRootActor = function () {
|
|
throw new Error("Should never get here!");
|
|
};
|
|
|
|
var connections = Object.create(null);
|
|
var nextId = 0;
|
|
var rpcDeferreds = [];
|
|
|
|
this.addEventListener("message", function (event) {
|
|
let packet = JSON.parse(event.data);
|
|
switch (packet.type) {
|
|
case "connect":
|
|
// Step 3: Create a connection to the parent.
|
|
let connection = DebuggerServer.connectToParent(packet.id, this);
|
|
connections[packet.id] = {
|
|
connection,
|
|
rpcs: []
|
|
};
|
|
|
|
// Step 4: Create a thread actor for the connection to the parent.
|
|
let pool = new ActorPool(connection);
|
|
connection.addActorPool(pool);
|
|
|
|
let sources = null;
|
|
|
|
let parent = {
|
|
actorID: packet.id,
|
|
|
|
makeDebugger: makeDebugger.bind(null, {
|
|
findDebuggees: () => {
|
|
return [this.global];
|
|
},
|
|
|
|
shouldAddNewGlobalAsDebuggee: () => {
|
|
return true;
|
|
},
|
|
}),
|
|
|
|
get sources() {
|
|
if (sources === null) {
|
|
sources = new TabSources(threadActor);
|
|
}
|
|
return sources;
|
|
},
|
|
|
|
window: global
|
|
};
|
|
|
|
let threadActor = new ThreadActor(parent, global);
|
|
pool.addActor(threadActor);
|
|
|
|
// parentActor.threadActor is needed from the webconsole for grip previewing
|
|
parent.threadActor = threadActor;
|
|
|
|
let consoleActor = new WebConsoleActor(connection, parent);
|
|
pool.addActor(consoleActor);
|
|
|
|
// Step 5: Send a response packet to the parent to notify
|
|
// it that a connection has been established.
|
|
postMessage(JSON.stringify({
|
|
type: "connected",
|
|
id: packet.id,
|
|
threadActor: threadActor.actorID,
|
|
consoleActor: consoleActor.actorID,
|
|
}));
|
|
break;
|
|
|
|
case "disconnect":
|
|
connections[packet.id].connection.close();
|
|
break;
|
|
|
|
case "rpc":
|
|
let deferred = rpcDeferreds[packet.id];
|
|
delete rpcDeferreds[packet.id];
|
|
if (packet.error) {
|
|
deferred.reject(packet.error);
|
|
}
|
|
deferred.resolve(packet.result);
|
|
break;
|
|
}
|
|
});
|