Bug 1016301 - Convert testactors.js to use native promises;r=past

This commit is contained in:
Eddy Bruel 2014-06-17 21:53:35 +02:00
parent 08fc0aebce
commit fc08592611
2 changed files with 62 additions and 69 deletions

View File

@ -44,7 +44,7 @@ function TestTabList(aConnection) {
TestTabList.prototype = {
constructor: TestTabList,
getList: function () {
return promise.resolve([tabActor for (tabActor of this._tabActors)]);
return Promise.resolve([tabActor for (tabActor of this._tabActors)]);
}
};

View File

@ -269,75 +269,68 @@ const chrome = { CC: undefined, Cc: undefined, ChromeWorker: undefined,
// The default instance of the worker debugger loader is defined differently
// depending on whether it is loaded from the main thread or a worker thread.
if (typeof Components === "object") {
(function () {
const { Constructor: CC, classes: Cc, manager: Cm, interfaces: Ci,
results: Cr, utils: Cu } = Components;
const { Constructor: CC, classes: Cc, manager: Cm, interfaces: Ci,
results: Cr, utils: Cu } = Components;
const principal = CC('@mozilla.org/systemprincipal;1', 'nsIPrincipal')();
const principal = CC('@mozilla.org/systemprincipal;1', 'nsIPrincipal')();
// Create a sandbox with the given name and prototype.
const createSandbox = function (name, prototype) {
return Cu.Sandbox(principal, {
invisibleToDebugger: true,
sandboxName: name,
sandboxPrototype: prototype,
wantComponents: false,
wantXrays: false
});
};
const loadSubScript = Cc['@mozilla.org/moz/jssubscript-loader;1'].
getService(Ci.mozIJSSubScriptLoader).loadSubScript;
// Load a script from the given URL in the given sandbox.
const loadInSandbox = function (url, sandbox) {
loadSubScript(url, sandbox, "UTF-8");
};
// Define the Debugger object in a sandbox to ensure that the this passed to
// addDebuggerToGlobal is a global.
const Debugger = (function () {
let sandbox = Cu.Sandbox(principal, {});
Cu.evalInSandbox(
"Components.utils.import('resource://gre/modules/jsdebugger.jsm');" +
"addDebuggerToGlobal(this);",
sandbox
);
return sandbox.Debugger;
})();
// TODO: Replace this with native promises: bug 1016301
const { Promise } = Cu.import("resource://gre/modules/Promise.jsm", {});;
const Timer = Cu.import("resource://gre/modules/Timer.jsm", {});
const xpcInspector = Cc["@mozilla.org/jsinspector;1"].
getService(Ci.nsIJSInspector);
this.worker = new WorkerDebuggerLoader({
createSandbox: createSandbox,
globals: {
"isWorker": true,
"Debugger": Debugger,
"promise": Promise,
"reportError": Cu.reportError,
"setInterval": Timer.setInterval,
"setTimeout": Timer.setTimeout,
"clearInterval": Timer.clearInterval,
"clearTimeout": Timer.clearTimeout,
"xpcInspector": xpcInspector,
},
loadInSandbox: loadInSandbox,
modules: {
"Services": {},
"chrome": chrome,
},
paths: {
"": "resource://gre/modules/commonjs/",
"devtools": "resource:///modules/devtools",
"devtools/server": "resource://gre/modules/devtools/server",
"devtools/toolkit": "resource://gre/modules/devtools",
"source-map": "resource://gre/modules/devtools/source-map",
"xpcshell-test": "resource://test",
}
// Create a sandbox with the given name and prototype.
const createSandbox = function (name, prototype) {
return Cu.Sandbox(principal, {
invisibleToDebugger: true,
sandboxName: name,
sandboxPrototype: prototype,
wantComponents: false,
wantXrays: false
});
}).call(this);
};
const loadSubScript = Cc['@mozilla.org/moz/jssubscript-loader;1'].
getService(Ci.mozIJSSubScriptLoader).loadSubScript;
// Load a script from the given URL in the given sandbox.
const loadInSandbox = function (url, sandbox) {
loadSubScript(url, sandbox, "UTF-8");
};
// Define the Debugger object in a sandbox to ensure that the this passed to
// addDebuggerToGlobal is a global.
let sandbox = Cu.Sandbox(principal, {});
Cu.evalInSandbox(
"Components.utils.import('resource://gre/modules/jsdebugger.jsm');" +
"addDebuggerToGlobal(this);",
sandbox
);
const Debugger = sandbox.Debugger;
const Timer = Cu.import("resource://gre/modules/Timer.jsm", {});
const xpcInspector = Cc["@mozilla.org/jsinspector;1"].
getService(Ci.nsIJSInspector);
this.worker = new WorkerDebuggerLoader({
createSandbox: createSandbox,
globals: {
"isWorker": true,
"Debugger": Debugger,
"setInterval": Timer.setInterval,
"setTimeout": Timer.setTimeout,
"clearInterval": Timer.clearInterval,
"clearTimeout": Timer.clearTimeout,
"xpcInspector": xpcInspector,
"reportError": Cu.reportError,
},
loadInSandbox: loadInSandbox,
modules: {
"Services": {},
"chrome": chrome,
},
paths: {
"": "resource://gre/modules/commonjs/",
"devtools": "resource:///modules/devtools",
"devtools/server": "resource://gre/modules/devtools/server",
"devtools/toolkit": "resource://gre/modules/devtools",
"source-map": "resource://gre/modules/devtools/source-map",
"xpcshell-test": "resource://test",
}
});
}