Bug 1321839 - make devtools/shared eslint-clean; r=jryans

MozReview-Commit-ID: AGSdhrT4Z3D

--HG--
extra : rebase_source : b053c5a54d39e6669598714e5f572c0d3dc0ebb4
This commit is contained in:
Tom Tromey 2016-12-02 10:32:04 -07:00
parent 6d092ba5ea
commit 16809923e0
11 changed files with 223 additions and 182 deletions

View file

@ -125,14 +125,6 @@ devtools/server/tests/browser/**
!devtools/server/tests/browser/browser_webextension_inspected_window.js
devtools/server/tests/mochitest/**
devtools/server/tests/unit/**
devtools/shared/*.js
!devtools/shared/async-storage.js
!devtools/shared/async-utils.js
!devtools/shared/defer.js
!devtools/shared/event-emitter.js
!devtools/shared/indentation.js
!devtools/shared/loader-plugin-raw.jsm
!devtools/shared/task.js
devtools/shared/apps/**
devtools/shared/client/**
devtools/shared/discovery/**

View file

@ -2,11 +2,13 @@
* 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/. */
/* globals setImmediate, rpc */
"use strict";
/* General utilities used throughout devtools. */
var { Ci, Cu, Cc, components } = require("chrome");
var { Ci, Cu, components } = require("chrome");
var Services = require("Services");
var promise = require("promise");
var defer = require("devtools/shared/defer");
@ -16,6 +18,10 @@ var {getStack, callFunctionWithAsyncStack} = require("devtools/shared/platform/s
loader.lazyRequireGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm", true);
// Using this name lets the eslint plugin know about lazy defines in
// this file.
var DevToolsUtils = exports;
// Re-export the thread-safe utils.
const ThreadSafeDevToolsUtils = require("./ThreadSafeDevToolsUtils.js");
for (let key of Object.keys(ThreadSafeDevToolsUtils)) {
@ -25,9 +31,9 @@ for (let key of Object.keys(ThreadSafeDevToolsUtils)) {
/**
* Waits for the next tick in the event loop to execute a callback.
*/
exports.executeSoon = function executeSoon(aFn) {
exports.executeSoon = function (fn) {
if (isWorker) {
setImmediate(aFn);
setImmediate(fn);
} else {
let executor;
// Only enable async stack reporting when DEBUG_JS_MODULES is set
@ -35,10 +41,10 @@ exports.executeSoon = function executeSoon(aFn) {
if (AppConstants.DEBUG_JS_MODULES || flags.testing) {
let stack = getStack();
executor = () => {
callFunctionWithAsyncStack(aFn, stack, "DevToolsUtils.executeSoon");
callFunctionWithAsyncStack(fn, stack, "DevToolsUtils.executeSoon");
};
} else {
executor = aFn;
executor = fn;
}
Services.tm.mainThread.dispatch({
run: exports.makeInfallible(executor)
@ -52,7 +58,7 @@ exports.executeSoon = function executeSoon(aFn) {
* @return Promise
* A promise that is resolved after the next tick in the event loop.
*/
exports.waitForTick = function waitForTick() {
exports.waitForTick = function () {
let deferred = defer();
exports.executeSoon(deferred.resolve);
return deferred.promise;
@ -61,14 +67,14 @@ exports.waitForTick = function waitForTick() {
/**
* Waits for the specified amount of time to pass.
*
* @param number aDelay
* @param number delay
* The amount of time to wait, in milliseconds.
* @return Promise
* A promise that is resolved after the specified amount of time passes.
*/
exports.waitForTime = function waitForTime(aDelay) {
exports.waitForTime = function (delay) {
let deferred = defer();
setTimeout(deferred.resolve, aDelay);
setTimeout(deferred.resolve, delay);
return deferred.promise;
};
@ -77,21 +83,21 @@ exports.waitForTime = function waitForTime(aDelay) {
* very large arrays by yielding to the browser and continuing execution on the
* next tick.
*
* @param Array aArray
* @param Array array
* The array being iterated over.
* @param Function aFn
* @param Function fn
* The function called on each item in the array. If a promise is
* returned by this function, iterating over the array will be paused
* until the respective promise is resolved.
* @returns Promise
* A promise that is resolved once the whole array has been iterated
* over, and all promises returned by the aFn callback are resolved.
* over, and all promises returned by the fn callback are resolved.
*/
exports.yieldingEach = function yieldingEach(aArray, aFn) {
exports.yieldingEach = function (array, fn) {
const deferred = defer();
let i = 0;
let len = aArray.length;
let len = array.length;
let outstanding = [deferred.promise];
(function loop() {
@ -108,7 +114,7 @@ exports.yieldingEach = function yieldingEach(aArray, aFn) {
}
try {
outstanding.push(aFn(aArray[i], i++));
outstanding.push(fn(array[i], i++));
} catch (e) {
deferred.reject(e);
return;
@ -126,22 +132,21 @@ exports.yieldingEach = function yieldingEach(aArray, aFn) {
* allows the lazy getter to be defined on a prototype and work correctly with
* instances.
*
* @param Object aObject
* @param Object object
* The prototype object to define the lazy getter on.
* @param String aKey
* @param String key
* The key to define the lazy getter on.
* @param Function aCallback
* @param Function callback
* The callback that will be called to determine the value. Will be
* called with the |this| value of the current instance.
*/
exports.defineLazyPrototypeGetter =
function defineLazyPrototypeGetter(aObject, aKey, aCallback) {
Object.defineProperty(aObject, aKey, {
exports.defineLazyPrototypeGetter = function (object, key, callback) {
Object.defineProperty(object, key, {
configurable: true,
get: function () {
const value = aCallback.call(this);
const value = callback.call(this);
Object.defineProperty(this, aKey, {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value: value
@ -156,17 +161,17 @@ function defineLazyPrototypeGetter(aObject, aKey, aCallback) {
* Safely get the property value from a Debugger.Object for a given key. Walks
* the prototype chain until the property is found.
*
* @param Debugger.Object aObject
* @param Debugger.Object object
* The Debugger.Object to get the value from.
* @param String aKey
* @param String key
* The key to look for.
* @return Any
*/
exports.getProperty = function getProperty(aObj, aKey) {
let root = aObj;
exports.getProperty = function (object, key) {
let root = object;
try {
do {
const desc = aObj.getOwnPropertyDescriptor(aKey);
const desc = object.getOwnPropertyDescriptor(key);
if (desc) {
if ("value" in desc) {
return desc.value;
@ -174,8 +179,8 @@ exports.getProperty = function getProperty(aObj, aKey) {
// Call the getter if it's safe.
return exports.hasSafeGetter(desc) ? desc.get.call(root).return : undefined;
}
aObj = aObj.proto;
} while (aObj);
object = object.proto;
} while (object);
} catch (e) {
// If anything goes wrong report the error and return undefined.
exports.reportException("getProperty", e);
@ -186,16 +191,16 @@ exports.getProperty = function getProperty(aObj, aKey) {
/**
* Determines if a descriptor has a getter which doesn't call into JavaScript.
*
* @param Object aDesc
* @param Object desc
* The descriptor to check for a safe getter.
* @return Boolean
* Whether a safe getter was found.
*/
exports.hasSafeGetter = function hasSafeGetter(aDesc) {
exports.hasSafeGetter = function (desc) {
// Scripted functions that are CCWs will not appear scripted until after
// unwrapping.
try {
let fn = aDesc.get.unwrap();
let fn = desc.get.unwrap();
return fn && fn.callable && fn.class == "Function" && fn.script === undefined;
} catch (e) {
// Avoid exception 'Object in compartment marked as invisible to Debugger'
@ -210,32 +215,34 @@ exports.hasSafeGetter = function hasSafeGetter(aDesc) {
*
* See bugs 945920 and 946752 for discussion.
*
* @type Object aObj
* @type Object obj
* The object to check.
* @return Boolean
* True if it is safe to read properties from aObj, or false otherwise.
* True if it is safe to read properties from obj, or false otherwise.
*/
exports.isSafeJSObject = function isSafeJSObject(aObj) {
exports.isSafeJSObject = function (obj) {
// If we are running on a worker thread, Cu is not available. In this case,
// we always return false, just to be on the safe side.
if (isWorker) {
return false;
}
if (Cu.getGlobalForObject(aObj) ==
if (Cu.getGlobalForObject(obj) ==
Cu.getGlobalForObject(exports.isSafeJSObject)) {
return true; // aObj is not a cross-compartment wrapper.
// obj is not a cross-compartment wrapper.
return true;
}
let principal = Cu.getObjectPrincipal(aObj);
let principal = Cu.getObjectPrincipal(obj);
if (Services.scriptSecurityManager.isSystemPrincipal(principal)) {
return true; // allow chrome objects
// allow chrome objects
return true;
}
return Cu.isXrayWrapper(aObj);
return Cu.isXrayWrapper(obj);
};
exports.dumpn = function dumpn(str) {
exports.dumpn = function (str) {
if (flags.wantLogging) {
dump("DBG-SERVER: " + str + "\n");
}
@ -253,26 +260,27 @@ exports.dumpv = function (msg) {
/**
* Defines a getter on a specified object that will be created upon first use.
*
* @param aObject
* @param object
* The object to define the lazy getter on.
* @param aName
* The name of the getter to define on aObject.
* @param aLambda
* @param name
* The name of the getter to define on object.
* @param lambda
* A function that returns what the getter should return. This will
* only ever be called once.
*/
exports.defineLazyGetter = function defineLazyGetter(aObject, aName, aLambda) {
Object.defineProperty(aObject, aName, {
exports.defineLazyGetter = function (object, name, lambda) {
Object.defineProperty(object, name, {
get: function () {
delete aObject[aName];
return aObject[aName] = aLambda.apply(aObject);
delete object[name];
object[name] = lambda.apply(object);
return object[name];
},
configurable: true,
enumerable: true
});
};
exports.defineLazyGetter(this, "AppConstants", () => {
DevToolsUtils.defineLazyGetter(this, "AppConstants", () => {
if (isWorker) {
return {};
}
@ -329,47 +337,44 @@ Object.defineProperty(exports, "assert", {
* Defines a getter on a specified object for a module. The module will not
* be imported until first use.
*
* @param aObject
* @param object
* The object to define the lazy getter on.
* @param aName
* The name of the getter to define on aObject for the module.
* @param aResource
* @param name
* The name of the getter to define on object for the module.
* @param resource
* The URL used to obtain the module.
* @param aSymbol
* @param symbol
* The name of the symbol exported by the module.
* This parameter is optional and defaults to aName.
* This parameter is optional and defaults to name.
*/
exports.defineLazyModuleGetter = function defineLazyModuleGetter(aObject, aName,
aResource,
aSymbol)
{
this.defineLazyGetter(aObject, aName, function XPCU_moduleLambda() {
var temp = {};
Cu.import(aResource, temp);
return temp[aSymbol || aName];
exports.defineLazyModuleGetter = function (object, name, resource, symbol) {
this.defineLazyGetter(object, name, function () {
let temp = {};
Cu.import(resource, temp);
return temp[symbol || name];
});
};
exports.defineLazyGetter(this, "NetUtil", () => {
DevToolsUtils.defineLazyGetter(this, "NetUtil", () => {
return Cu.import("resource://gre/modules/NetUtil.jsm", {}).NetUtil;
});
exports.defineLazyGetter(this, "OS", () => {
DevToolsUtils.defineLazyGetter(this, "OS", () => {
return Cu.import("resource://gre/modules/osfile.jsm", {}).OS;
});
exports.defineLazyGetter(this, "TextDecoder", () => {
DevToolsUtils.defineLazyGetter(this, "TextDecoder", () => {
return Cu.import("resource://gre/modules/osfile.jsm", {}).TextDecoder;
});
exports.defineLazyGetter(this, "NetworkHelper", () => {
DevToolsUtils.defineLazyGetter(this, "NetworkHelper", () => {
return require("devtools/shared/webconsole/network-helper");
});
/**
* Performs a request to load the desired URL and returns a promise.
*
* @param aURL String
* @param urlIn String
* The URL we will request.
* @param aOptions Object
* An object with the following optional properties:
@ -396,14 +401,14 @@ exports.defineLazyGetter(this, "NetworkHelper", () => {
* without relying on caching when we can (not for eval, etc.):
* http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/
*/
function mainThreadFetch(aURL, aOptions = { loadFromCache: true,
function mainThreadFetch(urlIn, aOptions = { loadFromCache: true,
policy: Ci.nsIContentPolicy.TYPE_OTHER,
window: null,
charset: null,
principal: null,
cacheKey: null }) {
// Create a channel.
let url = aURL.split(" -> ").pop();
let url = urlIn.split(" -> ").pop();
let channel;
try {
channel = newChannelForURL(url, aOptions);
@ -526,7 +531,7 @@ function mainThreadFetch(aURL, aOptions = { loadFromCache: true,
* @return {nsIChannel} - The newly created channel. Throws on failure.
*/
function newChannelForURL(url, { policy, window, principal }) {
var securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
let securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
let uri;
try {
@ -570,15 +575,15 @@ function newChannelForURL(url, { policy, window, principal }) {
// Fetch is defined differently depending on whether we are on the main thread
// or a worker thread.
if (!this.isWorker) {
exports.fetch = mainThreadFetch;
} else {
if (this.isWorker) {
// Services is not available in worker threads, nor is there any other way
// to fetch a URL. We need to enlist the help from the main thread here, by
// issuing an rpc request, to fetch the URL on our behalf.
exports.fetch = function (url, options) {
return rpc("fetch", url, options);
};
} else {
exports.fetch = mainThreadFetch;
}
/**
@ -633,7 +638,7 @@ errorOnFlag(exports, "wantVerbose");
// Calls the property with the given `name` on the given `object`, where
// `name` is a string, and `object` a Debugger.Object instance.
///
//
// This function uses only the Debugger.Object API to call the property. It
// avoids the use of unsafeDeference. This is useful for example in workers,
// where unsafeDereference will return an opaque security wrapper to the
@ -668,5 +673,4 @@ function callPropertyOnObject(object, name) {
return result.return;
}
exports.callPropertyOnObject = callPropertyOnObject;

View file

@ -96,7 +96,7 @@ exports.reportException = function reportException(who, exception) {
* don't have a way to get at them from JavaScript at the moment.)
*/
exports.makeInfallible = function (handler, name = handler.name) {
return function (/* arguments */) {
return function () {
try {
return handler.apply(this, arguments);
} catch (ex) {
@ -128,7 +128,9 @@ exports.safeErrorString = function (error) {
errorString += "\nStack: " + stack;
}
}
} catch (ee) { }
} catch (ee) {
// Ignore.
}
// Append additional line and column number information to the output,
// since it might not be part of the stringified error.
@ -138,7 +140,9 @@ exports.safeErrorString = function (error) {
return errorString;
}
} catch (ee) { }
} catch (ee) {
// Ignore.
}
// We failed to find a good error description, so do the next best thing.
return Object.prototype.toString.call(error);
@ -294,7 +298,7 @@ exports.settleAll = values => {
if (!countdown) {
resolve(resolutionValues);
return deferred.promise;
return;
}
function checkForCompletion() {

View file

@ -20,32 +20,31 @@ const jsmScope = Cu.import("resource://gre/modules/Services.jsm", {});
const { Services } = jsmScope;
// Steal various globals only available in JSM scope (and not Sandbox one)
const { PromiseDebugging, ChromeUtils, ThreadSafeChromeUtils, HeapSnapshot,
atob, btoa, Iterator } = jsmScope;
atob, btoa } = jsmScope;
const { URL } = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
{wantGlobalProperties: ["URL"]});
/**
* Defines a getter on a specified object that will be created upon first use.
*
* @param aObject
* @param object
* The object to define the lazy getter on.
* @param aName
* The name of the getter to define on aObject.
* @param aLambda
* @param name
* The name of the getter to define on object.
* @param lambda
* A function that returns what the getter should return. This will
* only ever be called once.
*/
function defineLazyGetter(aObject, aName, aLambda)
{
Object.defineProperty(aObject, aName, {
function defineLazyGetter(object, name, lambda) {
Object.defineProperty(object, name, {
get: function () {
// Redefine this accessor property as a data property.
// Delete it first, to rule out "too much recursion" in case aObject is
// Delete it first, to rule out "too much recursion" in case object is
// a proxy whose defineProperty handler might unwittingly trigger this
// getter again.
delete aObject[aName];
let value = aLambda.apply(aObject);
Object.defineProperty(aObject, aName, {
delete object[name];
let value = lambda.apply(object);
Object.defineProperty(object, name, {
value,
writable: true,
configurable: true,
@ -62,19 +61,18 @@ function defineLazyGetter(aObject, aName, aLambda)
* Defines a getter on a specified object for a service. The service will not
* be obtained until first use.
*
* @param aObject
* @param object
* The object to define the lazy getter on.
* @param aName
* The name of the getter to define on aObject for the service.
* @param aContract
* @param name
* The name of the getter to define on object for the service.
* @param contract
* The contract used to obtain the service.
* @param aInterfaceName
* @param interfaceName
* The name of the interface to query the service to.
*/
function defineLazyServiceGetter(aObject, aName, aContract, aInterfaceName)
{
defineLazyGetter(aObject, aName, function XPCU_serviceLambda() {
return Cc[aContract].getService(Ci[aInterfaceName]);
function defineLazyServiceGetter(object, name, contract, interfaceName) {
defineLazyGetter(object, name, function () {
return Cc[contract].getService(Ci[interfaceName]);
});
}
@ -84,48 +82,47 @@ function defineLazyServiceGetter(aObject, aName, aContract, aInterfaceName)
* teardown code (e.g. to register/unregister to services) and accepts
* a proxy object which acts on behalf of the module until it is imported.
*
* @param aObject
* @param object
* The object to define the lazy getter on.
* @param aName
* The name of the getter to define on aObject for the module.
* @param aResource
* @param name
* The name of the getter to define on object for the module.
* @param resource
* The URL used to obtain the module.
* @param aSymbol
* @param symbol
* The name of the symbol exported by the module.
* This parameter is optional and defaults to aName.
* @param aPreLambda
* This parameter is optional and defaults to name.
* @param preLambda
* A function that is executed when the proxy is set up.
* This will only ever be called once.
* @param aPostLambda
* @param postLambda
* A function that is executed when the module has been imported to
* run optional teardown procedures on the proxy object.
* This will only ever be called once.
* @param aProxy
* @param proxy
* An object which acts on behalf of the module to be imported until
* the module has been imported.
*/
function defineLazyModuleGetter(aObject, aName, aResource, aSymbol,
aPreLambda, aPostLambda, aProxy)
{
let proxy = aProxy || {};
function defineLazyModuleGetter(object, name, resource, symbol,
preLambda, postLambda, proxy) {
proxy = proxy || {};
if (typeof (aPreLambda) === "function") {
aPreLambda.apply(proxy);
if (typeof (preLambda) === "function") {
preLambda.apply(proxy);
}
defineLazyGetter(aObject, aName, function XPCU_moduleLambda() {
var temp = {};
defineLazyGetter(object, name, function () {
let temp = {};
try {
Cu.import(aResource, temp);
Cu.import(resource, temp);
if (typeof (aPostLambda) === "function") {
aPostLambda.apply(proxy);
if (typeof (postLambda) === "function") {
postLambda.apply(proxy);
}
} catch (ex) {
Cu.reportError("Failed to load module " + aResource + ".");
Cu.reportError("Failed to load module " + resource + ".");
throw ex;
}
return temp[aSymbol || aName];
return temp[symbol || name];
});
}
@ -224,7 +221,8 @@ exports.globals = {
lazyImporter: defineLazyModuleGetter,
lazyServiceGetter: defineLazyServiceGetter,
lazyRequireGetter: lazyRequireGetter,
id: null // Defined by Loader.jsm
// Defined by Loader.jsm
id: null
},
// Let new XMLHttpRequest do the right thing.

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const {Cc, Ci, Cu, Cr} = require("chrome");
const {Ci} = require("chrome");
const Services = require("Services");
const events = require("sdk/event/core");

View file

@ -6,6 +6,8 @@
* THIS MODULE IS DEPRECATED. IMPORT "Promise.jsm" INSTEAD.
*/
/* eslint-disable */
"use strict";
this.Promise = {};

View file

@ -3,6 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* globals define */
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
module.exports = {

View file

@ -1,3 +1,4 @@
"use strict";
/*
* Create a writable property by tracking it with a private variable.
@ -7,8 +8,12 @@
function makeWritableFlag(exports, name) {
let flag = false;
Object.defineProperty(exports, name, {
get: function () { return flag; },
set: function (state) { flag = state; }
get: function () {
return flag;
},
set: function (state) {
flag = state;
}
});
}

View file

@ -13,9 +13,8 @@ exports.joinURI = (initialPath, ...paths) => {
try {
url = new URL(initialPath);
}
catch (e) {
return;
} catch (e) {
return null;
}
for (let path of paths) {

View file

@ -65,7 +65,9 @@ types.getType = function (type) {
// If already registered, we're done here.
let reg = registeredTypes.get(type);
if (reg) return reg;
if (reg) {
return reg;
}
// New type, see if it's a collection/lifetime type:
let sep = type.indexOf(":");
@ -146,7 +148,9 @@ types.addType = function (name, typeObject = {}, options = {}) {
}
let type = object.merge({
toString() { return "[protocol type:" + name + "]";},
toString() {
return "[protocol type:" + name + "]";
},
name: name,
primitive: !(typeObject.read || typeObject.write),
read: identityWrite,
@ -170,7 +174,9 @@ types.removeType = function (name) {
type.name = "DEFUNCT:" + name;
type.category = "defunct";
type.primitive = false;
type.read = type.write = function () { throw new Error("Using defunct type: " + name); };
type.read = type.write = function () {
throw new Error("Using defunct type: " + name);
};
registeredTypes.delete(name);
};
@ -274,7 +280,7 @@ types.addActorType = function (name) {
let actorID = typeof (v) === "string" ? v : v.actor;
let front = ctx.conn.getActor(actorID);
if (!front) {
front = new type.frontClass(ctx.conn);
front = new type.frontClass(ctx.conn); // eslint-disable-line new-cap
front.actorID = actorID;
ctx.marshallPool().manage(front);
}
@ -353,7 +359,8 @@ types.addNullableType = function (subtype) {
types.addActorDetail = function (name, actorType, detail) {
actorType = types.getType(actorType);
if (!actorType._actor) {
throw Error("Details only apply to actor types, tried to add detail '" + detail + "'' to " + actorType.name + "\n");
throw Error(`Details only apply to actor types, tried to add detail '${detail}' ` +
`to ${actorType.name}`);
}
return types.addType(name, {
_actor: true,
@ -402,7 +409,8 @@ types.removeLifetime = function (name) {
types.addLifetimeType = function (lifetime, subtype) {
subtype = types.getType(subtype);
if (!subtype._actor) {
throw Error("Lifetimes only apply to actor types, tried to apply lifetime '" + lifetime + "'' to " + subtype.name);
throw Error(`Lifetimes only apply to actor types, tried to apply ` +
`lifetime '${lifetime}' to ${subtype.name}`);
}
let prop = registeredLifetimes.get(lifetime);
return types.addType(lifetime + ":" + subtype.name, {
@ -580,7 +588,6 @@ function findPlaceholders(template, constructor, path = [], placeholders = []) {
return placeholders;
}
function describeTemplate(template) {
return JSON.parse(JSON.stringify(template, (key, value) => {
if (value.describe) {
@ -644,7 +651,9 @@ var Request = Class({
return fnArgs;
},
describe: function () { return describeTemplate(this.template); }
describe: function () {
return describeTemplate(this.template);
}
});
/**
@ -701,7 +710,9 @@ var Response = Class({
return this.retVal.read(v, ctx);
},
describe: function () { return describeTemplate(this.template); }
describe: function () {
return describeTemplate(this.template);
}
});
/**
@ -734,13 +745,17 @@ var Pool = Class({
/**
* Return the parent pool for this client.
*/
parent: function () { return this.conn.poolFor(this.actorID); },
parent: function () {
return this.conn.poolFor(this.actorID);
},
/**
* Override this if you want actors returned by this actor
* to belong to a different actor by default.
*/
marshallPool: function () { return this; },
marshallPool: function () {
return this;
},
/**
* Pool is the base class for all actors, even leaf nodes.
@ -749,7 +764,9 @@ var Pool = Class({
*/
__poolMap: null,
get _poolMap() {
if (this.__poolMap) return this.__poolMap;
if (this.__poolMap) {
return this.__poolMap;
}
this.__poolMap = new Map();
this.conn.addActorPool(this);
return this.__poolMap;
@ -883,7 +900,9 @@ var Actor = Class({
}
},
toString: function () { return "[Actor " + this.typeName + "/" + this.actorID + "]"; },
toString: function () {
return "[Actor " + this.typeName + "/" + this.actorID + "]";
},
_sendEvent: function (name, ...args) {
if (!this._actorSpec.events.has(name)) {
@ -950,8 +969,12 @@ exports.Actor = Actor;
*/
exports.method = function (fn, spec = {}) {
fn._methodSpec = Object.freeze(spec);
if (spec.request) Object.freeze(spec.request);
if (spec.response) Object.freeze(spec.response);
if (spec.request) {
Object.freeze(spec.request);
}
if (spec.response) {
Object.freeze(spec.response);
}
return fn;
};
@ -986,7 +1009,8 @@ var generateActorSpec = function (actorDesc) {
let methodSpec = desc.value._methodSpec;
let spec = {};
spec.name = methodSpec.name || name;
spec.request = Request(object.merge({type: spec.name}, methodSpec.request || undefined));
spec.request = Request(object.merge({type: spec.name},
methodSpec.request || undefined));
spec.response = Response(methodSpec.response || undefined);
spec.release = methodSpec.release;
spec.oneway = methodSpec.oneway;
@ -1002,7 +1026,8 @@ var generateActorSpec = function (actorDesc) {
let spec = {};
spec.name = methodSpec.name || name;
spec.request = Request(object.merge({type: spec.name}, methodSpec.request || undefined));
spec.request = Request(object.merge({type: spec.name},
methodSpec.request || undefined));
spec.response = Response(methodSpec.response || undefined);
spec.release = methodSpec.release;
spec.oneway = methodSpec.oneway;
@ -1056,7 +1081,7 @@ var generateRequestHandlers = function (actorSpec, actorProto) {
let ret = this[spec.name].apply(this, args);
let sendReturn = (ret) => {
let sendReturn = (retToSend) => {
if (spec.oneway) {
// No need to send a response.
return;
@ -1064,7 +1089,7 @@ var generateRequestHandlers = function (actorSpec, actorProto) {
let response;
try {
response = spec.response.write(ret, this);
response = spec.response.write(retToSend, this);
} catch (ex) {
console.error("Error writing response to: " + spec.name);
throw ex;
@ -1202,9 +1227,13 @@ var Front = Class({
* @returns a promise that will resolve to the actorID this front
* represents.
*/
actor: function () { return promise.resolve(this.actorID); },
actor: function () {
return promise.resolve(this.actorID);
},
toString: function () { return "[Front for " + this.typeName + "/" + this.actorID + "]"; },
toString: function () {
return "[Front for " + this.typeName + "/" + this.actorID + "]";
},
/**
* Update the actor from its representation.
@ -1265,7 +1294,9 @@ var Front = Class({
// Check to see if any of the preEvents returned a promise -- if so,
// wait for their resolution before emitting. Otherwise, emit synchronously.
if (results.some(result => result && typeof result.then === "function")) {
promise.all(results).then(() => events.emit.apply(null, [this, event.name].concat(args)));
promise.all(results).then(() => {
return events.emit.apply(null, [this, event.name].concat(args));
});
return;
}
}
@ -1368,7 +1399,8 @@ var generateRequestMethods = function (actorSpec, frontProto) {
if (name in frontProto) {
let custom = frontProto[spec.name]._customFront;
if (custom === undefined) {
throw Error("Existing method for " + spec.name + " not marked customFront while processing " + actorType.typeName + ".");
throw Error(`Existing method for ${spec.name} not marked customFront while ` +
` processing ${actorSpec.typeName}.`);
}
// If the user doesn't need the impl don't generate it.
if (!custom.impl) {
@ -1415,12 +1447,11 @@ var generateRequestMethods = function (actorSpec, frontProto) {
}
});
// Process event specifications
frontProto._clientSpec = {};
let events = actorSpec.events;
if (events) {
let actorEvents = actorSpec.events;
if (actorEvents) {
// This actor has events, scan the prototype for preEvent handlers...
let preHandlers = new Map();
for (let name of Object.getOwnPropertyNames(frontProto)) {
@ -1430,7 +1461,7 @@ var generateRequestMethods = function (actorSpec, frontProto) {
}
if (desc.value._preEvent) {
let preEvent = desc.value._preEvent;
if (!events.has(preEvent)) {
if (!actorEvents.has(preEvent)) {
throw Error("preEvent for event that doesn't exist: " + preEvent);
}
let handlers = preHandlers.get(preEvent);
@ -1444,7 +1475,7 @@ var generateRequestMethods = function (actorSpec, frontProto) {
frontProto._clientSpec.events = new Map();
for (let [name, request] of events) {
for (let [name, request] of actorEvents) {
frontProto._clientSpec.events.set(request.type, {
name: name,
request: request,
@ -1518,7 +1549,6 @@ exports.dumpActorSpec = function (type) {
}
}
JSON.stringify(ret);
return ret;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { Cc, Ci, Cu } = require("chrome");
const { Cc, Ci } = require("chrome");
const { Task } = require("devtools/shared/task");
loader.lazyRequireGetter(this, "Services");
@ -64,10 +64,10 @@ function* getSystemInfo() {
hardware = yield exports.getSetting("deviceinfo.hardware");
version = yield exports.getSetting("deviceinfo.os");
} catch (e) {
// Ignore.
}
}
// Not B2G
else {
} else {
// Not B2G
os = appInfo.OS;
version = appInfo.version;
}
@ -80,7 +80,8 @@ function* getSystemInfo() {
}
if (win) {
let utils = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
let utils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
dpi = utils.displayDPI;
useragent = win.navigator.userAgent;
width = win.screen.width;
@ -131,7 +132,8 @@ function* getSystemInfo() {
geckoversion: geckoVersion,
// Locale used in this build
locale: Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry).getSelectedLocale("global"),
locale: Cc["@mozilla.org/chrome/chrome-registry;1"]
.getService(Ci.nsIXULChromeRegistry).getSelectedLocale("global"),
/**
* Information regarding the operating system.
@ -186,12 +188,13 @@ function getProfileLocation() {
// In child processes, we cannot access the profile location.
try {
let profd = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
let profservice = Cc["@mozilla.org/toolkit/profile-service;1"].getService(Ci.nsIToolkitProfileService);
var profiles = profservice.profiles;
let profservice = Cc["@mozilla.org/toolkit/profile-service;1"]
.getService(Ci.nsIToolkitProfileService);
let profiles = profservice.profiles;
while (profiles.hasMoreElements()) {
let profile = profiles.getNext().QueryInterface(Ci.nsIToolkitProfile);
if (profile.rootDir.path == profd.path) {
return profile = profile.name;
return profile.name;
}
}
@ -214,7 +217,8 @@ function getAppIniString(section, key) {
return undefined;
}
let iniParser = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].getService(Ci.nsIINIParserFactory).createINIParser(inifile);
let iniParser = Cc["@mozilla.org/xpcom/ini-parser-factory;1"]
.getService(Ci.nsIINIParserFactory).createINIParser(inifile);
try {
return iniParser.getString(section, key);
} catch (e) {
@ -316,13 +320,14 @@ function getSetting(name) {
// settingsService fails in b2g child processes
// TODO bug 1205797, make this work in child processes.
try {
settingsService = Cc["@mozilla.org/settingsService;1"].getService(Ci.nsISettingsService);
settingsService = Cc["@mozilla.org/settingsService;1"]
.getService(Ci.nsISettingsService);
} catch (e) {
return promise.reject(e);
}
let req = settingsService.createLock().get(name, {
handle: (name, value) => deferred.resolve(value),
settingsService.createLock().get(name, {
handle: (_, value) => deferred.resolve(value),
handleError: (error) => deferred.reject(error),
});
} else {