Bug 1473578 - Remove deprecated synchronous DebuggerServer.registerModule feature. r=jryans

MozReview-Commit-ID: DTAEJyfICNz

--HG--
extra : rebase_source : 043241ac68dd00f24236e9583dc262bce4d208b7
This commit is contained in:
Alexandre Poirot 2018-07-05 07:13:52 -07:00
Родитель 7d9ee61570
Коммит aece1534ef
24 изменённых файлов: 99 добавлений и 190 удалений

Просмотреть файл

@ -70,7 +70,7 @@ exports.sendShutdownEvent = sendShutdownEvent;
* * @param connection DebuggerServerConnection
* The conection to the client.
*/
function createRootActor(connection) {
exports.createRootActor = function createRootActor(connection) {
return new RootActor(connection, {
tabList: new BrowserTabList(connection),
addonList: new BrowserAddonList(connection),
@ -81,7 +81,7 @@ function createRootActor(connection) {
globalActorFactories: DebuggerServer.globalActorFactories,
onShutdown: sendShutdownEvent
});
}
};
/**
* A live list of FrameTargetActorProxys representing the current browser tabs,
@ -757,11 +757,3 @@ BrowserAddonList.prototype._adjustListener = function() {
};
exports.BrowserAddonList = BrowserAddonList;
exports.register = function(handle) {
handle.setRootActor(createRootActor);
};
exports.unregister = function(handle) {
handle.setRootActor(null);
};

Просмотреть файл

@ -61,61 +61,6 @@ loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
var gRegisteredModules = Object.create(null);
/**
* The ModuleAPI object is passed to modules loaded using the
* DebuggerServer.registerModule() API. Modules can use this
* object to register actor factories.
* Factories registered through the module API will be removed
* when the module is unregistered or when the server is
* destroyed.
*/
function ModuleAPI() {
let activeTargetScopedActors = new Set();
let activeGlobalActors = new Set();
return {
// See DebuggerServer.setRootActor for a description.
setRootActor(factory) {
DebuggerServer.setRootActor(factory);
},
// See DebuggerServer.addGlobalActor for a description.
addGlobalActor(factory, name) {
DebuggerServer.addGlobalActor(factory, name);
activeGlobalActors.add(factory);
},
// See DebuggerServer.removeGlobalActor for a description.
removeGlobalActor(factory) {
DebuggerServer.removeGlobalActor(factory);
activeGlobalActors.delete(factory);
},
// See DebuggerServer.addTargetScopedActor for a description.
addTargetScopedActor(factory, name) {
DebuggerServer.addTargetScopedActor(factory, name);
activeTargetScopedActors.add(factory);
},
// See DebuggerServer.removeTargetScopedActor for a description.
removeTargetScopedActor(factory) {
DebuggerServer.removeTargetScopedActor(factory);
activeTargetScopedActors.delete(factory);
},
// Destroy the module API object, unregistering any
// factories registered by the module.
destroy() {
for (const factory of activeTargetScopedActors) {
DebuggerServer.removeTargetScopedActor(factory);
}
activeTargetScopedActors = null;
for (const factory of activeGlobalActors) {
DebuggerServer.removeGlobalActor(factory);
}
activeGlobalActors = null;
}
};
}
/**
* Public API
*/
@ -151,7 +96,7 @@ var DebuggerServer = {
* actor registered on DebuggerServer.
*/
get rootlessServer() {
return !this.isModuleRegistered("devtools/server/actors/webbrowser");
return !this.createRootActor;
},
/**
@ -239,7 +184,8 @@ var DebuggerServer = {
}
if (root) {
this.registerModule("devtools/server/actors/webbrowser");
const { createRootActor } = require("devtools/server/actors/webbrowser");
this.setRootActor(createRootActor);
}
if (target) {
@ -269,16 +215,11 @@ var DebuggerServer = {
/**
* Register a CommonJS module with the debugger server.
* @param id string
* The ID of a CommonJS module. This module must export 'register'
* and 'unregister' functions if no `options` argument is given.
* If `options` is set, the actor is going to be registered
* immediately, but loaded only when a client starts sending packets
* to an actor with the same id.
* The ID of a CommonJS module.
* The actor is going to be registered immediately, but loaded only
* when a client starts sending packets to an actor with the same id.
*
* @param options object (optional)
* This parameter is still optional, but not providing it is
* deprecated and will result in eagerly loading the actor module
* with the memory overhead that entails.
* @param options object
* An object with 3 mandatory attributes:
* - prefix (string):
* The prefix of an actor is used to compute:
@ -306,46 +247,37 @@ var DebuggerServer = {
return;
}
if (options) {
// Lazy loaded actors
const {prefix, constructor, type} = options;
if (typeof (prefix) !== "string") {
throw new Error(`Lazy actor definition for '${id}' requires a string ` +
`'prefix' option.`);
}
if (typeof (constructor) !== "string") {
throw new Error(`Lazy actor definition for '${id}' requires a string ` +
`'constructor' option.`);
}
if (!("global" in type) && !("target" in type)) {
throw new Error(`Lazy actor definition for '${id}' requires a dictionary ` +
`'type' option whose attributes can be 'global' or 'target'.`);
}
const name = prefix + "Actor";
const mod = {
id: id,
prefix: prefix,
constructorName: constructor,
type: type,
globalActor: type.global,
targetScopedActor: type.target
};
gRegisteredModules[id] = mod;
if (mod.targetScopedActor) {
this.addTargetScopedActor(mod, name);
}
if (mod.globalActor) {
this.addGlobalActor(mod, name);
}
} else {
// Deprecated actors being loaded at startup
const moduleAPI = ModuleAPI();
const mod = require(id);
mod.register(moduleAPI);
gRegisteredModules[id] = {
module: mod,
api: moduleAPI
};
if (!options) {
throw new Error("DebuggerServer.registerModule requires an options argument");
}
const {prefix, constructor, type} = options;
if (typeof (prefix) !== "string") {
throw new Error(`Lazy actor definition for '${id}' requires a string ` +
`'prefix' option.`);
}
if (typeof (constructor) !== "string") {
throw new Error(`Lazy actor definition for '${id}' requires a string ` +
`'constructor' option.`);
}
if (!("global" in type) && !("target" in type)) {
throw new Error(`Lazy actor definition for '${id}' requires a dictionary ` +
`'type' option whose attributes can be 'global' or 'target'.`);
}
const name = prefix + "Actor";
const mod = {
id,
prefix,
constructorName: constructor,
type,
globalActor: type.global,
targetScopedActor: type.target
};
gRegisteredModules[id] = mod;
if (mod.targetScopedActor) {
this.addTargetScopedActor(mod, name);
}
if (mod.globalActor) {
this.addGlobalActor(mod, name);
}
},
@ -373,12 +305,6 @@ var DebuggerServer = {
this.removeGlobalActor(mod);
}
if (mod.module) {
// Deprecated non-lazy module API
mod.module.unregister(mod.api);
mod.api.destroy();
}
delete gRegisteredModules[id];
},

Просмотреть файл

@ -398,7 +398,14 @@ function attachTestTabAndResume(client, title, callback = () => {}) {
* Initialize the testing debugger server.
*/
function initTestDebuggerServer(server = DebuggerServer) {
server.registerModule("xpcshell-test/testactors");
if (server === WorkerDebuggerServer) {
const { createRootActor } = worker.require("xpcshell-test/testactors");
server.setRootActor(createRootActor);
} else {
const { createRootActor } = require("xpcshell-test/testactors");
server.setRootActor(createRootActor);
}
// Allow incoming connections.
server.init(function() {
return true;

Просмотреть файл

@ -28,7 +28,8 @@ function run_test() {
/this is undefined/,
"closeAllListeners should throw if createRootActor hasn't been added");
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
// Now they should work.
DebuggerServer.createListener();

Просмотреть файл

@ -4,7 +4,8 @@ var SOURCE_URL = getFileUrl("setBreakpoint-on-column.js");
async function run_test() {
do_test_pending();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
const global = createTestGlobal("test");
DebuggerServer.addTestGlobal(global);

Просмотреть файл

@ -5,7 +5,8 @@ var SOURCE_URL = getFileUrl("setBreakpoint-on-column.js");
async function run_test() {
do_test_pending();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
const global = createTestGlobal("test");

Просмотреть файл

@ -10,7 +10,8 @@ function run_test() {
loadSubScriptWithOptions(SOURCE_URL, {target: global, ignoreCache: true});
Cu.forceGC(); Cu.forceGC(); Cu.forceGC();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
DebuggerServer.addTestGlobal(global);
const client = new DebuggerClient(DebuggerServer.connectPipe());

Просмотреть файл

@ -6,7 +6,8 @@ function run_test() {
return (async function() {
do_test_pending();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
const global = createTestGlobal("test");

Просмотреть файл

@ -10,7 +10,8 @@ function run_test() {
loadSubScriptWithOptions(SOURCE_URL, {target: global, ignoreCache: true});
Cu.forceGC(); Cu.forceGC(); Cu.forceGC();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
DebuggerServer.addTestGlobal(global);
const client = new DebuggerClient(DebuggerServer.connectPipe());

Просмотреть файл

@ -6,7 +6,8 @@ function run_test() {
return (async function() {
do_test_pending();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
const global = createTestGlobal("test");

Просмотреть файл

@ -6,7 +6,8 @@ function run_test() {
return (async function() {
do_test_pending();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
const global = createTestGlobal("test");

Просмотреть файл

@ -10,7 +10,8 @@ function run_test() {
loadSubScriptWithOptions(SOURCE_URL, {target: global, ignoreCache: true});
Cu.forceGC(); Cu.forceGC(); Cu.forceGC();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
DebuggerServer.addTestGlobal(global);

Просмотреть файл

@ -6,7 +6,8 @@ function run_test() {
return (async function() {
do_test_pending();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
const global = createTestGlobal("test");

Просмотреть файл

@ -6,7 +6,8 @@ function run_test() {
return (async function() {
do_test_pending();
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init(() => true);
const global = createTestGlobal("test");

Просмотреть файл

@ -62,7 +62,7 @@ TestTabList.prototype = {
}
};
function createRootActor(connection) {
exports.createRootActor = function createRootActor(connection) {
const root = new RootActor(connection, {
tabList: new TestTabList(connection),
globalActorFactories: DebuggerServer.globalActorFactories,
@ -70,7 +70,7 @@ function createRootActor(connection) {
root.applicationType = "xpcshell-tests";
return root;
}
};
function TestTargetActor(connection, global) {
this.conn = connection;
@ -165,11 +165,3 @@ TestTargetActor.prototype.requestTypes = {
"detach": TestTargetActor.prototype.onDetach,
"reload": TestTargetActor.prototype.onReload
};
exports.register = function(handle) {
handle.setRootActor(createRootActor);
};
exports.unregister = function(handle) {
handle.setRootActor(null);
};

Просмотреть файл

@ -82,6 +82,7 @@ Services.console.registerListener(listener);
* Initialize the testing debugger server.
*/
function initTestDebuggerServer() {
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.init();
}

Просмотреть файл

@ -52,14 +52,14 @@ TestTabList.prototype = {
}
};
function createRootActor(connection) {
exports.createRootActor = function createRootActor(connection) {
const root = new RootActor(connection, {
tabList: new TestTabList(connection),
globalActorFactories: DebuggerServer.globalActorFactories
});
root.applicationType = "xpcshell-tests";
return root;
}
};
function TestTargetActor(connection, global) {
this.conn = connection;
@ -123,11 +123,3 @@ TestTargetActor.prototype.requestTypes = {
"attach": TestTargetActor.prototype.onAttach,
"detach": TestTargetActor.prototype.onDetach
};
exports.register = function(handle) {
handle.setRootActor(createRootActor);
};
exports.unregister = function(handle) {
handle.setRootActor(null);
};

Просмотреть файл

@ -96,7 +96,8 @@ function initTestDebuggerServer() {
constructor: "ScriptActor",
type: { global: true, target: true }
});
DebuggerServer.registerModule("xpcshell-test/testactors");
const { createRootActor } = require("xpcshell-test/testactors");
DebuggerServer.setRootActor(createRootActor);
// Allow incoming connections.
DebuggerServer.init();
}

Просмотреть файл

@ -4,7 +4,8 @@
"use strict";
function run_test() {
DebuggerServer.registerModule("xpcshell-test/testactors-no-bulk");
const { createRootActor } = require("xpcshell-test/testactors-no-bulk");
DebuggerServer.setRootActor(createRootActor);
// Allow incoming connections.
DebuggerServer.init();

Просмотреть файл

@ -8,7 +8,7 @@ const { DebuggerServer } = require("devtools/server/main");
/**
* Root actor that doesn't have the bulk trait.
*/
function createRootActor(connection) {
exports.createRootActor = function createRootActor(connection) {
const root = new RootActor(connection, {
globalActorFactories: DebuggerServer.globalActorFactories
});
@ -17,12 +17,4 @@ function createRootActor(connection) {
bulk: false
};
return root;
}
exports.register = function(handle) {
handle.setRootActor(createRootActor);
};
exports.unregister = function(handle) {
handle.setRootActor(null);
};

Просмотреть файл

@ -51,14 +51,14 @@ TestTabList.prototype = {
}
};
function createRootActor(connection) {
exports.createRootActor = function createRootActor(connection) {
const root = new RootActor(connection, {
tabList: new TestTabList(connection),
globalActorFactories: DebuggerServer.globalActorFactories
});
root.applicationType = "xpcshell-tests";
return root;
}
};
function TestTargetActor(connection, global) {
this.conn = connection;
@ -122,11 +122,3 @@ TestTargetActor.prototype.requestTypes = {
"attach": TestTargetActor.prototype.onAttach,
"detach": TestTargetActor.prototype.onDetach
};
exports.register = function(handle) {
handle.setRootActor(createRootActor);
};
exports.unregister = function(handle) {
handle.setRootActor(null);
};

Просмотреть файл

@ -5,8 +5,12 @@
/* globals DebuggerServer */
"use strict";
XPCOMUtils.defineLazyGetter(this, "DebuggerServer", () => {
XPCOMUtils.defineLazyGetter(this, "require", () => {
let { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
return require;
});
XPCOMUtils.defineLazyGetter(this, "DebuggerServer", () => {
let { DebuggerServer } = require("devtools/server/main");
return DebuggerServer;
});
@ -201,7 +205,8 @@ var RemoteDebugger = {
// Add browser and Fennec specific actors
DebuggerServer.registerAllActors();
DebuggerServer.registerModule("resource://gre/modules/dbg-browser-actors.js");
const { createRootActor } = require("resource://gre/modules/dbg-browser-actors.js");
DebuggerServer.setRootActor(createRootActor);
// Allow debugging of chrome for any process
DebuggerServer.allowChromeProcess = true;

Просмотреть файл

@ -26,7 +26,7 @@ const { BrowserTabList, BrowserAddonList, sendShutdownEvent } =
* * @param aConnection DebuggerServerConnection
* The conection to the client.
*/
function createRootActor(aConnection) {
exports.createRootActor = function createRootActor(aConnection) {
let parameters = {
tabList: new MobileTabList(aConnection),
addonList: new BrowserAddonList(aConnection),
@ -34,7 +34,7 @@ function createRootActor(aConnection) {
onShutdown: sendShutdownEvent
};
return new RootActor(aConnection, parameters);
}
};
/**
* A live list of BrowserTabActors representing the current browser tabs,
@ -67,11 +67,3 @@ MobileTabList.prototype._getSelectedBrowser = function(aWindow) {
MobileTabList.prototype._getChildren = function(aWindow) {
return aWindow.BrowserApp.tabs.map(tab => tab.browser);
};
exports.register = function(handle) {
handle.setRootActor(createRootActor);
};
exports.unregister = function(handle) {
handle.setRootActor(null);
};

Просмотреть файл

@ -13,8 +13,12 @@ XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",
});
XPCOMUtils.defineLazyGetter(this, "DebuggerServer", () => {
XPCOMUtils.defineLazyGetter(this, "require", () => {
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
return require;
});
XPCOMUtils.defineLazyGetter(this, "DebuggerServer", () => {
const { DebuggerServer } = require("devtools/server/main");
return DebuggerServer;
});
@ -48,7 +52,8 @@ var GeckoViewRemoteDebugger = {
debug `onEnable`;
DebuggerServer.init();
DebuggerServer.registerAllActors();
DebuggerServer.registerModule("resource://gre/modules/dbg-browser-actors.js");
const { createRootActor } = require("resource://gre/modules/dbg-browser-actors.js");
DebuggerServer.setRootActor(createRootActor);
DebuggerServer.allowChromeProcess = true;
DebuggerServer.chromeWindowType = "navigator:geckoview";