Bug 1275078 - Fix ESLint issues in toolbox and target files. r=ochameau

MozReview-Commit-ID: 8SoQ2JnTib3

--HG--
extra : rebase_source : 2e987c465c21150265b1d1f1a3a218e71db9bcae
This commit is contained in:
J. Ryan Stinnett 2017-02-22 12:33:20 -06:00
parent c396116b69
commit 9896e105b8
9 changed files with 102 additions and 93 deletions

View file

@ -82,7 +82,8 @@ devtools/client/commandline/**
devtools/client/debugger/**
devtools/client/framework/**
!devtools/client/framework/selection.js
!devtools/client/framework/toolbox.js
!devtools/client/framework/target*
!devtools/client/framework/toolbox*
devtools/client/netmonitor/test/**
devtools/client/netmonitor/har/test/**
devtools/client/projecteditor/**

View file

@ -30,14 +30,14 @@ var processes = new Set();
/**
* Constructor for creating a process that will hold a chrome toolbox.
*
* @param function aOnClose [optional]
* @param function onClose [optional]
* A function called when the process stops running.
* @param function aOnRun [optional]
* @param function onRun [optional]
* A function called when the process starts running.
* @param object aOptions [optional]
* @param object options [optional]
* An object with properties for configuring BrowserToolboxProcess.
*/
this.BrowserToolboxProcess = function BrowserToolboxProcess(aOnClose, aOnRun, aOptions) {
this.BrowserToolboxProcess = function BrowserToolboxProcess(onClose, onRun, options) {
let emitter = new EventEmitter();
this.on = emitter.on.bind(emitter);
this.off = emitter.off.bind(emitter);
@ -50,22 +50,22 @@ this.BrowserToolboxProcess = function BrowserToolboxProcess(aOnClose, aOnRun, aO
// If first argument is an object, use those properties instead of
// all three arguments
if (typeof aOnClose === "object") {
if (aOnClose.onClose) {
this.once("close", aOnClose.onClose);
if (typeof onClose === "object") {
if (onClose.onClose) {
this.once("close", onClose.onClose);
}
if (aOnClose.onRun) {
this.once("run", aOnClose.onRun);
if (onClose.onRun) {
this.once("run", onClose.onRun);
}
this._options = aOnClose;
this._options = onClose;
} else {
if (aOnClose) {
this.once("close", aOnClose);
if (onClose) {
this.once("close", onClose);
}
if (aOnRun) {
this.once("run", aOnRun);
if (onRun) {
this.once("run", onRun);
}
this._options = aOptions || {};
this._options = options || {};
}
this._telemetry = new Telemetry();
@ -85,24 +85,24 @@ EventEmitter.decorate(BrowserToolboxProcess);
* Initializes and starts a chrome toolbox process.
* @return object
*/
BrowserToolboxProcess.init = function (aOnClose, aOnRun, aOptions) {
return new BrowserToolboxProcess(aOnClose, aOnRun, aOptions);
BrowserToolboxProcess.init = function (onClose, onRun, options) {
return new BrowserToolboxProcess(onClose, onRun, options);
};
/**
* Passes a set of options to the BrowserAddonActors for the given ID.
*
* @param aId string
* @param id string
* The ID of the add-on to pass the options to
* @param aOptions object
* @param options object
* The options.
* @return a promise that will be resolved when complete.
*/
BrowserToolboxProcess.setAddonOptions = function DSC_setAddonOptions(aId, aOptions) {
BrowserToolboxProcess.setAddonOptions = function (id, options) {
let promises = [];
for (let process of processes.values()) {
promises.push(process.debuggerServer.setAddonOptions(aId, aOptions));
promises.push(process.debuggerServer.setAddonOptions(id, options));
}
return promise.all(promises);
@ -190,7 +190,8 @@ BrowserToolboxProcess.prototype = {
// always works:
Services.prefs.savePrefFile(prefsFile);
dumpn("Finished creating the chrome toolbox user profile at: " + this._dbgProfilePath);
dumpn("Finished creating the chrome toolbox user profile at: " +
this._dbgProfilePath);
},
/**
@ -198,7 +199,8 @@ BrowserToolboxProcess.prototype = {
*/
_create: function () {
dumpn("Initializing chrome debugging process.");
let process = this._dbgProcess = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
this._dbgProcess = process;
process.init(Services.dirsvc.get("XREExeF", Ci.nsIFile));
let xulURI = DBG_XUL;
@ -208,7 +210,12 @@ BrowserToolboxProcess.prototype = {
}
dumpn("Running chrome debugging process.");
let args = ["-no-remote", "-foreground", "-profile", this._dbgProfilePath, "-chrome", xulURI];
let args = [
"-no-remote",
"-foreground",
"-profile", this._dbgProfilePath,
"-chrome", xulURI
];
// During local development, incremental builds can trigger the main process
// to clear its startup cache with the "flag file" .purgecaches, but this
@ -223,7 +230,8 @@ BrowserToolboxProcess.prototype = {
// Disable safe mode for the new process in case this was opened via the
// keyboard shortcut.
let nsIEnvironment = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment);
let nsIEnvironment = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
let originalValue = nsIEnvironment.get("MOZ_DISABLE_SAFE_MODE_KEY");
nsIEnvironment.set("MOZ_DISABLE_SAFE_MODE_KEY", "1");
@ -288,7 +296,9 @@ function dumpn(str) {
var wantLogging = Services.prefs.getBoolPref("devtools.debugger.log");
Services.prefs.addObserver("devtools.debugger.log", {
observe: (...args) => wantLogging = Services.prefs.getBoolPref(args.pop())
observe: (...args) => {
wantLogging = Services.prefs.getBoolPref(args.pop());
}
}, false);
Services.obs.notifyObservers(null, "ToolboxProcessLoaded", null);

View file

@ -62,16 +62,16 @@ exports.targetFromURL = Task.async(function* (url) {
let form, isTabActor;
if (type === "tab") {
// Fetch target for a remote tab
id = parseInt(id);
id = parseInt(id, 10);
if (isNaN(id)) {
throw new Error("targetFromURL, wrong tab id:'" + id + "', should be a number");
throw new Error(`targetFromURL, wrong tab id '${id}', should be a number`);
}
try {
let response = yield client.getTab({ outerWindowID: id });
form = response.tab;
} catch (ex) {
if (ex.error == "noTab") {
throw new Error("targetFromURL, tab with outerWindowID:'" + id + "' doesn't exist");
throw new Error(`targetFromURL, tab with outerWindowID '${id}' doesn't exist`);
}
throw ex;
}
@ -79,7 +79,7 @@ exports.targetFromURL = Task.async(function* (url) {
// Fetch target for a remote chrome actor
DebuggerServer.allowChromeProcess = true;
try {
id = parseInt(id);
id = parseInt(id, 10);
if (isNaN(id)) {
id = 0;
}
@ -92,7 +92,7 @@ exports.targetFromURL = Task.async(function* (url) {
}
} catch (ex) {
if (ex.error == "noProcess") {
throw new Error("targetFromURL, process with id:'" + id + "' doesn't exist");
throw new Error(`targetFromURL, process with id '${id}' doesn't exist`);
}
throw ex;
}
@ -111,13 +111,12 @@ exports.targetFromURL = Task.async(function* (url) {
chrome = true;
} catch (ex) {
if (ex.error == "notFound") {
throw new Error(`targetFromURL, window with id:'${id}' ` +
"doesn't exist");
throw new Error(`targetFromURL, window with id '${id}' doesn't exist`);
}
throw ex;
}
} else {
throw new Error("targetFromURL, unsupported type='" + type + "' parameter");
throw new Error(`targetFromURL, unsupported type '${type}' parameter`);
}
return TargetFactory.forRemoteTab({ client, form, chrome, isTabActor });
@ -137,7 +136,7 @@ function* createClient(params) {
DebuggerServer.init();
DebuggerServer.addBrowserActors();
}
transport = DebuggerServer.connectPipe()
transport = DebuggerServer.connectPipe();
}
return new DebuggerClient(transport);
}

View file

@ -5,7 +5,6 @@
"use strict";
const { Ci } = require("chrome");
const promise = require("promise");
const defer = require("devtools/shared/defer");
const EventEmitter = require("devtools/shared/event-emitter");
const Services = require("Services");
@ -486,30 +485,30 @@ TabTarget.prototype = {
_setupRemoteListeners: function () {
this.client.addListener("closed", this.destroy);
this._onTabDetached = (aType, aPacket) => {
this._onTabDetached = (type, packet) => {
// We have to filter message to ensure that this detach is for this tab
if (aPacket.from == this._form.actor) {
if (packet.from == this._form.actor) {
this.destroy();
}
};
this.client.addListener("tabDetached", this._onTabDetached);
this._onTabNavigated = (aType, aPacket) => {
this._onTabNavigated = (type, packet) => {
let event = Object.create(null);
event.url = aPacket.url;
event.title = aPacket.title;
event.nativeConsoleAPI = aPacket.nativeConsoleAPI;
event.isFrameSwitching = aPacket.isFrameSwitching;
event.url = packet.url;
event.title = packet.title;
event.nativeConsoleAPI = packet.nativeConsoleAPI;
event.isFrameSwitching = packet.isFrameSwitching;
if (!aPacket.isFrameSwitching) {
if (!packet.isFrameSwitching) {
// Update the title and url unless this is a frame switch.
this._url = aPacket.url;
this._title = aPacket.title;
this._url = packet.url;
this._title = packet.title;
}
// Send any stored event payload (DOMWindow or nsIRequest) for backwards
// compatibility with non-remotable tools.
if (aPacket.state == "start") {
if (packet.state == "start") {
event._navPayload = this._navRequest;
this.emit("will-navigate", event);
this._navRequest = null;
@ -521,8 +520,8 @@ TabTarget.prototype = {
};
this.client.addListener("tabNavigated", this._onTabNavigated);
this._onFrameUpdate = (aType, aPacket) => {
this.emit("frame-update", aPacket);
this._onFrameUpdate = (type, packet) => {
this.emit("frame-update", packet);
};
this.client.addListener("frameUpdate", this._onFrameUpdate);
@ -565,9 +564,11 @@ TabTarget.prototype = {
}
},
// Automatically respawn the toolbox when the tab changes between being
// loaded within the parent process and loaded from a content process.
// Process change can go in both ways.
/**
* Automatically respawn the toolbox when the tab changes between being
* loaded within the parent process and loaded from a content process.
* Process change can go in both ways.
*/
onRemotenessChange: function () {
// Responsive design do a crazy dance around tabs and triggers
// remotenesschange events. But we should ignore them as at the end
@ -687,11 +688,11 @@ TabTarget.prototype = {
/**
* WebProgressListener for TabTarget.
*
* @param object aTarget
* @param object target
* The TabTarget instance to work with.
*/
function TabWebProgressListener(aTarget) {
this.target = aTarget;
function TabWebProgressListener(target) {
this.target = target;
}
TabWebProgressListener.prototype = {

View file

@ -33,7 +33,7 @@ add_task(function* () {
yield targetFromURL(new URL("http://foo?type=x"));
ok(false, "Shouldn't pass");
} catch (e) {
is(e.message, "targetFromURL, unsupported type='x' parameter");
is(e.message, "targetFromURL, unsupported type 'x' parameter");
}
info("Test browser window");
@ -61,7 +61,7 @@ add_task(function* () {
yield targetFromURL(new URL("http://foo?type=tab&id=10000"));
ok(false, "Shouldn't pass");
} catch (e) {
is(e.message, "targetFromURL, tab with outerWindowID:'10000' doesn't exist");
is(e.message, "targetFromURL, tab with outerWindowID '10000' doesn't exist");
}
info("Test parent process");

View file

@ -1,5 +1,3 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
@ -33,7 +31,6 @@ const flags = require("devtools/shared/flags");
exports.getHighlighterUtils = function (toolbox) {
if (!toolbox || !toolbox.target) {
throw new Error("Missing or invalid toolbox passed to getHighlighterUtils");
return;
}
// Exported API properties will go here
@ -97,12 +94,11 @@ exports.getHighlighterUtils = function (toolbox) {
* activated.
* @return A promise that resolves when done
*/
let togglePicker = exported.togglePicker = function (doFocus) {
exported.togglePicker = function (doFocus) {
if (isPicking) {
return cancelPicker();
} else {
return startPicker(doFocus);
}
return startPicker(doFocus);
};
/**
@ -250,8 +246,7 @@ exports.getHighlighterUtils = function (toolbox) {
* highlightNodeFront, so it has the same signature.
* @see highlightNodeFront
*/
let highlightDomValueGrip = exported.highlightDomValueGrip = requireInspector(
function* (valueGrip, options = {}) {
exported.highlightDomValueGrip = requireInspector(function* (valueGrip, options = {}) {
let nodeFront = yield gripToNodeFront(valueGrip);
if (nodeFront) {
yield highlightNodeFront(nodeFront, options);
@ -279,13 +274,13 @@ exports.getHighlighterUtils = function (toolbox) {
* markup view, which is when this param is passed to true
* @return a promise that resolves when the highlighter is hidden
*/
let unhighlight = exported.unhighlight = Task.async(
function* (forceHide = false) {
exported.unhighlight = Task.async(function* (forceHide = false) {
forceHide = forceHide || !flags.testing;
// Note that if isRemoteHighlightable is true, there's no need to hide the
// highlighter as the walker uses setTimeout to hide it after some time
if (isNodeFrontHighlighted && forceHide && toolbox.highlighter && isRemoteHighlightable()) {
if (isNodeFrontHighlighted && forceHide && toolbox.highlighter &&
isRemoteHighlightable()) {
isNodeFrontHighlighted = false;
yield toolbox.highlighter.hideBoxModel();
}
@ -306,8 +301,7 @@ exports.getHighlighterUtils = function (toolbox) {
* methods and needs to be released by the consumer when not needed anymore.
* @return a promise that resolves to the highlighter
*/
let getHighlighterByType = exported.getHighlighterByType = requireInspector(
function* (typeName) {
exported.getHighlighterByType = requireInspector(function* (typeName) {
let highlighter = null;
if (supportsCustomHighlighters()) {
@ -316,7 +310,6 @@ exports.getHighlighterUtils = function (toolbox) {
return highlighter || promise.reject("The target doesn't support " +
`creating highlighters by types or ${typeName} is unknown`);
});
// Return the public API

View file

@ -1,5 +1,10 @@
/* 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 Services = require("Services");
const {Ci} = require("chrome");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
@ -67,10 +72,13 @@ ToolboxHostManager.prototype = {
// We have to listen on capture as no event fires on bubble
this.host.frame.addEventListener("unload", this, true);
let toolbox = new Toolbox(this.target, toolId, this.host.type, this.host.frame.contentWindow, this.frameId);
let toolbox = new Toolbox(this.target, toolId, this.host.type,
this.host.frame.contentWindow, this.frameId);
// Prevent reloading the toolbox when loading the tools in a tab (e.g. from about:debugging)
if (!this.host.frame.contentWindow.location.href.startsWith("about:devtools-toolbox")) {
// Prevent reloading the toolbox when loading the tools in a tab
// (e.g. from about:debugging)
let location = this.host.frame.contentWindow.location;
if (!location.href.startsWith("about:devtools-toolbox")) {
this.host.frame.setAttribute("src", "about:devtools-toolbox");
}
@ -78,7 +86,7 @@ ToolboxHostManager.prototype = {
}),
handleEvent(event) {
switch(event.type) {
switch (event.type) {
case "message":
this.onMessage(event);
break;

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-env browser */
/* global XPCNativeWrapper */
"use strict";

View file

@ -1,5 +1,3 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
@ -69,8 +67,7 @@ function OptionsPanel(iframeWindow, toolbox) {
this._themeUnregistered = this._themeUnregistered.bind(this);
this._disableJSClicked = this._disableJSClicked.bind(this);
this.disableJSNode = this.panelDoc.getElementById(
"devtools-disable-javascript");
this.disableJSNode = this.panelDoc.getElementById("devtools-disable-javascript");
this._addListeners();
@ -116,9 +113,8 @@ OptionsPanel.prototype = {
_prefChanged: function (subject, topic, prefName) {
if (prefName === "devtools.cache.disabled") {
let cacheDisabled = data.newValue;
let cacheDisabled = GetPref(prefName);
let cbx = this.panelDoc.getElementById("devtools-disable-cache");
cbx.checked = cacheDisabled;
} else if (prefName === "devtools.theme") {
this.updateCurrentTheme();
@ -359,7 +355,7 @@ OptionsPanel.prototype = {
}
},
populatePreferences: function () {
populatePreferences: Task.async(function* () {
let prefCheckboxes = this.panelDoc.querySelectorAll(
"input[type=checkbox][data-pref]");
for (let prefCheckbox of prefCheckboxes) {
@ -399,6 +395,7 @@ OptionsPanel.prototype = {
prefSelect.selectedIndex = options.indexOf(option);
return true;
}
return false;
});
prefSelect.addEventListener("change", function (e) {
@ -409,16 +406,15 @@ OptionsPanel.prototype = {
}
if (this.target.activeTab) {
return this.target.client.attachTab(this.target.activeTab._actor)
.then(([response, client]) => {
this._origJavascriptEnabled = !response.javascriptEnabled;
this.disableJSNode.checked = this._origJavascriptEnabled;
this.disableJSNode.addEventListener("click",
this._disableJSClicked);
});
let [ response ] = yield this.target.client.attachTab(this.target.activeTab._actor);
this._origJavascriptEnabled = !response.javascriptEnabled;
this.disableJSNode.checked = this._origJavascriptEnabled;
this.disableJSNode.addEventListener("click", this._disableJSClicked);
} else {
// Hide the checkbox and label
this.disableJSNode.parentNode.style.display = "none";
}
this.disableJSNode.hidden = true;
},
}),
updateCurrentTheme: function () {
let currentTheme = GetPref("devtools.theme");