Bug 1592730 - Make target updates async friendly, r=jlast.

Differential Revision: https://phabricator.services.mozilla.com/D51158

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brian Hackett 2019-10-31 13:44:20 +00:00
Родитель b6039daa64
Коммит d3809112ad
2 изменённых файлов: 49 добавлений и 54 удалений

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

@ -479,7 +479,9 @@ async function updateThreads(type: ThreadType) {
observeAsmJS: true,
};
const newTargets = await updateTargets(type, {
const oldActors = Object.keys(targets[type]);
await updateTargets(type, {
currentTarget,
debuggerClient,
targets,
@ -490,17 +492,15 @@ async function updateThreads(type: ThreadType) {
// NOTE: This runs in the background and fails quitely because it is
// pretty easy for sources to throw during the fetch if their thread
// shuts down, which would cause test failures.
for (const actor in newTargets) {
if (!targets[type][actor]) {
const { threadFront } = newTargets[actor];
for (const entry of Object.entries(targets[type])) {
const [actor, { threadFront }] = (entry: any);
if (!oldActors.includes(actor)) {
getSources(threadFront).catch(e => console.error(e));
}
}
targets = { ...targets, [type]: newTargets };
return Object.keys(newTargets).map(actor =>
createThread(actor, newTargets[actor])
return Object.entries(targets[type]).map(([actor, target]) =>
createThread((actor: any), (target: any))
);
}

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

@ -20,66 +20,63 @@ type Args = {
};
async function attachTargets(type, targetLists, args) {
const newTargets = {};
const targets = args.targets[type] || {};
const { targets } = args;
for (const actor of Object.keys(targets[type])) {
if (!targetLists.some(target => target.targetForm.threadActor == actor)) {
delete targets[type][actor];
}
}
for (const targetFront of targetLists) {
try {
await targetFront.attach();
const threadActorID = targetFront.targetForm.threadActor;
if (targets[threadActorID]) {
newTargets[threadActorID] = targets[threadActorID];
} else {
// Content process targets have already been attached by the toolbox.
// And the thread front has been initialized from there.
// So we only need to retrieve it here.
let threadFront = targetFront.threadFront;
// But workers targets are still only managed by the debugger codebase
// and so we have to attach their thread actor
if (!threadFront) {
[, threadFront] = await targetFront.attachThread({
...defaultThreadOptions(),
...args.options,
});
// NOTE: resume is not necessary for ProcessDescriptors and can be removed
// once we switch to WorkerDescriptors
threadFront.resume();
}
addThreadEventListeners(threadFront);
newTargets[threadFront.actor] = targetFront;
if (targets[type][threadActorID]) {
continue;
}
targets[type][threadActorID] = targetFront;
// Content process targets have already been attached by the toolbox.
// And the thread front has been initialized from there.
// So we only need to retrieve it here.
let threadFront = targetFront.threadFront;
// But workers targets are still only managed by the debugger codebase
// and so we have to attach their thread actor
if (!threadFront) {
[, threadFront] = await targetFront.attachThread({
...defaultThreadOptions(),
...args.options,
});
// NOTE: resume is not necessary for ProcessDescriptors and can be removed
// once we switch to WorkerDescriptors
threadFront.resume();
}
addThreadEventListeners(threadFront);
} catch (e) {
// If any of the workers have terminated since the list command initiated
// then we will get errors. Ignore these.
}
}
return newTargets;
}
export async function updateWorkerTargets(
type: ThreadType,
args: Args
): Promise<{ string: Target }> {
export async function updateWorkerTargets(type: ThreadType, args: Args) {
const { currentTarget } = args;
if (!currentTarget.isBrowsingContext || currentTarget.isContentProcess) {
return {};
return;
}
const { workers } = await currentTarget.listWorkers();
return attachTargets(type, workers, args);
await attachTargets(type, workers, args);
}
export async function updateProcessTargets(
type: ThreadType,
args: Args
): Promise<{ string: Target }> {
export async function updateProcessTargets(type: ThreadType, args: Args) {
const { currentTarget, debuggerClient } = args;
if (!prefs.fission || !currentTarget.chrome || currentTarget.isAddon) {
return Promise.resolve({});
return;
}
const { processes } = await debuggerClient.mainRoot.listProcesses();
@ -89,17 +86,15 @@ export async function updateProcessTargets(
.map(descriptor => descriptor.getTarget())
);
return attachTargets(type, targets, args);
await attachTargets(type, targets, args);
}
export async function updateTargets(type: ThreadType, args: Args) {
if (type == "worker") {
return updateWorkerTargets(type, args);
await updateWorkerTargets(type, args);
} else if (type == "contentProcess") {
await updateProcessTargets(type, args);
} else {
throw new Error(`Unable to fetch targts for ${type}`);
}
if (type == "contentProcess") {
return updateProcessTargets(type, args);
}
throw new Error(`Unable to fetch targts for ${type}`);
}