Backed out changeset b7cdb0cf84b6 (bug 1785277) for causing devtools failures on browser_dbg-quick-open.js. CLOSED TREE

This commit is contained in:
Marian Laza 2022-10-19 10:43:20 +03:00
Родитель 745c699b4d
Коммит 00f993530e
31 изменённых файлов: 273 добавлений и 464 удалений

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

@ -233,12 +233,7 @@ class DebuggerPanel {
// select worker's source
const source = this.getSourceByURL(workerDescriptorFront._url);
const sourceActor = this._selectors.getFirstSourceActorForGeneratedSource(
this._getState(),
source.id,
threadActorID
);
await this.selectSource(source.id, sourceActor.actor, 1, 1);
await this.selectSource(source.id, 1, 1);
}
selectThread(threadActorID) {
@ -246,11 +241,11 @@ class DebuggerPanel {
this._actions.selectThread(cx, threadActorID);
}
async selectSource(sourceId, sourceActorId, line, column) {
async selectSource(sourceId, line, column) {
const cx = this._selectors.getContext(this._getState());
const location = { sourceId, line, column };
await this._actions.selectSource(cx, sourceId, sourceActorId, location);
await this._actions.selectSource(cx, sourceId, location);
if (this._selectors.hasLogpoint(this._getState(), location)) {
this._actions.openConditionalPanel(location, true);
}

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

@ -0,0 +1,110 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
import {
actions,
selectors,
createStore,
makeSource,
waitForState,
} from "../../../utils/test-head";
import { createSource } from "../../tests/helpers/mockCommandClient";
describe("breakpointPositions", () => {
it("fetches positions", async () => {
const fooContent = createSource("foo", "");
const store = createStore({
getSourceActorBreakpointPositions: async () => ({ "9": [1] }),
getSourceActorBreakableLines: async () => [],
sourceContents: async () => fooContent,
});
const { dispatch, getState, cx } = store;
const source = await dispatch(
actions.newGeneratedSource(makeSource("foo"))
);
await dispatch(actions.loadSourceById(cx, source.id));
dispatch(actions.setBreakpointPositions({ cx, sourceId: "foo", line: 9 }));
await waitForState(store, state =>
selectors.hasBreakpointPositions(state, "foo")
);
expect(
selectors.getBreakpointPositionsForSource(getState(), "foo")
).toEqual({
[9]: [
{
location: {
line: 9,
column: 1,
sourceId: "foo",
sourceUrl: "http://localhost:8000/examples/foo",
},
generatedLocation: {
line: 9,
column: 1,
sourceId: "foo",
sourceUrl: "http://localhost:8000/examples/foo",
},
},
],
});
});
it("doesn't re-fetch positions", async () => {
const fooContent = createSource("foo", "");
let resolve = _ => {};
let count = 0;
const store = createStore({
getSourceActorBreakpointPositions: () =>
new Promise(r => {
count++;
resolve = r;
}),
getSourceActorBreakableLines: async () => [],
sourceContents: async () => fooContent,
});
const { dispatch, getState, cx } = store;
const source = await dispatch(
actions.newGeneratedSource(makeSource("foo"))
);
await dispatch(actions.loadSourceById(cx, source.id));
dispatch(actions.setBreakpointPositions({ cx, sourceId: "foo", line: 9 }));
dispatch(actions.setBreakpointPositions({ cx, sourceId: "foo", line: 9 }));
resolve({ "9": [1] });
await waitForState(store, state =>
selectors.hasBreakpointPositions(state, "foo")
);
expect(
selectors.getBreakpointPositionsForSource(getState(), "foo")
).toEqual({
[9]: [
{
location: {
line: 9,
column: 1,
sourceId: "foo",
sourceUrl: "http://localhost:8000/examples/foo",
},
generatedLocation: {
line: 9,
column: 1,
sourceId: "foo",
sourceUrl: "http://localhost:8000/examples/foo",
},
},
],
});
expect(count).toEqual(1);
});
});

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

@ -50,8 +50,9 @@ describe("breakpoints", () => {
};
const source = await dispatch(actions.newGeneratedSource(makeSource("a")));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(
actions.selectLocation(cx, {
actions.setSelectedLocation(cx, source, {
line: 1,
column: 1,
sourceId: source.id,
@ -78,8 +79,9 @@ describe("breakpoints", () => {
sourceUrl: "http://localhost:8000/examples/a",
};
const source = await dispatch(actions.newGeneratedSource(makeSource("a")));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(
actions.selectLocation(cx, {
actions.setSelectedLocation(cx, source, {
line: 1,
column: 1,
sourceId: source.id,
@ -103,8 +105,9 @@ describe("breakpoints", () => {
sourceUrl: "http://localhost:8000/examples/a",
};
const source = await dispatch(actions.newGeneratedSource(makeSource("a")));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(
actions.selectLocation(cx, {
actions.setSelectedLocation(cx, source, {
line: 1,
column: 1,
sourceId: source.id,
@ -135,8 +138,9 @@ describe("breakpoints", () => {
};
const source = await dispatch(actions.newGeneratedSource(makeSource("a")));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(
actions.selectLocation(cx, {
actions.setSelectedLocation(cx, source, {
line: 1,
column: 1,
sourceId: source.id,
@ -172,19 +176,13 @@ describe("breakpoints", () => {
};
const aSource = await dispatch(actions.newGeneratedSource(makeSource("a")));
await dispatch(actions.loadSourceText({ cx, source: aSource }));
const bSource = await dispatch(actions.newGeneratedSource(makeSource("b")));
const bSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
bSource.id
);
await dispatch(actions.loadSourceText({ cx, source: bSource }));
await dispatch(
actions.loadSourceText({ cx, source: bSource, sourceActor: bSourceActor })
);
await dispatch(
actions.selectLocation(cx, {
actions.setSelectedLocation(cx, aSource, {
line: 1,
column: 1,
sourceId: aSource.id,
@ -223,22 +221,10 @@ describe("breakpoints", () => {
};
const aSource = await dispatch(actions.newGeneratedSource(makeSource("a")));
const aSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
aSource.id
);
await dispatch(
actions.loadSourceText({ cx, source: aSource, sourceActor: aSourceActor })
);
await dispatch(actions.loadSourceText({ cx, source: aSource }));
const bSource = await dispatch(actions.newGeneratedSource(makeSource("b")));
const bSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
bSource.id
);
await dispatch(
actions.loadSourceText({ cx, source: bSource, sourceActor: bSourceActor })
);
await dispatch(actions.loadSourceText({ cx, source: bSource }));
await dispatch(actions.addBreakpoint(cx, loc1));
await dispatch(actions.addBreakpoint(cx, loc2));
@ -266,13 +252,7 @@ describe("breakpoints", () => {
};
const aSource = await dispatch(actions.newGeneratedSource(makeSource("a")));
const aSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
aSource.id
);
await dispatch(
actions.loadSourceText({ cx, source: aSource, sourceActor: aSourceActor })
);
await dispatch(actions.loadSourceText({ cx, source: aSource }));
await dispatch(actions.addBreakpoint(cx, loc));
let bp = selectors.getBreakpoint(getState(), loc);
@ -315,22 +295,10 @@ describe("breakpoints", () => {
};
const aSource = await dispatch(actions.newGeneratedSource(makeSource("a")));
const aSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
aSource.id
);
await dispatch(
actions.loadSourceText({ cx, source: aSource, sourceActor: aSourceActor })
);
await dispatch(actions.loadSourceText({ cx, source: aSource }));
const bSource = await dispatch(actions.newGeneratedSource(makeSource("b")));
const bSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
bSource.id
);
await dispatch(
actions.loadSourceText({ cx, source: bSource, sourceActor: bSourceActor })
);
await dispatch(actions.loadSourceText({ cx, source: bSource }));
await dispatch(actions.addBreakpoint(cx, loc1));
await dispatch(actions.addBreakpoint(cx, loc2));
@ -398,22 +366,10 @@ describe("breakpoints", () => {
};
const aSource = await dispatch(actions.newGeneratedSource(makeSource("a")));
const aSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
aSource.id
);
await dispatch(
actions.loadSourceText({ cx, source: aSource, sourceActor: aSourceActor })
);
await dispatch(actions.loadSourceText({ cx, source: aSource }));
const bSource = await dispatch(actions.newGeneratedSource(makeSource("b")));
const bSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
bSource.id
);
await dispatch(
actions.loadSourceText({ cx, source: bSource, sourceActor: bSourceActor })
);
await dispatch(actions.loadSourceText({ cx, source: bSource }));
expect(selectors.getBreakpointsList(getState())).toHaveLength(0);
expect(selectors.getPendingBreakpointList(getState())).toHaveLength(1);
@ -441,7 +397,11 @@ describe("breakpoints", () => {
const { dispatch, getState, cx } = createStore(mockClient({ "5": [1] }));
await dispatch(actions.newGeneratedSource(makeSource("foo1")));
const source = await dispatch(
actions.newGeneratedSource(makeSource("foo1"))
);
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(actions.selectLocation(cx, loc));
await dispatch(actions.toggleBreakpointAtLine(cx, 5));
@ -458,7 +418,11 @@ describe("breakpoints", () => {
const { dispatch, getState, cx } = createStore(mockClient({ "5": [1] }));
await dispatch(actions.newGeneratedSource(makeSource("foo1")));
const source = await dispatch(
actions.newGeneratedSource(makeSource("foo1"))
);
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(actions.selectLocation(cx, { sourceId: "foo1", line: 1 }));
await dispatch(actions.toggleBreakpointAtLine(cx, 5));
@ -484,11 +448,7 @@ describe("breakpoints", () => {
};
const source = await dispatch(actions.newGeneratedSource(makeSource("a")));
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(actions.addBreakpoint(cx, loc));
@ -517,11 +477,7 @@ describe("breakpoints", () => {
};
const source = await dispatch(actions.newGeneratedSource(makeSource("a")));
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(actions.addBreakpoint(cx, loc));
let bp = selectors.getBreakpoint(getState(), loc);
@ -560,11 +516,7 @@ describe("breakpoints", () => {
const source = await dispatch(
actions.newGeneratedSource(makeSource("a.js"))
);
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(actions.addBreakpoint(cx, loc));
await dispatch(actions.togglePrettyPrint(cx, "a.js"));
@ -591,11 +543,7 @@ describe("breakpoints", () => {
const source = await dispatch(
actions.newGeneratedSource(makeSource("a.js"))
);
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(actions.addBreakpoint(cx, loc));
await dispatch(actions.togglePrettyPrint(cx, "a.js"));

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

@ -12,7 +12,6 @@ import {
getSelectedGeneratedScope,
getSelectedOriginalScope,
getThreadContext,
getFirstSourceActorForGeneratedSource,
} from "../../selectors";
import { loadSourceText } from "../sources/loadSourceText";
import { PROMISE } from "../utils/middleware/promise";
@ -150,22 +149,10 @@ export function getMappedScopes(cx, scopes, frame) {
return null;
}
// Load source text for the original source
await dispatch(loadSourceText({ cx, source, sourceActor: null }));
const generatedSourceActor = getFirstSourceActorForGeneratedSource(
getState(),
generatedSource.id
);
// Also load source text for its corresponding generated source
await dispatch(
loadSourceText({
cx,
source: generatedSource,
sourceActor: generatedSourceActor,
})
);
await dispatch(loadSourceText({ cx, source }));
if (source.isOriginal) {
await dispatch(loadSourceText({ cx, source: generatedSource }));
}
try {
const content =

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

@ -168,12 +168,7 @@ describe("pause", () => {
{
generatedLocation: { column: 0, line: 1, sourceId: "foo" },
id: mockFrameId,
location: {
column: 0,
line: 1,
sourceId: "foo",
sourceActorId: "foo-1-actor",
},
location: { column: 0, line: 1, sourceId: "foo" },
originalDisplayName: "foo",
scope: {
bindings: {
@ -245,12 +240,7 @@ describe("pause", () => {
{
generatedLocation: { column: 0, line: 1, sourceId: "foo" },
id: mockFrameId,
location: {
column: 0,
line: 3,
sourceActorId: "foo-original-1-actor",
sourceId: "foo-original",
},
location: { column: 0, line: 3, sourceId: "foo-original" },
originalDisplayName: "fooOriginal",
scope: { bindings: { arguments: [], variables: {} } },
thread: "FakeThread",
@ -322,12 +312,7 @@ describe("pause", () => {
id: "1",
index: undefined,
isOriginal: true,
location: {
column: 1,
line: 1,
sourceActorId: null,
sourceId: "foo-wasm/originalSource",
},
location: { column: 1, line: 1, sourceId: "foo-wasm/originalSource" },
originalDisplayName: "fooBar",
originalVariables: undefined,
scope: { bindings: { arguments: [], variables: {} } },

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

@ -11,7 +11,6 @@ import { isFulfilled } from "../utils/async-value";
import { findSourceMatches } from "../workers/search";
import {
getSource,
getFirstSourceActorForGeneratedSource,
hasPrettySource,
getSourceList,
getSourceContent,
@ -93,12 +92,7 @@ export function searchSources(cx, query) {
if (cancelled) {
return;
}
const sourceActor = getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(loadSourceText({ cx, source, sourceActor }));
await dispatch(loadSourceText({ cx, source }));
await dispatch(searchSource(cx, source.id, query));
}
dispatch(updateSearchStatus(cx, statusType.done));

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

@ -5,6 +5,7 @@
import { PROMISE } from "../utils/middleware/promise";
import {
getSource,
getSourceFromId,
getSourceTextContent,
getSourceContent,
getGeneratedSource,
@ -62,19 +63,27 @@ async function loadSource(
return result;
}
// If no source actor can be found then the text for the
// source cannot be loaded.
if (!sourceActor) {
throw new Error("Unknown source");
}
let response;
try {
telemetry.start(loadSourceHistogram, source);
response = await client.sourceContents(sourceActor);
telemetry.finish(loadSourceHistogram, source);
} catch (e) {
throw new Error(`sourceContents failed: ${e}`);
if (!sourceActor) {
// We only need the source text from one actor, but messages sent to retrieve
// the source might fail if the actor has or is about to shut down. Keep
// trying with different actors until one request succeeds.
const handledActors = new Set();
while (true) {
const actors = getSourceActorsForSource(state, source.id);
sourceActor = actors.find(({ actor: a }) => !handledActors.has(a));
if (!sourceActor) {
throw new Error("Unknown source");
}
handledActors.add(sourceActor.actor);
response = await fetchTextContent(client, source, sourceActor);
if (response) {
break;
}
}
} else {
response = await fetchTextContent(client, source, sourceActor);
}
return {
@ -84,6 +93,18 @@ async function loadSource(
};
}
async function fetchTextContent(client, source, sourceActor) {
let response;
try {
telemetry.start(loadSourceHistogram, source);
response = await client.sourceContents(sourceActor);
telemetry.finish(loadSourceHistogram, source);
} catch (e) {
console.warn(`sourceContents failed: ${e}`);
}
return response;
}
async function loadSourceTextPromise(
cx,
source,
@ -126,16 +147,13 @@ async function loadSourceTextPromise(
}
}
/**
* Loads the source text for a source and source actor
* @param {Object} source
* The source to load the source text
* @param {Object|null} sourceActor
* There can be more than one source actor per source
* so the source actor needs to be specified. This is
* required for generated sources but will be null for
* original/pretty printed sources.
*/
export function loadSourceById(cx, sourceId) {
return ({ getState, dispatch }) => {
const source = getSourceFromId(getState(), sourceId);
return dispatch(loadSourceText({ cx, source }));
};
}
export const loadSourceText = memoizeableAction("loadSourceText", {
getValue: ({ source, sourceActor }, { getState }) => {
if (!source) {
@ -147,7 +165,7 @@ export const loadSourceText = memoizeableAction("loadSourceText", {
return sourceTextContent;
}
// if a source actor is specified,lets also check that the source actor for the
// if a source actor is specified,lets check the source actor for the
// currently loaded text.
if (sourceActor && sourceTextContent && isFulfilled(sourceTextContent)) {
if (

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

@ -35,7 +35,6 @@ import {
getPendingBreakpointsForSource,
getContext,
getSourceTextContent,
getFirstSourceActorForGeneratedSource,
} from "../../selectors";
import { prefs } from "../../utils/prefs";
@ -173,11 +172,7 @@ function checkPendingBreakpoints(cx, sourceId) {
}
// load the source text if there is a pending breakpoint for it
const sourceActor = getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(loadSourceText({ cx, source, sourceActor }));
await dispatch(loadSourceText({ cx, source }));
await dispatch(setBreakableLines(cx, source.id));

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

@ -22,7 +22,6 @@ import { createPrettyPrintOriginalSource } from "../../client/firefox/create";
import {
getSource,
getFirstSourceActorForGeneratedSource,
getSourceFromId,
getSourceByURL,
getSelectedLocation,
@ -122,11 +121,8 @@ export function togglePrettyPrint(cx, sourceId) {
if (!source.isPrettyPrinted) {
recordEvent("pretty_print");
}
const sourceActor = getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(loadSourceText({ cx, source, sourceActor }));
await dispatch(loadSourceText({ cx, source }));
assert(
isGenerated(source),
"Pretty-printing only allowed on generated sources"
@ -146,7 +142,7 @@ export function togglePrettyPrint(cx, sourceId) {
const threadcx = getThreadContext(getState());
await dispatch(mapFrames(threadcx));
await dispatch(setSymbols({ cx, source: newPrettySource, sourceActor }));
await dispatch(setSymbols({ cx, source: newPrettySource }));
await dispatch(updateBreakpointsForNewPrettyPrintedSource(cx, sourceId));

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

@ -25,8 +25,6 @@ import { getRelatedMapLocation } from "../../utils/source-maps";
import {
getSource,
getSourceActor,
getFirstSourceActorForGeneratedSource,
getSourceByURL,
getPrettySource,
getActiveSearch,
@ -77,7 +75,8 @@ export function selectSourceURL(cx, url, options) {
return dispatch(setPendingSelectedLocation(cx, url, options));
}
const location = createLocation({ ...options, sourceId: source.id });
const sourceId = source.id;
const location = createLocation({ ...options, sourceId });
return dispatch(selectLocation(cx, location));
};
}
@ -90,16 +89,13 @@ export function selectSourceURL(cx, url, options) {
* @param {Object} cx
* @param {String} sourceId
* The precise source to select.
* @param {String} sourceActorId
* The specific source actor of the source to
* select the source text. This is optional.
* @param {Object} location
* Optional precise location to select, if we need to select
* a precise line/column.
*/
export function selectSource(cx, sourceId, sourceActorId, location = {}) {
export function selectSource(cx, sourceId, location = {}) {
return async ({ dispatch }) => {
location = createLocation({ ...location, sourceId, sourceActorId });
location = createLocation({ ...location, sourceId });
return dispatch(selectSpecificLocation(cx, location));
};
}
@ -168,19 +164,9 @@ export function selectLocation(cx, location, { keepContext = true } = {}) {
dispatch(addTab(source));
}
let sourceActor;
if (!location.sourceActorId) {
sourceActor = getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
location.sourceActorId = sourceActor ? sourceActor.actor : null;
} else {
sourceActor = getSourceActor(getState(), location.sourceActorId);
}
dispatch(setSelectedLocation(cx, source, location));
await dispatch(loadSourceText({ cx, source, sourceActor }));
await dispatch(loadSourceText({ cx, source }));
await dispatch(setBreakableLines(cx, source.id));
const loadedSource = getSource(getState(), source.id);
@ -203,7 +189,7 @@ export function selectLocation(cx, location, { keepContext = true } = {}) {
dispatch(closeTab(cx, loadedSource));
}
await dispatch(setSymbols({ cx, source: loadedSource, sourceActor }));
await dispatch(setSymbols({ cx, source: loadedSource }));
dispatch(setInScopeLines(cx));
if (getIsCurrentThreadPaused(getState())) {

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

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
import { getSymbols, getSourceActorForSymbols } from "../../selectors";
import { getSymbols } from "../../selectors";
import { PROMISE } from "../utils/middleware/promise";
import { loadSourceText } from "./loadSourceText";
@ -10,27 +10,21 @@ import { loadSourceText } from "./loadSourceText";
import { memoizeableAction } from "../../utils/memoizableAction";
import { fulfilled } from "../../utils/async-value";
async function doSetSymbols(
cx,
source,
sourceActor,
{ dispatch, getState, parser }
) {
async function doSetSymbols(cx, source, { dispatch, getState, parser }) {
const sourceId = source.id;
await dispatch(loadSourceText({ cx, source, sourceActor }));
await dispatch(loadSourceText({ cx, source }));
await dispatch({
type: "SET_SYMBOLS",
cx,
sourceId,
// sourceActor can be null for original and pretty-printed sources
sourceActorId: sourceActor ? sourceActor.actor : null,
[PROMISE]: parser.getSymbols(sourceId),
});
}
export const setSymbols = memoizeableAction("setSymbols", {
getValue: ({ source, sourceActor }, { getState }) => {
getValue: ({ source }, { getState }) => {
if (source.isWasm) {
return fulfilled(null);
}
@ -40,17 +34,8 @@ export const setSymbols = memoizeableAction("setSymbols", {
return null;
}
// Also check the spcific actor for the cached symbols
if (
sourceActor &&
getSourceActorForSymbols(getState(), source) !== sourceActor.actor
) {
return null;
}
return fulfilled(symbols);
},
createKey: ({ source }) => source.id,
action: ({ cx, source, sourceActor }, thunkArgs) =>
doSetSymbols(cx, source, sourceActor, thunkArgs),
action: ({ cx, source }, thunkArgs) => doSetSymbols(cx, source, thunkArgs),
});

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

@ -25,17 +25,7 @@ describe("loadSourceText", () => {
const foo1Source = await dispatch(
actions.newGeneratedSource(makeSource("foo1"))
);
const foo1SourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
foo1Source.id
);
await dispatch(
actions.loadSourceText({
cx,
source: foo1Source,
sourceActor: foo1SourceActor,
})
);
await dispatch(actions.loadSourceText({ cx, source: foo1Source }));
const foo1Content = selectors.getSourceContent(getState(), foo1Source.id);
expect(
@ -49,18 +39,7 @@ describe("loadSourceText", () => {
const foo2Source = await dispatch(
actions.newGeneratedSource(makeSource("foo2"))
);
const foo2SourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
foo2Source.id
);
await dispatch(
actions.loadSourceText({
cx,
source: foo2Source,
sourceActor: foo2SourceActor,
})
);
await dispatch(actions.loadSourceText({ cx, source: foo2Source }));
const foo2Content = selectors.getSourceContent(getState(), foo2Source.id);
expect(
@ -117,6 +96,30 @@ describe("loadSourceText", () => {
: -1
).not.toBe(-1);
// Load the source text which has been cached when the source
// actor is not specified.
await dispatch(
actions.loadSourceText({
cx,
source: testSource1,
})
);
const testSource1ContentAfterSecondLoad = selectors.getSourceContent(
getState(),
testSource1.id
);
expect(
testSource1ContentAfterSecondLoad &&
isFulfilled(testSource1ContentAfterSecondLoad) &&
testSource1ContentAfterSecondLoad.value.type === "text"
? testSource1ContentAfterSecondLoad.value.value.indexOf(
mockContents["testSource2-0-actor"]
)
: -1
).not.toBe(-1);
// Load the new source text when a different source actor is specified
await dispatch(
actions.loadSourceText({
@ -187,18 +190,7 @@ describe("loadSourceText", () => {
actions.newOriginalSource(makeOriginalSource(fooGenSource2))
);
const fooOrigSource1SourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
fooOrigSource1.id
);
await dispatch(
actions.loadSourceText({
cx,
source: fooOrigSource1,
sourceActor: fooOrigSource1SourceActor,
})
);
await dispatch(actions.loadSourceText({ cx, source: fooOrigSource1 }));
await dispatch(
actions.addBreakpoint(
@ -216,35 +208,13 @@ describe("loadSourceText", () => {
expect(breakpoint1.text).toBe("");
expect(breakpoint1.originalText).toBe("var fooOrig = 42;");
const fooGenSource1SourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
fooGenSource1.id
);
await dispatch(
actions.loadSourceText({
cx,
source: fooGenSource1,
sourceActor: fooGenSource1SourceActor,
})
);
await dispatch(actions.loadSourceText({ cx, source: fooGenSource1 }));
const breakpoint2 = getBreakpointsList(getState())[0];
expect(breakpoint2.text).toBe("var fooGen = 42;");
expect(breakpoint2.originalText).toBe("var fooOrig = 42;");
const fooGenSource2SourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
fooGenSource2.id
);
await dispatch(
actions.loadSourceText({
cx,
source: fooGenSource2,
sourceActor: fooGenSource2SourceActor,
})
);
await dispatch(actions.loadSourceText({ cx, source: fooGenSource2 }));
await dispatch(
actions.addBreakpoint(
@ -262,18 +232,7 @@ describe("loadSourceText", () => {
expect(breakpoint3.text).toBe("var fooGen = 42;");
expect(breakpoint3.originalText).toBe("");
const fooOrigSource2SourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
fooOrigSource2.id
);
await dispatch(
actions.loadSourceText({
cx,
source: fooOrigSource2,
sourceActor: fooOrigSource2SourceActor,
})
);
await dispatch(actions.loadSourceText({ cx, source: fooOrigSource2 }));
const breakpoint4 = getBreakpointsList(getState())[1];
expect(breakpoint4.text).toBe("var fooGen = 42;");
@ -297,21 +256,10 @@ describe("loadSourceText", () => {
await dispatch(actions.newGeneratedSource(makeSource(id)));
let source = selectors.getSourceFromId(getState(), id);
let sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
dispatch(actions.loadSourceText({ cx, source, sourceActor }));
dispatch(actions.loadSourceText({ cx, source }));
source = selectors.getSourceFromId(getState(), id);
sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
const loading = dispatch(
actions.loadSourceText({ cx, source, sourceActor })
);
const loading = dispatch(actions.loadSourceText({ cx, source }));
if (!resolve) {
throw new Error("no resolve");
@ -345,13 +293,7 @@ describe("loadSourceText", () => {
await dispatch(actions.newGeneratedSource(makeSource(id)));
let source = selectors.getSourceFromId(getState(), id);
let sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
const loading = dispatch(
actions.loadSourceText({ cx, source, sourceActor })
);
const loading = dispatch(actions.loadSourceText({ cx, source }));
if (!resolve) {
throw new Error("no resolve");
@ -360,11 +302,7 @@ describe("loadSourceText", () => {
await loading;
source = selectors.getSourceFromId(getState(), id);
sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
expect(count).toEqual(1);
const content = selectors.getSourceContent(getState(), id);
@ -382,24 +320,10 @@ describe("loadSourceText", () => {
const source = await dispatch(
actions.newGeneratedSource(makeSource("foo1"))
);
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
const prevSource = selectors.getSourceFromId(getState(), "foo1");
const prevSourceSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
prevSource.id
);
await dispatch(
actions.loadSourceText({
cx,
source: prevSource,
sourceActor: prevSourceSourceActor,
})
);
await dispatch(actions.loadSourceText({ cx, source: prevSource }));
const curSource = selectors.getSource(getState(), "foo1");
expect(prevSource === curSource).toBeTruthy();
@ -407,7 +331,7 @@ describe("loadSourceText", () => {
it("should indicate a loading source", async () => {
const store = createStore(mockCommandClient);
const { dispatch, cx, getState } = store;
const { dispatch, cx } = store;
const source = await dispatch(
actions.newGeneratedSource(makeSource("foo2"))
@ -416,11 +340,8 @@ describe("loadSourceText", () => {
const wasLoading = watchForState(store, state => {
return !selectors.getSourceContent(state, "foo2");
});
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
expect(wasLoading()).toBe(true);
});
@ -431,11 +352,7 @@ describe("loadSourceText", () => {
const source = await dispatch(
actions.newGeneratedSource(makeSource("bad-id"))
);
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
const badSource = selectors.getSource(getState(), "bad-id");
const content = badSource
@ -443,7 +360,7 @@ describe("loadSourceText", () => {
: null;
expect(
content && isRejected(content) && typeof content.value === "string"
? content.value.indexOf("sourceContents failed")
? content.value.indexOf("Unknown source")
: -1
).not.toBe(-1);
});

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

@ -18,11 +18,7 @@ describe("sources - pretty print", () => {
const url = "base.js";
const source = await dispatch(actions.newGeneratedSource(makeSource(url)));
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(createPrettySource(cx, source.id));
@ -49,12 +45,7 @@ describe("sources - pretty print", () => {
const source = await dispatch(
actions.newGeneratedSource(makeSource("foobar.js"))
);
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
await dispatch(actions.togglePrettyPrint(cx, source.id));
expect(selectors.getSourceCount(getState())).toEqual(2);

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

@ -1,5 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`preview queued previews (w/ the 1st finishing first) 1`] = `null`;
exports[`preview should generate previews 1`] = `null`;

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

@ -48,28 +48,10 @@ describe("ast", () => {
const base = await dispatch(
actions.newGeneratedSource(makeSource("base.js"))
);
const baseSourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
base.id
);
await dispatch(
actions.loadSourceText({
cx,
source: base,
sourceActor: baseSourceActor,
})
);
await dispatch(actions.loadSourceText({ cx, source: base }));
const loadedSource = selectors.getSourceFromId(getState(), base.id);
await dispatch(
actions.setSymbols({
cx,
source: loadedSource,
sourceActor: baseSourceActor,
})
);
await dispatch(actions.setSymbols({ cx, source: loadedSource }));
await waitForState(store, state => getSymbols(state, base));
const baseSymbols = getSymbols(getState(), base);

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

@ -81,14 +81,7 @@ describe("project text search", () => {
const source1 = await dispatch(
actions.newGeneratedSource(makeSource("bar"))
);
const sourceActor1 = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source1.id
);
await dispatch(
actions.loadSourceText({ cx, source: source1, sourceActor: sourceActor1 })
);
await dispatch(actions.loadSourceText({ cx, source: source1 }));
await dispatch(actions.togglePrettyPrint(cx, source1.id));
@ -104,12 +97,7 @@ describe("project text search", () => {
const source = await dispatch(
actions.newGeneratedSource(makeSource("bar"))
);
const sourceActor = selectors.getFirstSourceActorForGeneratedSource(
getState(),
source.id
);
await dispatch(actions.loadSourceText({ cx, source, sourceActor }));
await dispatch(actions.loadSourceText({ cx, source }));
dispatch(actions.addSearchQuery(cx, "bla"));

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

@ -244,7 +244,7 @@ function createSourceObject({
// True if WASM is enabled *and* the generated source is a WASM source
isWasm,
// True if this source is an HTML and relates to many sources actors,
// True is this source is an HTML and relates to many sources actors,
// one for each of its inline <script>
isHTML,

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

@ -15,7 +15,6 @@ import {
getGeneratedSourceByURL,
getContext,
getSourceContent,
getFirstSourceActorForGeneratedSource,
} from "../../selectors";
import actions from "../../actions";
@ -40,7 +39,6 @@ class SourceTreeItem extends Component {
hasMatchingGeneratedSource: PropTypes.bool.isRequired,
item: PropTypes.object.isRequired,
loadSourceText: PropTypes.func.isRequired,
getFirstSourceActorForGeneratedSource: PropTypes.func.isRequired,
projectRoot: PropTypes.string.isRequired,
selectSourceItem: PropTypes.func.isRequired,
setExpanded: PropTypes.func.isRequired,
@ -83,6 +81,7 @@ class SourceTreeItem extends Component {
const { item } = this.props;
if (item.type == "source") {
const { source } = item;
const copySourceUri2 = {
id: "node-menu-copy-source",
label: copySourceUri2Label,
@ -155,11 +154,7 @@ class SourceTreeItem extends Component {
}
if (!this.props.sourceContent) {
const sourceActor = this.props.getFirstSourceActorForGeneratedSource(
source.id,
source.thread
);
await this.props.loadSourceText({ cx, source, sourceActor });
await this.props.loadSourceText({ cx, source });
}
const data = this.props.sourceContent;
if (!data) {
@ -398,14 +393,10 @@ const mapStateToProps = (state, props) => {
cx: getContext(state),
hasMatchingGeneratedSource: getHasMatchingGeneratedSource(state, source),
sourceContent: getSourceContentValue(state, source),
getFirstSourceActorForGeneratedSource: (sourceId, threadId) =>
getFirstSourceActorForGeneratedSource(state, sourceId, threadId),
};
}
return {
cx: getContext(state),
getFirstSourceActorForGeneratedSource: (sourceId, threadId) =>
getFirstSourceActorForGeneratedSource(state, sourceId, threadId),
};
};

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

@ -11,9 +11,6 @@ import { makeBreakpointId } from "../utils/breakpoint";
export function initialASTState() {
return {
// Internal map of the source id to the specific source actor
// that loads the text for these symbols.
actors: {},
symbols: {},
inScopeLines: {},
};
@ -22,7 +19,7 @@ export function initialASTState() {
function update(state = initialASTState(), action) {
switch (action.type) {
case "SET_SYMBOLS": {
const { sourceId, sourceActorId } = action;
const { sourceId } = action;
if (action.status === "start") {
return state;
}
@ -30,7 +27,6 @@ function update(state = initialASTState(), action) {
const value = action.value;
return {
...state,
actors: { ...state.actors, [sourceId]: sourceActorId },
symbols: { ...state.symbols, [sourceId]: value },
};
}

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

@ -79,6 +79,7 @@ function updateSourceTextContent(state, action) {
}
state.mutableTextContentMap.set(action.sourceId, content);
return {
...state,
};

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

@ -12,14 +12,6 @@ export function getSymbols(state, source) {
return state.ast.symbols[source.id] || null;
}
export function getSourceActorForSymbols(state, source) {
if (!source) {
return null;
}
return state.ast.actors[source.id] || null;
}
export function getInScopeLines(state, location) {
return state.ast.inScopeLines[makeBreakpointId(location)];
}

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

@ -159,38 +159,6 @@ export function getSelectedSourceId(state) {
const source = getSelectedSource(state);
return source?.id;
}
/**
* Gets the first source actor for the source and/or thread
* provided.
*
* @param {Object} state
* @param {String} sourceId
* The source used
* @param {String} [threadId]
* The thread to check, this is optional.
* @param {Object} sourceActor
*
*/
export function getFirstSourceActorForGeneratedSource(
state,
sourceId,
threadId
) {
const source = getSource(state, sourceId);
if (source.isOriginal) {
return null;
}
let actorsInfo = state.sources.actors[sourceId];
if (!actorsInfo.length) {
return null;
}
if (threadId) {
actorsInfo = actorsInfo.filter(actorInfo => actorInfo.thread == threadId);
}
return actorsInfo.length ? getSourceActor(state, actorsInfo[0].id) : null;
}
/**
* Get the source actor of the source
*

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

@ -14,14 +14,12 @@ export function createLocation({
line = 0,
column,
sourceUrl = "",
sourceActorId = null,
}) {
return {
sourceId,
line,
column,
sourceUrl,
sourceActorId,
};
}

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

@ -357,13 +357,7 @@ add_task(async function testFailingHtmlSource() {
{ sourceId: source.id },
{ keepContext: false }
);
ok(
getCM(dbg)
.getValue()
.includes("Could not load the source"),
"Display failure error"
);
is(getCM(dbg).getValue(), `Error loading this URI: Unknown source`);
});
/**

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

@ -50,7 +50,7 @@ add_task(async function() {
{ sourceId: source.id },
{ keepContext: false }
);
is(getCM(dbg).getValue(), `Please refresh to debug this module`);
is(getCM(dbg).getValue(), `Error loading this URI: Unknown source`);
info("Reload and assert that WASM files are then debuggable");
await reload(dbg, "doc-wasm-sourcemaps.html", "fib.wasm", "fib.c");

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

@ -38,7 +38,7 @@ add_task(async function() {
await waitForGoToLineBoxFocus(dbg);
type(dbg, "66");
pressKey(dbg, "Enter");
await assertLine(dbg, 66);
assertLine(dbg, 66);
});
function assertEnabled(dbg) {
@ -53,9 +53,7 @@ async function waitForGoToLineBoxFocus(dbg) {
await waitFor(() => dbg.win.document.activeElement.tagName === "INPUT");
}
async function assertLine(dbg, lineNumber) {
// Wait for the line to be set
await waitUntil(() => !!dbg.selectors.getSelectedLocation().line);
function assertLine(dbg, lineNumber) {
is(
dbg.selectors.getSelectedLocation().line,
lineNumber,

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

@ -14,7 +14,7 @@ add_task(async function() {
const originalSource = getItems(dbg);
clickElement(dbg, "prettyPrintButton");
await waitForLoadedSource(dbg, "simple1.js:formatted");
await waitForSource(dbg, "simple1.js:formatted");
await waitForElementWithSelector(dbg, ".outline-list");
const prettySource = getItems(dbg);

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

@ -33,7 +33,6 @@ add_task(async function() {
info("Click an item in outline panel");
const item = getNthItem(dbg, 3);
item.click();
await waitForLoadedSource(dbg, "simple1.js");
assertHighlightLocation(dbg, "simple1.js", 15);
ok(
item.parentNode.classList.contains("focused"),

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

@ -90,7 +90,6 @@ add_task(async function() {
await quickOpen(dbg, ":7:12");
await waitForResults(dbg, [undefined, undefined]);
pressKey(dbg, "Enter");
await waitForSelectedSource(dbg, "script-switching-02.js");
assertLine(dbg, 7);
assertColumn(dbg, 12);

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

@ -15,15 +15,13 @@ add_task(async function() {
await selectSource(dbg, "simple1.js");
await selectSource(dbg, "simple2.js");
is(countTabs(dbg), 2, "Two tabs are open");
is(countTabs(dbg), 2);
pressKey(dbg, "close");
waitForDispatch(dbg.store, "CLOSE_TAB");
is(countTabs(dbg), 1, "One tab is open");
await waitForSelectedSource(dbg, "simple1.js");
is(countTabs(dbg), 1);
pressKey(dbg, "close");
waitForDispatch(dbg.store, "CLOSE_TAB");
is(countTabs(dbg), 0, "No tabs open");
is(countTabs(dbg), 0);
});

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

@ -133,7 +133,7 @@ exports.viewSourceInDebugger = async function(
const dbg = await toolbox.selectTool("jsdebugger", reason);
try {
await dbg.selectSource(id, sourceActorId, line, column);
await dbg.selectSource(id, line, column);
return true;
} catch (err) {
console.error("Failed to view source in debugger", err);