forked from mirrors/gecko-dev
Bug 1321839 - make devtools/shared eslint-clean; r=jryans
MozReview-Commit-ID: AGSdhrT4Z3D --HG-- extra : rebase_source : b053c5a54d39e6669598714e5f572c0d3dc0ebb4
This commit is contained in:
parent
6d092ba5ea
commit
16809923e0
11 changed files with 223 additions and 182 deletions
|
|
@ -125,14 +125,6 @@ devtools/server/tests/browser/**
|
||||||
!devtools/server/tests/browser/browser_webextension_inspected_window.js
|
!devtools/server/tests/browser/browser_webextension_inspected_window.js
|
||||||
devtools/server/tests/mochitest/**
|
devtools/server/tests/mochitest/**
|
||||||
devtools/server/tests/unit/**
|
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/apps/**
|
||||||
devtools/shared/client/**
|
devtools/shared/client/**
|
||||||
devtools/shared/discovery/**
|
devtools/shared/discovery/**
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
/* globals setImmediate, rpc */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/* General utilities used throughout devtools. */
|
/* General utilities used throughout devtools. */
|
||||||
|
|
||||||
var { Ci, Cu, Cc, components } = require("chrome");
|
var { Ci, Cu, components } = require("chrome");
|
||||||
var Services = require("Services");
|
var Services = require("Services");
|
||||||
var promise = require("promise");
|
var promise = require("promise");
|
||||||
var defer = require("devtools/shared/defer");
|
var defer = require("devtools/shared/defer");
|
||||||
|
|
@ -16,6 +18,10 @@ var {getStack, callFunctionWithAsyncStack} = require("devtools/shared/platform/s
|
||||||
loader.lazyRequireGetter(this, "FileUtils",
|
loader.lazyRequireGetter(this, "FileUtils",
|
||||||
"resource://gre/modules/FileUtils.jsm", true);
|
"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.
|
// Re-export the thread-safe utils.
|
||||||
const ThreadSafeDevToolsUtils = require("./ThreadSafeDevToolsUtils.js");
|
const ThreadSafeDevToolsUtils = require("./ThreadSafeDevToolsUtils.js");
|
||||||
for (let key of Object.keys(ThreadSafeDevToolsUtils)) {
|
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.
|
* Waits for the next tick in the event loop to execute a callback.
|
||||||
*/
|
*/
|
||||||
exports.executeSoon = function executeSoon(aFn) {
|
exports.executeSoon = function (fn) {
|
||||||
if (isWorker) {
|
if (isWorker) {
|
||||||
setImmediate(aFn);
|
setImmediate(fn);
|
||||||
} else {
|
} else {
|
||||||
let executor;
|
let executor;
|
||||||
// Only enable async stack reporting when DEBUG_JS_MODULES is set
|
// 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) {
|
if (AppConstants.DEBUG_JS_MODULES || flags.testing) {
|
||||||
let stack = getStack();
|
let stack = getStack();
|
||||||
executor = () => {
|
executor = () => {
|
||||||
callFunctionWithAsyncStack(aFn, stack, "DevToolsUtils.executeSoon");
|
callFunctionWithAsyncStack(fn, stack, "DevToolsUtils.executeSoon");
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
executor = aFn;
|
executor = fn;
|
||||||
}
|
}
|
||||||
Services.tm.mainThread.dispatch({
|
Services.tm.mainThread.dispatch({
|
||||||
run: exports.makeInfallible(executor)
|
run: exports.makeInfallible(executor)
|
||||||
|
|
@ -52,7 +58,7 @@ exports.executeSoon = function executeSoon(aFn) {
|
||||||
* @return Promise
|
* @return Promise
|
||||||
* A promise that is resolved after the next tick in the event loop.
|
* A promise that is resolved after the next tick in the event loop.
|
||||||
*/
|
*/
|
||||||
exports.waitForTick = function waitForTick() {
|
exports.waitForTick = function () {
|
||||||
let deferred = defer();
|
let deferred = defer();
|
||||||
exports.executeSoon(deferred.resolve);
|
exports.executeSoon(deferred.resolve);
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
|
|
@ -61,14 +67,14 @@ exports.waitForTick = function waitForTick() {
|
||||||
/**
|
/**
|
||||||
* Waits for the specified amount of time to pass.
|
* Waits for the specified amount of time to pass.
|
||||||
*
|
*
|
||||||
* @param number aDelay
|
* @param number delay
|
||||||
* The amount of time to wait, in milliseconds.
|
* The amount of time to wait, in milliseconds.
|
||||||
* @return Promise
|
* @return Promise
|
||||||
* A promise that is resolved after the specified amount of time passes.
|
* A promise that is resolved after the specified amount of time passes.
|
||||||
*/
|
*/
|
||||||
exports.waitForTime = function waitForTime(aDelay) {
|
exports.waitForTime = function (delay) {
|
||||||
let deferred = defer();
|
let deferred = defer();
|
||||||
setTimeout(deferred.resolve, aDelay);
|
setTimeout(deferred.resolve, delay);
|
||||||
return deferred.promise;
|
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
|
* very large arrays by yielding to the browser and continuing execution on the
|
||||||
* next tick.
|
* next tick.
|
||||||
*
|
*
|
||||||
* @param Array aArray
|
* @param Array array
|
||||||
* The array being iterated over.
|
* The array being iterated over.
|
||||||
* @param Function aFn
|
* @param Function fn
|
||||||
* The function called on each item in the array. If a promise is
|
* The function called on each item in the array. If a promise is
|
||||||
* returned by this function, iterating over the array will be paused
|
* returned by this function, iterating over the array will be paused
|
||||||
* until the respective promise is resolved.
|
* until the respective promise is resolved.
|
||||||
* @returns Promise
|
* @returns Promise
|
||||||
* A promise that is resolved once the whole array has been iterated
|
* 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();
|
const deferred = defer();
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let len = aArray.length;
|
let len = array.length;
|
||||||
let outstanding = [deferred.promise];
|
let outstanding = [deferred.promise];
|
||||||
|
|
||||||
(function loop() {
|
(function loop() {
|
||||||
|
|
@ -108,7 +114,7 @@ exports.yieldingEach = function yieldingEach(aArray, aFn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
outstanding.push(aFn(aArray[i], i++));
|
outstanding.push(fn(array[i], i++));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
deferred.reject(e);
|
deferred.reject(e);
|
||||||
return;
|
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
|
* allows the lazy getter to be defined on a prototype and work correctly with
|
||||||
* instances.
|
* instances.
|
||||||
*
|
*
|
||||||
* @param Object aObject
|
* @param Object object
|
||||||
* The prototype object to define the lazy getter on.
|
* The prototype object to define the lazy getter on.
|
||||||
* @param String aKey
|
* @param String key
|
||||||
* The key to define the lazy getter on.
|
* 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
|
* The callback that will be called to determine the value. Will be
|
||||||
* called with the |this| value of the current instance.
|
* called with the |this| value of the current instance.
|
||||||
*/
|
*/
|
||||||
exports.defineLazyPrototypeGetter =
|
exports.defineLazyPrototypeGetter = function (object, key, callback) {
|
||||||
function defineLazyPrototypeGetter(aObject, aKey, aCallback) {
|
Object.defineProperty(object, key, {
|
||||||
Object.defineProperty(aObject, aKey, {
|
|
||||||
configurable: true,
|
configurable: true,
|
||||||
get: function () {
|
get: function () {
|
||||||
const value = aCallback.call(this);
|
const value = callback.call(this);
|
||||||
|
|
||||||
Object.defineProperty(this, aKey, {
|
Object.defineProperty(this, key, {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
writable: true,
|
writable: true,
|
||||||
value: value
|
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
|
* Safely get the property value from a Debugger.Object for a given key. Walks
|
||||||
* the prototype chain until the property is found.
|
* the prototype chain until the property is found.
|
||||||
*
|
*
|
||||||
* @param Debugger.Object aObject
|
* @param Debugger.Object object
|
||||||
* The Debugger.Object to get the value from.
|
* The Debugger.Object to get the value from.
|
||||||
* @param String aKey
|
* @param String key
|
||||||
* The key to look for.
|
* The key to look for.
|
||||||
* @return Any
|
* @return Any
|
||||||
*/
|
*/
|
||||||
exports.getProperty = function getProperty(aObj, aKey) {
|
exports.getProperty = function (object, key) {
|
||||||
let root = aObj;
|
let root = object;
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
const desc = aObj.getOwnPropertyDescriptor(aKey);
|
const desc = object.getOwnPropertyDescriptor(key);
|
||||||
if (desc) {
|
if (desc) {
|
||||||
if ("value" in desc) {
|
if ("value" in desc) {
|
||||||
return desc.value;
|
return desc.value;
|
||||||
|
|
@ -174,8 +179,8 @@ exports.getProperty = function getProperty(aObj, aKey) {
|
||||||
// Call the getter if it's safe.
|
// Call the getter if it's safe.
|
||||||
return exports.hasSafeGetter(desc) ? desc.get.call(root).return : undefined;
|
return exports.hasSafeGetter(desc) ? desc.get.call(root).return : undefined;
|
||||||
}
|
}
|
||||||
aObj = aObj.proto;
|
object = object.proto;
|
||||||
} while (aObj);
|
} while (object);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// If anything goes wrong report the error and return undefined.
|
// If anything goes wrong report the error and return undefined.
|
||||||
exports.reportException("getProperty", e);
|
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.
|
* 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.
|
* The descriptor to check for a safe getter.
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
* Whether a safe getter was found.
|
* 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
|
// Scripted functions that are CCWs will not appear scripted until after
|
||||||
// unwrapping.
|
// unwrapping.
|
||||||
try {
|
try {
|
||||||
let fn = aDesc.get.unwrap();
|
let fn = desc.get.unwrap();
|
||||||
return fn && fn.callable && fn.class == "Function" && fn.script === undefined;
|
return fn && fn.callable && fn.class == "Function" && fn.script === undefined;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Avoid exception 'Object in compartment marked as invisible to Debugger'
|
// 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.
|
* See bugs 945920 and 946752 for discussion.
|
||||||
*
|
*
|
||||||
* @type Object aObj
|
* @type Object obj
|
||||||
* The object to check.
|
* The object to check.
|
||||||
* @return Boolean
|
* @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,
|
// 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.
|
// we always return false, just to be on the safe side.
|
||||||
if (isWorker) {
|
if (isWorker) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cu.getGlobalForObject(aObj) ==
|
if (Cu.getGlobalForObject(obj) ==
|
||||||
Cu.getGlobalForObject(exports.isSafeJSObject)) {
|
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)) {
|
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) {
|
if (flags.wantLogging) {
|
||||||
dump("DBG-SERVER: " + str + "\n");
|
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.
|
* 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.
|
* The object to define the lazy getter on.
|
||||||
* @param aName
|
* @param name
|
||||||
* The name of the getter to define on aObject.
|
* The name of the getter to define on object.
|
||||||
* @param aLambda
|
* @param lambda
|
||||||
* A function that returns what the getter should return. This will
|
* A function that returns what the getter should return. This will
|
||||||
* only ever be called once.
|
* only ever be called once.
|
||||||
*/
|
*/
|
||||||
exports.defineLazyGetter = function defineLazyGetter(aObject, aName, aLambda) {
|
exports.defineLazyGetter = function (object, name, lambda) {
|
||||||
Object.defineProperty(aObject, aName, {
|
Object.defineProperty(object, name, {
|
||||||
get: function () {
|
get: function () {
|
||||||
delete aObject[aName];
|
delete object[name];
|
||||||
return aObject[aName] = aLambda.apply(aObject);
|
object[name] = lambda.apply(object);
|
||||||
|
return object[name];
|
||||||
},
|
},
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.defineLazyGetter(this, "AppConstants", () => {
|
DevToolsUtils.defineLazyGetter(this, "AppConstants", () => {
|
||||||
if (isWorker) {
|
if (isWorker) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
@ -329,47 +337,44 @@ Object.defineProperty(exports, "assert", {
|
||||||
* Defines a getter on a specified object for a module. The module will not
|
* Defines a getter on a specified object for a module. The module will not
|
||||||
* be imported until first use.
|
* be imported until first use.
|
||||||
*
|
*
|
||||||
* @param aObject
|
* @param object
|
||||||
* The object to define the lazy getter on.
|
* The object to define the lazy getter on.
|
||||||
* @param aName
|
* @param name
|
||||||
* The name of the getter to define on aObject for the module.
|
* The name of the getter to define on object for the module.
|
||||||
* @param aResource
|
* @param resource
|
||||||
* The URL used to obtain the module.
|
* The URL used to obtain the module.
|
||||||
* @param aSymbol
|
* @param symbol
|
||||||
* The name of the symbol exported by the module.
|
* 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,
|
exports.defineLazyModuleGetter = function (object, name, resource, symbol) {
|
||||||
aResource,
|
this.defineLazyGetter(object, name, function () {
|
||||||
aSymbol)
|
let temp = {};
|
||||||
{
|
Cu.import(resource, temp);
|
||||||
this.defineLazyGetter(aObject, aName, function XPCU_moduleLambda() {
|
return temp[symbol || name];
|
||||||
var temp = {};
|
|
||||||
Cu.import(aResource, temp);
|
|
||||||
return temp[aSymbol || aName];
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.defineLazyGetter(this, "NetUtil", () => {
|
DevToolsUtils.defineLazyGetter(this, "NetUtil", () => {
|
||||||
return Cu.import("resource://gre/modules/NetUtil.jsm", {}).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;
|
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;
|
return Cu.import("resource://gre/modules/osfile.jsm", {}).TextDecoder;
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.defineLazyGetter(this, "NetworkHelper", () => {
|
DevToolsUtils.defineLazyGetter(this, "NetworkHelper", () => {
|
||||||
return require("devtools/shared/webconsole/network-helper");
|
return require("devtools/shared/webconsole/network-helper");
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a request to load the desired URL and returns a promise.
|
* Performs a request to load the desired URL and returns a promise.
|
||||||
*
|
*
|
||||||
* @param aURL String
|
* @param urlIn String
|
||||||
* The URL we will request.
|
* The URL we will request.
|
||||||
* @param aOptions Object
|
* @param aOptions Object
|
||||||
* An object with the following optional properties:
|
* 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.):
|
* without relying on caching when we can (not for eval, etc.):
|
||||||
* http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/
|
* 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,
|
policy: Ci.nsIContentPolicy.TYPE_OTHER,
|
||||||
window: null,
|
window: null,
|
||||||
charset: null,
|
charset: null,
|
||||||
principal: null,
|
principal: null,
|
||||||
cacheKey: null }) {
|
cacheKey: null }) {
|
||||||
// Create a channel.
|
// Create a channel.
|
||||||
let url = aURL.split(" -> ").pop();
|
let url = urlIn.split(" -> ").pop();
|
||||||
let channel;
|
let channel;
|
||||||
try {
|
try {
|
||||||
channel = newChannelForURL(url, aOptions);
|
channel = newChannelForURL(url, aOptions);
|
||||||
|
|
@ -526,7 +531,7 @@ function mainThreadFetch(aURL, aOptions = { loadFromCache: true,
|
||||||
* @return {nsIChannel} - The newly created channel. Throws on failure.
|
* @return {nsIChannel} - The newly created channel. Throws on failure.
|
||||||
*/
|
*/
|
||||||
function newChannelForURL(url, { policy, window, principal }) {
|
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;
|
let uri;
|
||||||
try {
|
try {
|
||||||
|
|
@ -570,15 +575,15 @@ function newChannelForURL(url, { policy, window, principal }) {
|
||||||
|
|
||||||
// Fetch is defined differently depending on whether we are on the main thread
|
// Fetch is defined differently depending on whether we are on the main thread
|
||||||
// or a worker thread.
|
// or a worker thread.
|
||||||
if (!this.isWorker) {
|
if (this.isWorker) {
|
||||||
exports.fetch = mainThreadFetch;
|
|
||||||
} else {
|
|
||||||
// Services is not available in worker threads, nor is there any other way
|
// 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
|
// 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.
|
// issuing an rpc request, to fetch the URL on our behalf.
|
||||||
exports.fetch = function (url, options) {
|
exports.fetch = function (url, options) {
|
||||||
return rpc("fetch", 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
|
// Calls the property with the given `name` on the given `object`, where
|
||||||
// `name` is a string, and `object` a Debugger.Object instance.
|
// `name` is a string, and `object` a Debugger.Object instance.
|
||||||
///
|
//
|
||||||
// This function uses only the Debugger.Object API to call the property. It
|
// 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,
|
// avoids the use of unsafeDeference. This is useful for example in workers,
|
||||||
// where unsafeDereference will return an opaque security wrapper to the
|
// where unsafeDereference will return an opaque security wrapper to the
|
||||||
|
|
@ -668,5 +673,4 @@ function callPropertyOnObject(object, name) {
|
||||||
return result.return;
|
return result.return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.callPropertyOnObject = callPropertyOnObject;
|
exports.callPropertyOnObject = callPropertyOnObject;
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ exports.reportException = function reportException(who, exception) {
|
||||||
* don't have a way to get at them from JavaScript at the moment.)
|
* don't have a way to get at them from JavaScript at the moment.)
|
||||||
*/
|
*/
|
||||||
exports.makeInfallible = function (handler, name = handler.name) {
|
exports.makeInfallible = function (handler, name = handler.name) {
|
||||||
return function (/* arguments */) {
|
return function () {
|
||||||
try {
|
try {
|
||||||
return handler.apply(this, arguments);
|
return handler.apply(this, arguments);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
|
@ -128,7 +128,9 @@ exports.safeErrorString = function (error) {
|
||||||
errorString += "\nStack: " + stack;
|
errorString += "\nStack: " + stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ee) { }
|
} catch (ee) {
|
||||||
|
// Ignore.
|
||||||
|
}
|
||||||
|
|
||||||
// Append additional line and column number information to the output,
|
// Append additional line and column number information to the output,
|
||||||
// since it might not be part of the stringified error.
|
// since it might not be part of the stringified error.
|
||||||
|
|
@ -138,7 +140,9 @@ exports.safeErrorString = function (error) {
|
||||||
|
|
||||||
return errorString;
|
return errorString;
|
||||||
}
|
}
|
||||||
} catch (ee) { }
|
} catch (ee) {
|
||||||
|
// Ignore.
|
||||||
|
}
|
||||||
|
|
||||||
// We failed to find a good error description, so do the next best thing.
|
// We failed to find a good error description, so do the next best thing.
|
||||||
return Object.prototype.toString.call(error);
|
return Object.prototype.toString.call(error);
|
||||||
|
|
@ -294,7 +298,7 @@ exports.settleAll = values => {
|
||||||
|
|
||||||
if (!countdown) {
|
if (!countdown) {
|
||||||
resolve(resolutionValues);
|
resolve(resolutionValues);
|
||||||
return deferred.promise;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForCompletion() {
|
function checkForCompletion() {
|
||||||
|
|
|
||||||
|
|
@ -20,32 +20,31 @@ const jsmScope = Cu.import("resource://gre/modules/Services.jsm", {});
|
||||||
const { Services } = jsmScope;
|
const { Services } = jsmScope;
|
||||||
// Steal various globals only available in JSM scope (and not Sandbox one)
|
// Steal various globals only available in JSM scope (and not Sandbox one)
|
||||||
const { PromiseDebugging, ChromeUtils, ThreadSafeChromeUtils, HeapSnapshot,
|
const { PromiseDebugging, ChromeUtils, ThreadSafeChromeUtils, HeapSnapshot,
|
||||||
atob, btoa, Iterator } = jsmScope;
|
atob, btoa } = jsmScope;
|
||||||
const { URL } = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
|
const { URL } = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
|
||||||
{wantGlobalProperties: ["URL"]});
|
{wantGlobalProperties: ["URL"]});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a getter on a specified object that will be created upon first use.
|
* 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.
|
* The object to define the lazy getter on.
|
||||||
* @param aName
|
* @param name
|
||||||
* The name of the getter to define on aObject.
|
* The name of the getter to define on object.
|
||||||
* @param aLambda
|
* @param lambda
|
||||||
* A function that returns what the getter should return. This will
|
* A function that returns what the getter should return. This will
|
||||||
* only ever be called once.
|
* only ever be called once.
|
||||||
*/
|
*/
|
||||||
function defineLazyGetter(aObject, aName, aLambda)
|
function defineLazyGetter(object, name, lambda) {
|
||||||
{
|
Object.defineProperty(object, name, {
|
||||||
Object.defineProperty(aObject, aName, {
|
|
||||||
get: function () {
|
get: function () {
|
||||||
// Redefine this accessor property as a data property.
|
// 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
|
// a proxy whose defineProperty handler might unwittingly trigger this
|
||||||
// getter again.
|
// getter again.
|
||||||
delete aObject[aName];
|
delete object[name];
|
||||||
let value = aLambda.apply(aObject);
|
let value = lambda.apply(object);
|
||||||
Object.defineProperty(aObject, aName, {
|
Object.defineProperty(object, name, {
|
||||||
value,
|
value,
|
||||||
writable: true,
|
writable: true,
|
||||||
configurable: 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
|
* Defines a getter on a specified object for a service. The service will not
|
||||||
* be obtained until first use.
|
* be obtained until first use.
|
||||||
*
|
*
|
||||||
* @param aObject
|
* @param object
|
||||||
* The object to define the lazy getter on.
|
* The object to define the lazy getter on.
|
||||||
* @param aName
|
* @param name
|
||||||
* The name of the getter to define on aObject for the service.
|
* The name of the getter to define on object for the service.
|
||||||
* @param aContract
|
* @param contract
|
||||||
* The contract used to obtain the service.
|
* The contract used to obtain the service.
|
||||||
* @param aInterfaceName
|
* @param interfaceName
|
||||||
* The name of the interface to query the service to.
|
* The name of the interface to query the service to.
|
||||||
*/
|
*/
|
||||||
function defineLazyServiceGetter(aObject, aName, aContract, aInterfaceName)
|
function defineLazyServiceGetter(object, name, contract, interfaceName) {
|
||||||
{
|
defineLazyGetter(object, name, function () {
|
||||||
defineLazyGetter(aObject, aName, function XPCU_serviceLambda() {
|
return Cc[contract].getService(Ci[interfaceName]);
|
||||||
return Cc[aContract].getService(Ci[aInterfaceName]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,48 +82,47 @@ function defineLazyServiceGetter(aObject, aName, aContract, aInterfaceName)
|
||||||
* teardown code (e.g. to register/unregister to services) and accepts
|
* 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.
|
* 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.
|
* The object to define the lazy getter on.
|
||||||
* @param aName
|
* @param name
|
||||||
* The name of the getter to define on aObject for the module.
|
* The name of the getter to define on object for the module.
|
||||||
* @param aResource
|
* @param resource
|
||||||
* The URL used to obtain the module.
|
* The URL used to obtain the module.
|
||||||
* @param aSymbol
|
* @param symbol
|
||||||
* The name of the symbol exported by the module.
|
* 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.
|
||||||
* @param aPreLambda
|
* @param preLambda
|
||||||
* A function that is executed when the proxy is set up.
|
* A function that is executed when the proxy is set up.
|
||||||
* This will only ever be called once.
|
* This will only ever be called once.
|
||||||
* @param aPostLambda
|
* @param postLambda
|
||||||
* A function that is executed when the module has been imported to
|
* A function that is executed when the module has been imported to
|
||||||
* run optional teardown procedures on the proxy object.
|
* run optional teardown procedures on the proxy object.
|
||||||
* This will only ever be called once.
|
* This will only ever be called once.
|
||||||
* @param aProxy
|
* @param proxy
|
||||||
* An object which acts on behalf of the module to be imported until
|
* An object which acts on behalf of the module to be imported until
|
||||||
* the module has been imported.
|
* the module has been imported.
|
||||||
*/
|
*/
|
||||||
function defineLazyModuleGetter(aObject, aName, aResource, aSymbol,
|
function defineLazyModuleGetter(object, name, resource, symbol,
|
||||||
aPreLambda, aPostLambda, aProxy)
|
preLambda, postLambda, proxy) {
|
||||||
{
|
proxy = proxy || {};
|
||||||
let proxy = aProxy || {};
|
|
||||||
|
|
||||||
if (typeof (aPreLambda) === "function") {
|
if (typeof (preLambda) === "function") {
|
||||||
aPreLambda.apply(proxy);
|
preLambda.apply(proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
defineLazyGetter(aObject, aName, function XPCU_moduleLambda() {
|
defineLazyGetter(object, name, function () {
|
||||||
var temp = {};
|
let temp = {};
|
||||||
try {
|
try {
|
||||||
Cu.import(aResource, temp);
|
Cu.import(resource, temp);
|
||||||
|
|
||||||
if (typeof (aPostLambda) === "function") {
|
if (typeof (postLambda) === "function") {
|
||||||
aPostLambda.apply(proxy);
|
postLambda.apply(proxy);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Cu.reportError("Failed to load module " + aResource + ".");
|
Cu.reportError("Failed to load module " + resource + ".");
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
return temp[aSymbol || aName];
|
return temp[symbol || name];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,7 +221,8 @@ exports.globals = {
|
||||||
lazyImporter: defineLazyModuleGetter,
|
lazyImporter: defineLazyModuleGetter,
|
||||||
lazyServiceGetter: defineLazyServiceGetter,
|
lazyServiceGetter: defineLazyServiceGetter,
|
||||||
lazyRequireGetter: lazyRequireGetter,
|
lazyRequireGetter: lazyRequireGetter,
|
||||||
id: null // Defined by Loader.jsm
|
// Defined by Loader.jsm
|
||||||
|
id: null
|
||||||
},
|
},
|
||||||
|
|
||||||
// Let new XMLHttpRequest do the right thing.
|
// Let new XMLHttpRequest do the right thing.
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const {Cc, Ci, Cu, Cr} = require("chrome");
|
const {Ci} = require("chrome");
|
||||||
const Services = require("Services");
|
const Services = require("Services");
|
||||||
|
|
||||||
const events = require("sdk/event/core");
|
const events = require("sdk/event/core");
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
* THIS MODULE IS DEPRECATED. IMPORT "Promise.jsm" INSTEAD.
|
* THIS MODULE IS DEPRECATED. IMPORT "Promise.jsm" INSTEAD.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this.Promise = {};
|
this.Promise = {};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/* globals define */
|
||||||
|
|
||||||
// Make this available to both AMD and CJS environments
|
// Make this available to both AMD and CJS environments
|
||||||
define(function (require, exports, module) {
|
define(function (require, exports, module) {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a writable property by tracking it with a private variable.
|
* Create a writable property by tracking it with a private variable.
|
||||||
|
|
@ -7,8 +8,12 @@
|
||||||
function makeWritableFlag(exports, name) {
|
function makeWritableFlag(exports, name) {
|
||||||
let flag = false;
|
let flag = false;
|
||||||
Object.defineProperty(exports, name, {
|
Object.defineProperty(exports, name, {
|
||||||
get: function () { return flag; },
|
get: function () {
|
||||||
set: function (state) { flag = state; }
|
return flag;
|
||||||
|
},
|
||||||
|
set: function (state) {
|
||||||
|
flag = state;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,8 @@ exports.joinURI = (initialPath, ...paths) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
url = new URL(initialPath);
|
url = new URL(initialPath);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
return null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let path of paths) {
|
for (let path of paths) {
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,9 @@ types.getType = function (type) {
|
||||||
|
|
||||||
// If already registered, we're done here.
|
// If already registered, we're done here.
|
||||||
let reg = registeredTypes.get(type);
|
let reg = registeredTypes.get(type);
|
||||||
if (reg) return reg;
|
if (reg) {
|
||||||
|
return reg;
|
||||||
|
}
|
||||||
|
|
||||||
// New type, see if it's a collection/lifetime type:
|
// New type, see if it's a collection/lifetime type:
|
||||||
let sep = type.indexOf(":");
|
let sep = type.indexOf(":");
|
||||||
|
|
@ -146,7 +148,9 @@ types.addType = function (name, typeObject = {}, options = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let type = object.merge({
|
let type = object.merge({
|
||||||
toString() { return "[protocol type:" + name + "]";},
|
toString() {
|
||||||
|
return "[protocol type:" + name + "]";
|
||||||
|
},
|
||||||
name: name,
|
name: name,
|
||||||
primitive: !(typeObject.read || typeObject.write),
|
primitive: !(typeObject.read || typeObject.write),
|
||||||
read: identityWrite,
|
read: identityWrite,
|
||||||
|
|
@ -170,7 +174,9 @@ types.removeType = function (name) {
|
||||||
type.name = "DEFUNCT:" + name;
|
type.name = "DEFUNCT:" + name;
|
||||||
type.category = "defunct";
|
type.category = "defunct";
|
||||||
type.primitive = false;
|
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);
|
registeredTypes.delete(name);
|
||||||
};
|
};
|
||||||
|
|
@ -274,7 +280,7 @@ types.addActorType = function (name) {
|
||||||
let actorID = typeof (v) === "string" ? v : v.actor;
|
let actorID = typeof (v) === "string" ? v : v.actor;
|
||||||
let front = ctx.conn.getActor(actorID);
|
let front = ctx.conn.getActor(actorID);
|
||||||
if (!front) {
|
if (!front) {
|
||||||
front = new type.frontClass(ctx.conn);
|
front = new type.frontClass(ctx.conn); // eslint-disable-line new-cap
|
||||||
front.actorID = actorID;
|
front.actorID = actorID;
|
||||||
ctx.marshallPool().manage(front);
|
ctx.marshallPool().manage(front);
|
||||||
}
|
}
|
||||||
|
|
@ -353,7 +359,8 @@ types.addNullableType = function (subtype) {
|
||||||
types.addActorDetail = function (name, actorType, detail) {
|
types.addActorDetail = function (name, actorType, detail) {
|
||||||
actorType = types.getType(actorType);
|
actorType = types.getType(actorType);
|
||||||
if (!actorType._actor) {
|
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, {
|
return types.addType(name, {
|
||||||
_actor: true,
|
_actor: true,
|
||||||
|
|
@ -402,7 +409,8 @@ types.removeLifetime = function (name) {
|
||||||
types.addLifetimeType = function (lifetime, subtype) {
|
types.addLifetimeType = function (lifetime, subtype) {
|
||||||
subtype = types.getType(subtype);
|
subtype = types.getType(subtype);
|
||||||
if (!subtype._actor) {
|
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);
|
let prop = registeredLifetimes.get(lifetime);
|
||||||
return types.addType(lifetime + ":" + subtype.name, {
|
return types.addType(lifetime + ":" + subtype.name, {
|
||||||
|
|
@ -580,7 +588,6 @@ function findPlaceholders(template, constructor, path = [], placeholders = []) {
|
||||||
return placeholders;
|
return placeholders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function describeTemplate(template) {
|
function describeTemplate(template) {
|
||||||
return JSON.parse(JSON.stringify(template, (key, value) => {
|
return JSON.parse(JSON.stringify(template, (key, value) => {
|
||||||
if (value.describe) {
|
if (value.describe) {
|
||||||
|
|
@ -644,7 +651,9 @@ var Request = Class({
|
||||||
return fnArgs;
|
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);
|
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.
|
* 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
|
* Override this if you want actors returned by this actor
|
||||||
* to belong to a different actor by default.
|
* 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.
|
* Pool is the base class for all actors, even leaf nodes.
|
||||||
|
|
@ -749,7 +764,9 @@ var Pool = Class({
|
||||||
*/
|
*/
|
||||||
__poolMap: null,
|
__poolMap: null,
|
||||||
get _poolMap() {
|
get _poolMap() {
|
||||||
if (this.__poolMap) return this.__poolMap;
|
if (this.__poolMap) {
|
||||||
|
return this.__poolMap;
|
||||||
|
}
|
||||||
this.__poolMap = new Map();
|
this.__poolMap = new Map();
|
||||||
this.conn.addActorPool(this);
|
this.conn.addActorPool(this);
|
||||||
return this.__poolMap;
|
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) {
|
_sendEvent: function (name, ...args) {
|
||||||
if (!this._actorSpec.events.has(name)) {
|
if (!this._actorSpec.events.has(name)) {
|
||||||
|
|
@ -950,8 +969,12 @@ exports.Actor = Actor;
|
||||||
*/
|
*/
|
||||||
exports.method = function (fn, spec = {}) {
|
exports.method = function (fn, spec = {}) {
|
||||||
fn._methodSpec = Object.freeze(spec);
|
fn._methodSpec = Object.freeze(spec);
|
||||||
if (spec.request) Object.freeze(spec.request);
|
if (spec.request) {
|
||||||
if (spec.response) Object.freeze(spec.response);
|
Object.freeze(spec.request);
|
||||||
|
}
|
||||||
|
if (spec.response) {
|
||||||
|
Object.freeze(spec.response);
|
||||||
|
}
|
||||||
return fn;
|
return fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -986,7 +1009,8 @@ var generateActorSpec = function (actorDesc) {
|
||||||
let methodSpec = desc.value._methodSpec;
|
let methodSpec = desc.value._methodSpec;
|
||||||
let spec = {};
|
let spec = {};
|
||||||
spec.name = methodSpec.name || name;
|
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.response = Response(methodSpec.response || undefined);
|
||||||
spec.release = methodSpec.release;
|
spec.release = methodSpec.release;
|
||||||
spec.oneway = methodSpec.oneway;
|
spec.oneway = methodSpec.oneway;
|
||||||
|
|
@ -1002,7 +1026,8 @@ var generateActorSpec = function (actorDesc) {
|
||||||
let spec = {};
|
let spec = {};
|
||||||
|
|
||||||
spec.name = methodSpec.name || name;
|
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.response = Response(methodSpec.response || undefined);
|
||||||
spec.release = methodSpec.release;
|
spec.release = methodSpec.release;
|
||||||
spec.oneway = methodSpec.oneway;
|
spec.oneway = methodSpec.oneway;
|
||||||
|
|
@ -1056,7 +1081,7 @@ var generateRequestHandlers = function (actorSpec, actorProto) {
|
||||||
|
|
||||||
let ret = this[spec.name].apply(this, args);
|
let ret = this[spec.name].apply(this, args);
|
||||||
|
|
||||||
let sendReturn = (ret) => {
|
let sendReturn = (retToSend) => {
|
||||||
if (spec.oneway) {
|
if (spec.oneway) {
|
||||||
// No need to send a response.
|
// No need to send a response.
|
||||||
return;
|
return;
|
||||||
|
|
@ -1064,7 +1089,7 @@ var generateRequestHandlers = function (actorSpec, actorProto) {
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = spec.response.write(ret, this);
|
response = spec.response.write(retToSend, this);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error("Error writing response to: " + spec.name);
|
console.error("Error writing response to: " + spec.name);
|
||||||
throw ex;
|
throw ex;
|
||||||
|
|
@ -1202,9 +1227,13 @@ var Front = Class({
|
||||||
* @returns a promise that will resolve to the actorID this front
|
* @returns a promise that will resolve to the actorID this front
|
||||||
* represents.
|
* 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.
|
* 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,
|
// Check to see if any of the preEvents returned a promise -- if so,
|
||||||
// wait for their resolution before emitting. Otherwise, emit synchronously.
|
// wait for their resolution before emitting. Otherwise, emit synchronously.
|
||||||
if (results.some(result => result && typeof result.then === "function")) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1368,7 +1399,8 @@ var generateRequestMethods = function (actorSpec, frontProto) {
|
||||||
if (name in frontProto) {
|
if (name in frontProto) {
|
||||||
let custom = frontProto[spec.name]._customFront;
|
let custom = frontProto[spec.name]._customFront;
|
||||||
if (custom === undefined) {
|
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 the user doesn't need the impl don't generate it.
|
||||||
if (!custom.impl) {
|
if (!custom.impl) {
|
||||||
|
|
@ -1415,12 +1447,11 @@ var generateRequestMethods = function (actorSpec, frontProto) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Process event specifications
|
// Process event specifications
|
||||||
frontProto._clientSpec = {};
|
frontProto._clientSpec = {};
|
||||||
|
|
||||||
let events = actorSpec.events;
|
let actorEvents = actorSpec.events;
|
||||||
if (events) {
|
if (actorEvents) {
|
||||||
// This actor has events, scan the prototype for preEvent handlers...
|
// This actor has events, scan the prototype for preEvent handlers...
|
||||||
let preHandlers = new Map();
|
let preHandlers = new Map();
|
||||||
for (let name of Object.getOwnPropertyNames(frontProto)) {
|
for (let name of Object.getOwnPropertyNames(frontProto)) {
|
||||||
|
|
@ -1430,7 +1461,7 @@ var generateRequestMethods = function (actorSpec, frontProto) {
|
||||||
}
|
}
|
||||||
if (desc.value._preEvent) {
|
if (desc.value._preEvent) {
|
||||||
let preEvent = 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);
|
throw Error("preEvent for event that doesn't exist: " + preEvent);
|
||||||
}
|
}
|
||||||
let handlers = preHandlers.get(preEvent);
|
let handlers = preHandlers.get(preEvent);
|
||||||
|
|
@ -1444,7 +1475,7 @@ var generateRequestMethods = function (actorSpec, frontProto) {
|
||||||
|
|
||||||
frontProto._clientSpec.events = new Map();
|
frontProto._clientSpec.events = new Map();
|
||||||
|
|
||||||
for (let [name, request] of events) {
|
for (let [name, request] of actorEvents) {
|
||||||
frontProto._clientSpec.events.set(request.type, {
|
frontProto._clientSpec.events.set(request.type, {
|
||||||
name: name,
|
name: name,
|
||||||
request: request,
|
request: request,
|
||||||
|
|
@ -1518,7 +1549,6 @@ exports.dumpActorSpec = function (type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSON.stringify(ret);
|
JSON.stringify(ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { Cc, Ci, Cu } = require("chrome");
|
const { Cc, Ci } = require("chrome");
|
||||||
const { Task } = require("devtools/shared/task");
|
const { Task } = require("devtools/shared/task");
|
||||||
|
|
||||||
loader.lazyRequireGetter(this, "Services");
|
loader.lazyRequireGetter(this, "Services");
|
||||||
|
|
@ -64,10 +64,10 @@ function* getSystemInfo() {
|
||||||
hardware = yield exports.getSetting("deviceinfo.hardware");
|
hardware = yield exports.getSetting("deviceinfo.hardware");
|
||||||
version = yield exports.getSetting("deviceinfo.os");
|
version = yield exports.getSetting("deviceinfo.os");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// Ignore.
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
// Not B2G
|
// Not B2G
|
||||||
else {
|
|
||||||
os = appInfo.OS;
|
os = appInfo.OS;
|
||||||
version = appInfo.version;
|
version = appInfo.version;
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +80,8 @@ function* getSystemInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (win) {
|
if (win) {
|
||||||
let utils = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
let utils = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils);
|
||||||
dpi = utils.displayDPI;
|
dpi = utils.displayDPI;
|
||||||
useragent = win.navigator.userAgent;
|
useragent = win.navigator.userAgent;
|
||||||
width = win.screen.width;
|
width = win.screen.width;
|
||||||
|
|
@ -131,7 +132,8 @@ function* getSystemInfo() {
|
||||||
geckoversion: geckoVersion,
|
geckoversion: geckoVersion,
|
||||||
|
|
||||||
// Locale used in this build
|
// 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.
|
* Information regarding the operating system.
|
||||||
|
|
@ -186,12 +188,13 @@ function getProfileLocation() {
|
||||||
// In child processes, we cannot access the profile location.
|
// In child processes, we cannot access the profile location.
|
||||||
try {
|
try {
|
||||||
let profd = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
let profd = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||||
let profservice = Cc["@mozilla.org/toolkit/profile-service;1"].getService(Ci.nsIToolkitProfileService);
|
let profservice = Cc["@mozilla.org/toolkit/profile-service;1"]
|
||||||
var profiles = profservice.profiles;
|
.getService(Ci.nsIToolkitProfileService);
|
||||||
|
let profiles = profservice.profiles;
|
||||||
while (profiles.hasMoreElements()) {
|
while (profiles.hasMoreElements()) {
|
||||||
let profile = profiles.getNext().QueryInterface(Ci.nsIToolkitProfile);
|
let profile = profiles.getNext().QueryInterface(Ci.nsIToolkitProfile);
|
||||||
if (profile.rootDir.path == profd.path) {
|
if (profile.rootDir.path == profd.path) {
|
||||||
return profile = profile.name;
|
return profile.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,7 +217,8 @@ function getAppIniString(section, key) {
|
||||||
return undefined;
|
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 {
|
try {
|
||||||
return iniParser.getString(section, key);
|
return iniParser.getString(section, key);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -316,13 +320,14 @@ function getSetting(name) {
|
||||||
// settingsService fails in b2g child processes
|
// settingsService fails in b2g child processes
|
||||||
// TODO bug 1205797, make this work in child processes.
|
// TODO bug 1205797, make this work in child processes.
|
||||||
try {
|
try {
|
||||||
settingsService = Cc["@mozilla.org/settingsService;1"].getService(Ci.nsISettingsService);
|
settingsService = Cc["@mozilla.org/settingsService;1"]
|
||||||
|
.getService(Ci.nsISettingsService);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return promise.reject(e);
|
return promise.reject(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
let req = settingsService.createLock().get(name, {
|
settingsService.createLock().get(name, {
|
||||||
handle: (name, value) => deferred.resolve(value),
|
handle: (_, value) => deferred.resolve(value),
|
||||||
handleError: (error) => deferred.reject(error),
|
handleError: (error) => deferred.reject(error),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue