зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1574040 - Generalize the Debugger's worker redux management. r=loganfsmyth
Differential Revision: https://phabricator.services.mozilla.com/D42238 --HG-- rename : devtools/client/debugger/src/utils/workers.js => devtools/client/debugger/src/utils/threads.js extra : moz-landing-system : lando
This commit is contained in:
Родитель
6becef12e3
Коммит
f88768528b
|
@ -8,33 +8,33 @@ import { differenceBy } from "lodash";
|
|||
import type { Action, ThunkArgs } from "./types";
|
||||
import { removeSourceActors } from "./source-actors";
|
||||
|
||||
import { getContext, getWorkers, getSourceActorsForThread } from "../selectors";
|
||||
import { getContext, getThreads, getSourceActorsForThread } from "../selectors";
|
||||
|
||||
export function updateWorkers() {
|
||||
export function updateThreads() {
|
||||
return async function({ dispatch, getState, client }: ThunkArgs) {
|
||||
const cx = getContext(getState());
|
||||
const workers = await client.fetchWorkers();
|
||||
const threads = await client.fetchThreads();
|
||||
|
||||
const currentWorkers = getWorkers(getState());
|
||||
const currentThreads = getThreads(getState());
|
||||
|
||||
const addedWorkers = differenceBy(workers, currentWorkers, w => w.actor);
|
||||
const removedWorkers = differenceBy(currentWorkers, workers, w => w.actor);
|
||||
if (removedWorkers.length > 0) {
|
||||
const addedThreads = differenceBy(threads, currentThreads, w => w.actor);
|
||||
const removedThreads = differenceBy(currentThreads, threads, w => w.actor);
|
||||
if (removedThreads.length > 0) {
|
||||
const sourceActors = getSourceActorsForThread(
|
||||
getState(),
|
||||
removedWorkers.map(w => w.actor)
|
||||
removedThreads.map(w => w.actor)
|
||||
);
|
||||
dispatch(removeSourceActors(sourceActors));
|
||||
dispatch(
|
||||
({
|
||||
type: "REMOVE_WORKERS",
|
||||
type: "REMOVE_THREADS",
|
||||
cx,
|
||||
workers: removedWorkers.map(w => w.actor),
|
||||
threads: removedThreads.map(w => w.actor),
|
||||
}: Action)
|
||||
);
|
||||
}
|
||||
if (addedWorkers.length > 0) {
|
||||
dispatch(({ type: "INSERT_WORKERS", cx, workers: addedWorkers }: Action));
|
||||
if (addedThreads.length > 0) {
|
||||
dispatch(({ type: "INSERT_THREADS", cx, threads: addedThreads }: Action));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import { clearDocuments } from "../utils/editor";
|
||||
import sourceQueue from "../utils/source-queue";
|
||||
|
||||
import { updateWorkers } from "./debuggee";
|
||||
import { updateThreads } from "./debuggee";
|
||||
|
||||
import { clearWasmStates } from "../utils/wasm";
|
||||
import { getMainThread } from "../selectors";
|
||||
|
@ -52,7 +52,7 @@ export function connect(
|
|||
isWebExtension: boolean
|
||||
) {
|
||||
return async function({ dispatch }: ThunkArgs) {
|
||||
await dispatch(updateWorkers());
|
||||
await dispatch(updateThreads());
|
||||
dispatch(
|
||||
({
|
||||
type: "CONNECT",
|
||||
|
|
|
@ -35,7 +35,7 @@ const threadFront = {
|
|||
describe("navigation", () => {
|
||||
it("connect sets the debuggeeUrl", async () => {
|
||||
const { dispatch, getState } = createStore({
|
||||
fetchWorkers: () => Promise.resolve([]),
|
||||
fetchThreads: () => Promise.resolve([]),
|
||||
getMainThread: () => "FakeThread",
|
||||
});
|
||||
await dispatch(
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// @flow
|
||||
|
||||
import typeof SourceMaps from "devtools-source-map";
|
||||
import type { WorkerList, MainThread, Context, ThreadId } from "../../types";
|
||||
import type { ThreadList, Thread, Context, ThreadId } from "../../types";
|
||||
import type { State } from "../../reducers/types";
|
||||
import type { MatchedLocations } from "../../reducers/file-search";
|
||||
import type { TreeNode } from "../../utils/sources-tree/types";
|
||||
|
@ -74,11 +74,11 @@ type UpdateTabAction = {|
|
|||
type NavigateAction =
|
||||
| {|
|
||||
+type: "CONNECT",
|
||||
+mainThread: MainThread,
|
||||
+mainThread: Thread,
|
||||
+canRewind: boolean,
|
||||
+isWebExtension: boolean,
|
||||
|}
|
||||
| {| +type: "NAVIGATE", +mainThread: MainThread |};
|
||||
| {| +type: "NAVIGATE", +mainThread: Thread |};
|
||||
|
||||
export type FocusItem = TreeNode;
|
||||
|
||||
|
@ -136,14 +136,14 @@ export type QuickOpenAction =
|
|||
|
||||
export type DebuggeeAction =
|
||||
| {|
|
||||
+type: "INSERT_WORKERS",
|
||||
+type: "INSERT_THREADS",
|
||||
+cx: Context,
|
||||
+workers: WorkerList,
|
||||
+threads: ThreadList,
|
||||
|}
|
||||
| {|
|
||||
+type: "REMOVE_WORKERS",
|
||||
+type: "REMOVE_THREADS",
|
||||
+cx: Context,
|
||||
+workers: Array<ThreadId>,
|
||||
+threads: Array<ThreadId>,
|
||||
|}
|
||||
| {|
|
||||
+type: "SELECT_THREAD",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
// @flow
|
||||
|
||||
import { prepareSourcePayload, createTarget } from "./create";
|
||||
import { prepareSourcePayload, createThread } from "./create";
|
||||
import { updateTargets } from "./targets";
|
||||
|
||||
import Reps from "devtools-reps";
|
||||
|
@ -405,7 +405,7 @@ function getSourceForActor(actor: ActorId) {
|
|||
return sourceActors[actor];
|
||||
}
|
||||
|
||||
async function fetchWorkers(): Promise<Worker[]> {
|
||||
async function fetchThreads(): Promise<Worker[]> {
|
||||
const options = {
|
||||
breakpoints,
|
||||
eventBreakpoints,
|
||||
|
@ -431,7 +431,7 @@ async function fetchWorkers(): Promise<Worker[]> {
|
|||
}
|
||||
|
||||
targets = newTargets;
|
||||
return Object.keys(targets).map(id => createTarget(id, targets[id]));
|
||||
return Object.keys(targets).map(id => createThread(id, targets[id]));
|
||||
}
|
||||
|
||||
function getMainThread() {
|
||||
|
@ -506,7 +506,7 @@ const clientCommands = {
|
|||
pauseOnExceptions,
|
||||
fetchSources,
|
||||
registerSourceActor,
|
||||
fetchWorkers,
|
||||
fetchThreads,
|
||||
getMainThread,
|
||||
sendPacket,
|
||||
setSkipPausing,
|
||||
|
|
|
@ -73,7 +73,7 @@ export function createPause(
|
|||
};
|
||||
}
|
||||
|
||||
export function createTarget(actor: string, target: Target): Worker {
|
||||
export function createThread(actor: string, target: Target): Worker {
|
||||
return {
|
||||
actor,
|
||||
url: target.url || "",
|
||||
|
|
|
@ -93,7 +93,7 @@ function newSource(threadFront: ThreadFront, { source }: SourcePacket) {
|
|||
}
|
||||
|
||||
function workerListChanged() {
|
||||
actions.updateWorkers();
|
||||
actions.updateThreads();
|
||||
}
|
||||
|
||||
const clientEvents = {
|
||||
|
|
|
@ -186,7 +186,7 @@ export type Actions = {
|
|||
resumed: ActorId => void,
|
||||
newQueuedSources: (QueuedSourceData[]) => void,
|
||||
fetchEventListeners: () => void,
|
||||
updateWorkers: () => void,
|
||||
updateThreads: () => void,
|
||||
};
|
||||
|
||||
type ConsoleClient = {
|
||||
|
|
|
@ -11,7 +11,7 @@ import { showMenu } from "devtools-contextmenu";
|
|||
|
||||
import SourceIcon from "../shared/SourceIcon";
|
||||
import AccessibleImage from "../shared/AccessibleImage";
|
||||
import { getDisplayName, isWorker } from "../../utils/workers";
|
||||
import { getDisplayName, isWorker } from "../../utils/threads";
|
||||
|
||||
import {
|
||||
getGeneratedSourceByURL,
|
||||
|
@ -36,13 +36,7 @@ import { features } from "../../utils/prefs";
|
|||
import { downloadFile } from "../../utils/utils";
|
||||
|
||||
import type { TreeNode } from "../../utils/sources-tree/types";
|
||||
import type {
|
||||
Source,
|
||||
Context,
|
||||
MainThread,
|
||||
Thread,
|
||||
SourceContent,
|
||||
} from "../../types";
|
||||
import type { Source, Context, Thread, SourceContent } from "../../types";
|
||||
|
||||
type Props = {
|
||||
autoExpand: ?boolean,
|
||||
|
@ -57,7 +51,7 @@ type Props = {
|
|||
focused: boolean,
|
||||
expanded: boolean,
|
||||
threads: Thread[],
|
||||
mainThread: MainThread,
|
||||
mainThread: Thread,
|
||||
hasMatchingGeneratedSource: boolean,
|
||||
hasSiblingOfSameName: boolean,
|
||||
hasPrettySource: boolean,
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
getActiveSearch,
|
||||
getProjectDirectoryRoot,
|
||||
getSelectedPrimaryPaneTab,
|
||||
getThreads,
|
||||
getAllThreads,
|
||||
getContext,
|
||||
} from "../../selectors";
|
||||
import { features, prefs } from "../../utils/prefs";
|
||||
|
@ -168,7 +168,7 @@ const mapStateToProps = state => ({
|
|||
selectedTab: getSelectedPrimaryPaneTab(state),
|
||||
sources: getDisplayedSources(state),
|
||||
sourceSearchOn: getActiveSearch(state) === "source",
|
||||
threads: getThreads(state),
|
||||
threads: getAllThreads(state),
|
||||
projectRoot: getProjectDirectoryRoot(state),
|
||||
});
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import classnames from "classnames";
|
|||
|
||||
import actions from "../../actions";
|
||||
import { getCurrentThread, getIsPaused, getContext } from "../../selectors";
|
||||
import { getDisplayName, isWorker } from "../../utils/workers";
|
||||
import { getDisplayName, isWorker } from "../../utils/threads";
|
||||
import AccessibleImage from "../shared/AccessibleImage";
|
||||
|
||||
import type { Context, Thread } from "../../types";
|
||||
|
|
|
@ -8,8 +8,8 @@ import React, { Component } from "react";
|
|||
import { connect } from "../../utils/connect";
|
||||
|
||||
import actions from "../../actions";
|
||||
import { getThreads } from "../../selectors";
|
||||
import { getDisplayName } from "../../utils/workers";
|
||||
import { getAllThreads } from "../../selectors";
|
||||
import { getDisplayName } from "../../utils/threads";
|
||||
import { features } from "../../utils/prefs";
|
||||
import Worker from "./Worker";
|
||||
import AccessibleImage from "../shared/AccessibleImage";
|
||||
|
@ -55,7 +55,7 @@ export class Workers extends Component<Props> {
|
|||
}
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
threads: getThreads(state),
|
||||
threads: getAllThreads(state),
|
||||
});
|
||||
|
||||
export default connect(
|
||||
|
|
|
@ -21,7 +21,7 @@ import {
|
|||
getSelectedFrame,
|
||||
getShouldPauseOnExceptions,
|
||||
getShouldPauseOnCaughtExceptions,
|
||||
getWorkers,
|
||||
getThreads,
|
||||
getCurrentThread,
|
||||
getThreadContext,
|
||||
getSourceFromId,
|
||||
|
@ -50,7 +50,7 @@ import "./SecondaryPanes.css";
|
|||
import type {
|
||||
Expression,
|
||||
Frame,
|
||||
WorkerList,
|
||||
ThreadList,
|
||||
ThreadContext,
|
||||
Source,
|
||||
} from "../../types";
|
||||
|
@ -95,7 +95,7 @@ type Props = {
|
|||
mapScopesEnabled: boolean,
|
||||
shouldPauseOnExceptions: boolean,
|
||||
shouldPauseOnCaughtExceptions: boolean,
|
||||
workers: WorkerList,
|
||||
workers: ThreadList,
|
||||
source: ?Source,
|
||||
toggleShortcutsModal: () => void,
|
||||
toggleAllBreakpoints: typeof actions.toggleAllBreakpoints,
|
||||
|
@ -531,7 +531,7 @@ const mapStateToProps = state => {
|
|||
mapScopesEnabled: isMapScopesEnabled(state),
|
||||
shouldPauseOnExceptions: getShouldPauseOnExceptions(state),
|
||||
shouldPauseOnCaughtExceptions: getShouldPauseOnCaughtExceptions(state),
|
||||
workers: getWorkers(state),
|
||||
workers: getThreads(state),
|
||||
source:
|
||||
selectedFrame && getSourceFromId(state, selectedFrame.location.sourceId),
|
||||
};
|
||||
|
|
|
@ -12,21 +12,21 @@
|
|||
import { sortBy } from "lodash";
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
import { getDisplayName } from "../utils/workers";
|
||||
import { getDisplayName } from "../utils/threads";
|
||||
|
||||
import type { Selector, State } from "./types";
|
||||
import type { MainThread, WorkerList, Thread } from "../types";
|
||||
import type { Thread, ThreadList } from "../types";
|
||||
import type { Action } from "../actions/types";
|
||||
|
||||
export type DebuggeeState = {
|
||||
workers: WorkerList,
|
||||
mainThread: MainThread,
|
||||
threads: ThreadList,
|
||||
mainThread: Thread,
|
||||
isWebExtension: boolean,
|
||||
};
|
||||
|
||||
export function initialDebuggeeState(): DebuggeeState {
|
||||
return {
|
||||
workers: [],
|
||||
threads: [],
|
||||
mainThread: { actor: "", url: "", type: -1, name: "" },
|
||||
isWebExtension: false,
|
||||
};
|
||||
|
@ -43,13 +43,13 @@ export default function debuggee(
|
|||
mainThread: { ...action.mainThread, name: L10N.getStr("mainThread") },
|
||||
isWebExtension: action.isWebExtension,
|
||||
};
|
||||
case "INSERT_WORKERS":
|
||||
return insertWorkers(state, action.workers);
|
||||
case "REMOVE_WORKERS":
|
||||
const { workers } = action;
|
||||
case "INSERT_THREADS":
|
||||
return insertThreads(state, action.threads);
|
||||
case "REMOVE_THREADS":
|
||||
const { threads } = action;
|
||||
return {
|
||||
...state,
|
||||
workers: state.workers.filter(w => !workers.includes(w.actor)),
|
||||
threads: state.threads.filter(w => !threads.includes(w.actor)),
|
||||
};
|
||||
case "NAVIGATE":
|
||||
return {
|
||||
|
@ -61,27 +61,27 @@ export default function debuggee(
|
|||
}
|
||||
}
|
||||
|
||||
function insertWorkers(state, workers) {
|
||||
const formatedWorkers = workers.map(worker => ({
|
||||
...worker,
|
||||
name: getDisplayName(worker),
|
||||
function insertThreads(state, threads) {
|
||||
const formatedThreads = threads.map(thread => ({
|
||||
...thread,
|
||||
name: getDisplayName(thread),
|
||||
}));
|
||||
|
||||
return {
|
||||
...state,
|
||||
workers: [...state.workers, ...formatedWorkers],
|
||||
threads: [...state.threads, ...formatedThreads],
|
||||
};
|
||||
}
|
||||
|
||||
export const getWorkers = (state: OuterState) => state.debuggee.workers;
|
||||
export const getThreads = (state: OuterState) => state.debuggee.threads;
|
||||
|
||||
export const getWorkerCount = (state: OuterState) => getWorkers(state).length;
|
||||
export const getWorkerCount = (state: OuterState) => getThreads(state).length;
|
||||
|
||||
export function getWorkerByThread(state: OuterState, thread: string) {
|
||||
return getWorkers(state).find(worker => worker.actor == thread);
|
||||
return getThreads(state).find(worker => worker.actor == thread);
|
||||
}
|
||||
|
||||
export function getMainThread(state: OuterState): MainThread {
|
||||
export function getMainThread(state: OuterState): Thread {
|
||||
return state.debuggee.mainThread;
|
||||
}
|
||||
|
||||
|
@ -89,16 +89,16 @@ export function getDebuggeeUrl(state: OuterState): string {
|
|||
return getMainThread(state).url;
|
||||
}
|
||||
|
||||
export const getThreads: Selector<Thread[]> = createSelector(
|
||||
export const getAllThreads: Selector<Thread[]> = createSelector(
|
||||
getMainThread,
|
||||
getWorkers,
|
||||
(mainThread, workers) => [mainThread, ...sortBy(workers, getDisplayName)]
|
||||
getThreads,
|
||||
(mainThread, threads) => [mainThread, ...sortBy(threads, getDisplayName)]
|
||||
);
|
||||
|
||||
// checks if a path begins with a thread actor
|
||||
// e.g "server1.conn0.child1/workerTarget22/context1/dbg-workers.glitch.me"
|
||||
export function startsWithThreadActor(state: State, path: string) {
|
||||
const threadActors = getThreads(state).map(t => t.actor);
|
||||
const threadActors = getAllThreads(state).map(t => t.actor);
|
||||
|
||||
const match = path.match(new RegExp(`(${threadActors.join("|")})\/(.*)`));
|
||||
return match && match[1];
|
||||
|
|
|
@ -234,7 +234,7 @@ const queryThreadsBySourceObject: ReduceAllQuery<
|
|||
}, {})
|
||||
);
|
||||
|
||||
export function getThreadsBySource(
|
||||
export function getAllThreadsBySource(
|
||||
state: SourceActorOuterState
|
||||
): { [SourceId]: Array<ThreadId> } {
|
||||
return queryThreadsBySourceObject(state.sourceActors);
|
||||
|
|
|
@ -46,7 +46,7 @@ import {
|
|||
hasSourceActor,
|
||||
getSourceActor,
|
||||
getSourceActors,
|
||||
getThreadsBySource,
|
||||
getAllThreadsBySource,
|
||||
getBreakableLinesForSourceActors,
|
||||
type SourceActorId,
|
||||
type SourceActorOuterState,
|
||||
|
@ -851,7 +851,7 @@ type GetDisplayedSourceIDsSelector = (
|
|||
OuterState & SourceActorOuterState & DebuggeeOuterState
|
||||
) => { [ThreadId]: Set<SourceId> };
|
||||
const getDisplayedSourceIDs: GetDisplayedSourceIDsSelector = createSelector(
|
||||
getThreadsBySource,
|
||||
getAllThreadsBySource,
|
||||
getAllDisplayedSources,
|
||||
(threadsBySource, displayedSources) => {
|
||||
const sourceIDsByThread = {};
|
||||
|
|
|
@ -461,23 +461,15 @@ export type Scope = {|
|
|||
scopeKind: string,
|
||||
|};
|
||||
|
||||
export type MainThread = {
|
||||
export type Thread = {
|
||||
+actor: ThreadId,
|
||||
+url: string,
|
||||
+type: number,
|
||||
+name: string,
|
||||
};
|
||||
|
||||
export type Worker = {
|
||||
+actor: ThreadId,
|
||||
+url: string,
|
||||
+type: number,
|
||||
+name: string,
|
||||
};
|
||||
|
||||
export type Thread = MainThread & Worker;
|
||||
// export type Worker = Thread;
|
||||
export type ThreadList = Array<Thread>;
|
||||
export type WorkerList = Array<Worker>;
|
||||
|
||||
export type Cancellable = {
|
||||
cancel: () => void,
|
||||
|
|
|
@ -49,10 +49,10 @@ CompiledModules(
|
|||
'telemetry.js',
|
||||
'text.js',
|
||||
'timings.js',
|
||||
'threads.js',
|
||||
'ui.js',
|
||||
'url.js',
|
||||
'utils.js',
|
||||
'wasm.js',
|
||||
'worker.js',
|
||||
'workers.js',
|
||||
)
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
"findAllElements": false,
|
||||
"getIsPaused": false,
|
||||
"getThreadContext": false,
|
||||
"getWorkers": false,
|
||||
"getThreads": false,
|
||||
"openNewTabAndToolbox": false,
|
||||
"selectLocation": false,
|
||||
"stepOver": false,
|
||||
|
|
|
@ -42,7 +42,7 @@ add_task(async function() {
|
|||
const dbg = await initDebugger("doc-windowless-workers.html");
|
||||
const mainThread = dbg.toolbox.threadFront.actor;
|
||||
|
||||
const workers = await getWorkers(dbg);
|
||||
const workers = await getThreads(dbg);
|
||||
ok(workers.length == 2, "Got two workers");
|
||||
const thread1 = workers[0].actor;
|
||||
const thread2 = workers[1].actor;
|
||||
|
|
|
@ -423,9 +423,9 @@ function assertPausedAtSourceAndLine(dbg, expectedSourceId, expectedLine) {
|
|||
}
|
||||
|
||||
// Get any workers associated with the debugger.
|
||||
async function getWorkers(dbg) {
|
||||
await dbg.actions.updateWorkers();
|
||||
return dbg.selectors.getWorkers();
|
||||
async function getThreads(dbg) {
|
||||
await dbg.actions.updateThreads();
|
||||
return dbg.selectors.getThreads();
|
||||
}
|
||||
|
||||
async function waitForLoadedScopes(dbg) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче