Bug 1283583 - Clean up code style in devtools/server/child.js. r=ochameau

MozReview-Commit-ID: GoHv6jvX6M1
This commit is contained in:
J. Ryan Stinnett 2016-06-28 17:57:24 -05:00
parent e2e3133f6f
commit 89a70c452d
2 changed files with 27 additions and 32 deletions

View file

@ -109,6 +109,7 @@ devtools/client/webconsole/**
devtools/client/webide/** devtools/client/webide/**
!devtools/client/webide/components/webideCli.js !devtools/client/webide/components/webideCli.js
devtools/server/** devtools/server/**
!devtools/server/child.js
!devtools/server/css-logic.js !devtools/server/css-logic.js
!devtools/server/actors/webbrowser.js !devtools/server/actors/webbrowser.js
!devtools/server/actors/styles.js !devtools/server/actors/styles.js

View file

@ -4,12 +4,12 @@
"use strict"; "use strict";
try { /* global addMessageListener, removeMessageListener, sendAsyncMessage */
try {
var chromeGlobal = this; var chromeGlobal = this;
// Encapsulate in its own scope to allows loading this frame script // Encapsulate in its own scope to allows loading this frame script more than once.
// more than once.
(function () { (function () {
let Cu = Components.utils; let Cu = Components.utils;
let { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); let { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
@ -17,17 +17,16 @@ try {
const { dumpn } = DevToolsUtils; const { dumpn } = DevToolsUtils;
const { DebuggerServer, ActorPool } = require("devtools/server/main"); const { DebuggerServer, ActorPool } = require("devtools/server/main");
// Note that this frame script may be evaluated in non-e10s build // Note that this frame script may be evaluated in non-e10s build. In such case,
// In such case, DebuggerServer is already going to be initialized. // DebuggerServer is already going to be initialized.
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.isInChildProcess = true; DebuggerServer.isInChildProcess = true;
} }
// In case of apps being loaded in parent process, DebuggerServer is already // In case of apps being loaded in parent process, DebuggerServer is already
// initialized, but child specific actors are not registered. // initialized, but child specific actors are not registered. Otherwise, for apps in
// Otherwise, for apps in child process, we need to load actors the first // child process, we need to load actors the first time we load child.js.
// time we load child.js
DebuggerServer.addChildActors(); DebuggerServer.addChildActors();
let connections = new Map(); let connections = new Map();
@ -52,35 +51,32 @@ try {
addMessageListener("debug:connect", onConnect); addMessageListener("debug:connect", onConnect);
// Allows executing module setup helper from the parent process. // Allows executing module setup helper from the parent process.
// See also: DebuggerServer.setupInChild() // See also: DebuggerServer.setupInChild()
let onSetupInChild = DevToolsUtils.makeInfallible(msg => { let onSetupInChild = DevToolsUtils.makeInfallible(msg => {
let { module, setupChild, args } = msg.data; let { module, setupChild, args } = msg.data;
let m, fn; let m;
try { try {
m = require(module); m = require(module);
if (!setupChild in m) { if (!setupChild in m) {
dumpn("ERROR: module '" + module + "' does not export '" + dumpn(`ERROR: module '${module}' does not export 'setupChild'`);
setupChild + "'");
return false; return false;
} }
m[setupChild].apply(m, args); m[setupChild].apply(m, args);
} catch (e) { } catch (e) {
let error_msg = "exception during actor module setup running in the child process: "; let errorMessage =
DevToolsUtils.reportException(error_msg + e); "Exception during actor module setup running in the child process: ";
dumpn("ERROR: " + error_msg + " \n\t module: '" + module + DevToolsUtils.reportException(errorMessage + e);
"' \n\t setupChild: '" + setupChild + "'\n" + dumpn(`ERROR: ${errorMessage}\n\t module: '${module}'\n\t ` +
DevToolsUtils.safeErrorString(e)); `setupChild: '${setupChild}'\n${DevToolsUtils.safeErrorString(e)}`);
return false; return false;
} }
if (msg.data.id) { if (msg.data.id) {
// Send a message back to know when it is processed // Send a message back to know when it is processed
sendAsyncMessage("debug:setup-in-child-response", sendAsyncMessage("debug:setup-in-child-response", {id: msg.data.id});
{id: msg.data.id});
} }
return true; return true;
}); });
@ -90,9 +86,9 @@ try {
let onDisconnect = DevToolsUtils.makeInfallible(function (msg) { let onDisconnect = DevToolsUtils.makeInfallible(function (msg) {
removeMessageListener("debug:disconnect", onDisconnect); removeMessageListener("debug:disconnect", onDisconnect);
// Call DebuggerServerConnection.close to destroy all child actors // Call DebuggerServerConnection.close to destroy all child actors. It should end up
// (It should end up calling DebuggerServerConnection.onClosed // calling DebuggerServerConnection.onClosed that would actually cleanup all actor
// that would actually cleanup all actor pools) // pools.
let prefix = msg.data.prefix; let prefix = msg.data.prefix;
let conn = connections.get(prefix); let conn = connections.get(prefix);
if (conn) { if (conn) {
@ -103,16 +99,14 @@ try {
addMessageListener("debug:disconnect", onDisconnect); addMessageListener("debug:disconnect", onDisconnect);
let onInspect = DevToolsUtils.makeInfallible(function (msg) { let onInspect = DevToolsUtils.makeInfallible(function (msg) {
// Store the node to be inspected in a global variable // Store the node to be inspected in a global variable (gInspectingNode). Later
// (gInspectingNode). Later we'll fetch this variable again using // we'll fetch this variable again using the findInspectingNode request over the
// the findInspectingNode request over the remote debugging // remote debugging protocol.
// protocol.
let inspector = require("devtools/server/actors/inspector"); let inspector = require("devtools/server/actors/inspector");
inspector.setInspectingNode(msg.objects.node); inspector.setInspectingNode(msg.objects.node);
}); });
addMessageListener("debug:inspect", onInspect); addMessageListener("debug:inspect", onInspect);
})(); })();
} catch (e) { } catch (e) {
dump("Exception in app child process: " + e + "\n"); dump(`Exception in app child process: ${e}\n`);
} }