Backed out changeset b0ad994d07d0 (bug 1574040) for debugger failures.

--HG--
rename : devtools/client/debugger/src/utils/threads.js => devtools/client/debugger/src/utils/workers.js
This commit is contained in:
Cosmin Sabou 2019-08-20 03:41:14 +03:00
Родитель 780679ebf7
Коммит 1426dda56b
22 изменённых файлов: 90 добавлений и 76 удалений

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

@ -8,33 +8,33 @@ import { differenceBy } from "lodash";
import type { Action, ThunkArgs } from "./types";
import { removeSourceActors } from "./source-actors";
import { getContext, getThreads, getSourceActorsForThread } from "../selectors";
import { getContext, getWorkers, getSourceActorsForThread } from "../selectors";
export function updateThreads() {
export function updateWorkers() {
return async function({ dispatch, getState, client }: ThunkArgs) {
const cx = getContext(getState());
const threads = await client.fetchThreads();
const workers = await client.fetchWorkers();
const currentThreads = getThreads(getState());
const currentWorkers = getWorkers(getState());
const addedThreads = differenceBy(threads, currentThreads, w => w.actor);
const removedThreads = differenceBy(currentThreads, threads, w => w.actor);
if (removedThreads.length > 0) {
const addedWorkers = differenceBy(workers, currentWorkers, w => w.actor);
const removedWorkers = differenceBy(currentWorkers, workers, w => w.actor);
if (removedWorkers.length > 0) {
const sourceActors = getSourceActorsForThread(
getState(),
removedThreads.map(w => w.actor)
removedWorkers.map(w => w.actor)
);
dispatch(removeSourceActors(sourceActors));
dispatch(
({
type: "REMOVE_THREADS",
type: "REMOVE_WORKERS",
cx,
threads: removedThreads.map(w => w.actor),
workers: removedWorkers.map(w => w.actor),
}: Action)
);
}
if (addedThreads.length > 0) {
dispatch(({ type: "INSERT_THREADS", cx, threads: addedThreads }: Action));
if (addedWorkers.length > 0) {
dispatch(({ type: "INSERT_WORKERS", cx, workers: addedWorkers }: Action));
}
};
}

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

@ -7,7 +7,7 @@
import { clearDocuments } from "../utils/editor";
import sourceQueue from "../utils/source-queue";
import { updateThreads } from "./debuggee";
import { updateWorkers } 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(updateThreads());
await dispatch(updateWorkers());
dispatch(
({
type: "CONNECT",

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

@ -35,7 +35,7 @@ const threadFront = {
describe("navigation", () => {
it("connect sets the debuggeeUrl", async () => {
const { dispatch, getState } = createStore({
fetchThreads: () => Promise.resolve([]),
fetchWorkers: () => Promise.resolve([]),
getMainThread: () => "FakeThread",
});
await dispatch(

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

@ -5,7 +5,7 @@
// @flow
import typeof SourceMaps from "devtools-source-map";
import type { ThreadList, Thread, Context, ThreadId } from "../../types";
import type { WorkerList, MainThread, 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: Thread,
+mainThread: MainThread,
+canRewind: boolean,
+isWebExtension: boolean,
|}
| {| +type: "NAVIGATE", +mainThread: Thread |};
| {| +type: "NAVIGATE", +mainThread: MainThread |};
export type FocusItem = TreeNode;
@ -136,14 +136,14 @@ export type QuickOpenAction =
export type DebuggeeAction =
| {|
+type: "INSERT_THREADS",
+type: "INSERT_WORKERS",
+cx: Context,
+threads: ThreadList,
+workers: WorkerList,
|}
| {|
+type: "REMOVE_THREADS",
+type: "REMOVE_WORKERS",
+cx: Context,
+threads: Array<ThreadId>,
+workers: Array<ThreadId>,
|}
| {|
+type: "SELECT_THREAD",

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

@ -4,7 +4,7 @@
// @flow
import { prepareSourcePayload, createThread } from "./create";
import { prepareSourcePayload, createTarget } from "./create";
import { updateTargets } from "./targets";
import Reps from "devtools-reps";
@ -405,7 +405,7 @@ function getSourceForActor(actor: ActorId) {
return sourceActors[actor];
}
async function fetchThreads(): Promise<Worker[]> {
async function fetchWorkers(): Promise<Worker[]> {
const options = {
breakpoints,
eventBreakpoints,
@ -431,7 +431,7 @@ async function fetchThreads(): Promise<Worker[]> {
}
targets = newTargets;
return Object.keys(targets).map(id => createThread(id, targets[id]));
return Object.keys(targets).map(id => createTarget(id, targets[id]));
}
function getMainThread() {
@ -506,7 +506,7 @@ const clientCommands = {
pauseOnExceptions,
fetchSources,
registerSourceActor,
fetchThreads,
fetchWorkers,
getMainThread,
sendPacket,
setSkipPausing,

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

@ -73,7 +73,7 @@ export function createPause(
};
}
export function createThread(actor: string, target: Target): Worker {
export function createTarget(actor: string, target: Target): Worker {
return {
actor,
url: target.url || "",

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

@ -93,7 +93,7 @@ function newSource(threadFront: ThreadFront, { source }: SourcePacket) {
}
function workerListChanged() {
actions.updateThreads();
actions.updateWorkers();
}
const clientEvents = {

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

@ -186,7 +186,7 @@ export type Actions = {
resumed: ActorId => void,
newQueuedSources: (QueuedSourceData[]) => void,
fetchEventListeners: () => void,
updateThreads: () => void,
updateWorkers: () => 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/threads";
import { getDisplayName, isWorker } from "../../utils/workers";
import {
getGeneratedSourceByURL,
@ -36,7 +36,13 @@ import { features } from "../../utils/prefs";
import { downloadFile } from "../../utils/utils";
import type { TreeNode } from "../../utils/sources-tree/types";
import type { Source, Context, Thread, SourceContent } from "../../types";
import type {
Source,
Context,
MainThread,
Thread,
SourceContent,
} from "../../types";
type Props = {
autoExpand: ?boolean,
@ -51,7 +57,7 @@ type Props = {
focused: boolean,
expanded: boolean,
threads: Thread[],
mainThread: Thread,
mainThread: MainThread,
hasMatchingGeneratedSource: boolean,
hasSiblingOfSameName: boolean,
hasPrettySource: boolean,

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

@ -14,7 +14,7 @@ import {
getActiveSearch,
getProjectDirectoryRoot,
getSelectedPrimaryPaneTab,
getAllThreads,
getThreads,
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: getAllThreads(state),
threads: getThreads(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/threads";
import { getDisplayName, isWorker } from "../../utils/workers";
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 { getAllThreads } from "../../selectors";
import { getDisplayName } from "../../utils/threads";
import { getThreads } from "../../selectors";
import { getDisplayName } from "../../utils/workers";
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: getAllThreads(state),
threads: getThreads(state),
});
export default connect(

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

@ -21,7 +21,7 @@ import {
getSelectedFrame,
getShouldPauseOnExceptions,
getShouldPauseOnCaughtExceptions,
getThreads,
getWorkers,
getCurrentThread,
getThreadContext,
getSourceFromId,
@ -50,7 +50,7 @@ import "./SecondaryPanes.css";
import type {
Expression,
Frame,
ThreadList,
WorkerList,
ThreadContext,
Source,
} from "../../types";
@ -95,7 +95,7 @@ type Props = {
mapScopesEnabled: boolean,
shouldPauseOnExceptions: boolean,
shouldPauseOnCaughtExceptions: boolean,
workers: ThreadList,
workers: WorkerList,
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: getThreads(state),
workers: getWorkers(state),
source:
selectedFrame && getSourceFromId(state, selectedFrame.location.sourceId),
};

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

@ -12,21 +12,21 @@
import { sortBy } from "lodash";
import { createSelector } from "reselect";
import { getDisplayName } from "../utils/threads";
import { getDisplayName } from "../utils/workers";
import type { Selector, State } from "./types";
import type { Thread, ThreadList } from "../types";
import type { MainThread, WorkerList, Thread } from "../types";
import type { Action } from "../actions/types";
export type DebuggeeState = {
threads: ThreadList,
mainThread: Thread,
workers: WorkerList,
mainThread: MainThread,
isWebExtension: boolean,
};
export function initialDebuggeeState(): DebuggeeState {
return {
threads: [],
workers: [],
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_THREADS":
return insertThreads(state, action.threads);
case "REMOVE_THREADS":
const { threads } = action;
case "INSERT_WORKERS":
return insertWorkers(state, action.workers);
case "REMOVE_WORKERS":
const { workers } = action;
return {
...state,
threads: state.threads.filter(w => !threads.includes(w.actor)),
workers: state.workers.filter(w => !workers.includes(w.actor)),
};
case "NAVIGATE":
return {
@ -61,27 +61,27 @@ export default function debuggee(
}
}
function insertThreads(state, threads) {
const formatedThreads = threads.map(thread => ({
...thread,
name: getDisplayName(thread),
function insertWorkers(state, workers) {
const formatedWorkers = workers.map(worker => ({
...worker,
name: getDisplayName(worker),
}));
return {
...state,
threads: [...state.threads, ...formatedThreads],
workers: [...state.workers, ...formatedWorkers],
};
}
export const getThreads = (state: OuterState) => state.debuggee.threads;
export const getWorkers = (state: OuterState) => state.debuggee.workers;
export const getWorkerCount = (state: OuterState) => getThreads(state).length;
export const getWorkerCount = (state: OuterState) => getWorkers(state).length;
export function getWorkerByThread(state: OuterState, thread: string) {
return getThreads(state).find(worker => worker.actor == thread);
return getWorkers(state).find(worker => worker.actor == thread);
}
export function getMainThread(state: OuterState): Thread {
export function getMainThread(state: OuterState): MainThread {
return state.debuggee.mainThread;
}
@ -89,16 +89,16 @@ export function getDebuggeeUrl(state: OuterState): string {
return getMainThread(state).url;
}
export const getAllThreads: Selector<Thread[]> = createSelector(
export const getThreads: Selector<Thread[]> = createSelector(
getMainThread,
getThreads,
(mainThread, threads) => [mainThread, ...sortBy(threads, getDisplayName)]
getWorkers,
(mainThread, workers) => [mainThread, ...sortBy(workers, 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 = getAllThreads(state).map(t => t.actor);
const threadActors = getThreads(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 getAllThreadsBySource(
export function getThreadsBySource(
state: SourceActorOuterState
): { [SourceId]: Array<ThreadId> } {
return queryThreadsBySourceObject(state.sourceActors);

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

@ -46,7 +46,7 @@ import {
hasSourceActor,
getSourceActor,
getSourceActors,
getAllThreadsBySource,
getThreadsBySource,
getBreakableLinesForSourceActors,
type SourceActorId,
type SourceActorOuterState,
@ -851,7 +851,7 @@ type GetDisplayedSourceIDsSelector = (
OuterState & SourceActorOuterState & DebuggeeOuterState
) => { [ThreadId]: Set<SourceId> };
const getDisplayedSourceIDs: GetDisplayedSourceIDsSelector = createSelector(
getAllThreadsBySource,
getThreadsBySource,
getAllDisplayedSources,
(threadsBySource, displayedSources) => {
const sourceIDsByThread = {};

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

@ -461,15 +461,23 @@ export type Scope = {|
scopeKind: string,
|};
export type Thread = {
export type MainThread = {
+actor: ThreadId,
+url: string,
+type: number,
+name: string,
};
// export type Worker = Thread;
export type Worker = {
+actor: ThreadId,
+url: string,
+type: number,
+name: string,
};
export type Thread = MainThread & Worker;
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,
"getThreads": false,
"getWorkers": 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 getThreads(dbg);
const workers = await getWorkers(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 getThreads(dbg) {
await dbg.actions.updateThreads();
return dbg.selectors.getThreads();
async function getWorkers(dbg) {
await dbg.actions.updateWorkers();
return dbg.selectors.getWorkers();
}
async function waitForLoadedScopes(dbg) {