Bug 1745795 - [devtools] Avoid confusion between "reducer source" and "SourceFront" objects. r=bomsy

I'm also removing the `isBlackBoxed` boolean from source actor in the reducer
in order to ensure we always only use the source reducer one.

And I dropped some comment here and there to help understand where all these sources objects are coming from.

Differential Revision: https://phabricator.services.mozilla.com/D133658
This commit is contained in:
Alexandre Poirot 2021-12-15 16:11:23 +00:00
Родитель 03287165e3
Коммит c7d855b0b4
6 изменённых файлов: 44 добавлений и 44 удалений

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

@ -262,12 +262,14 @@ export function newOriginalSources(sourceInfo) {
};
}
// Wrapper around newGeneratedSources, only used by tests
export function newGeneratedSource(sourceInfo) {
return async ({ dispatch }) => {
const sources = await dispatch(newGeneratedSources([sourceInfo]));
return sources[0];
};
}
export function newGeneratedSources(sourceInfo) {
return async ({ dispatch, getState, client }) => {
if (sourceInfo.length == 0) {
@ -278,38 +280,42 @@ export function newGeneratedSources(sourceInfo) {
const newSourcesObj = {};
const newSourceActors = [];
for (const { thread, source, id } of sourceInfo) {
const newId = id || makeSourceId(source, thread);
// `sourceInfo` is an array of objects returned by `prepareSourceActorPayload` (in production)
// and `makeSource` (in jest tests)
for (const { thread, sourceFront, id } of sourceInfo) {
// Only jest test pass an `id` to avoid having to call makeSourceId.
// i.e. production code will always call makeSourceId.
const newId = id || makeSourceId(sourceFront, thread);
if (!getSource(getState(), newId) && !newSourcesObj[newId]) {
newSourcesObj[newId] = {
id: newId,
url: source.url,
relativeUrl: source.url,
url: sourceFront.url,
relativeUrl: sourceFront.url,
isPrettyPrinted: false,
extensionName: source.extensionName,
extensionName: sourceFront.extensionName,
isBlackBoxed: false,
isWasm: !!features.wasm && source.introductionType === "wasm",
isExtension: (source.url && isUrlExtension(source.url)) || false,
isWasm: !!features.wasm && sourceFront.introductionType === "wasm",
isExtension:
(sourceFront.url && isUrlExtension(sourceFront.url)) || false,
isOriginal: false,
};
}
const actorId = stringToSourceActorId(source.actor);
const actorId = stringToSourceActorId(sourceFront.actor);
// We are sometimes notified about a new source multiple times if we
// request a new source list and also get a source event from the server.
if (!hasSourceActor(getState(), actorId)) {
newSourceActors.push({
id: actorId,
actor: source.actor,
actor: sourceFront.actor,
thread,
source: newId,
isBlackBoxed: source.isBlackBoxed,
sourceMapBaseURL: source.sourceMapBaseURL,
sourceMapURL: source.sourceMapURL,
url: source.url,
introductionType: source.introductionType,
sourceMapBaseURL: sourceFront.sourceMapBaseURL,
sourceMapURL: sourceFront.sourceMapURL,
url: sourceFront.url,
introductionType: sourceFront.introductionType,
});
}

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

@ -3,11 +3,7 @@
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
import { setupCommands, clientCommands } from "./firefox/commands";
import {
setupCreate,
createPause,
prepareSourcePayload,
} from "./firefox/create";
import { setupCreate, createPause } from "./firefox/create";
import { features } from "../utils/prefs";
import { recordEvent } from "../utils/telemetry";
@ -153,18 +149,28 @@ function onTargetDestroyed({ targetFront }) {
}
async function onSourceAvailable(sources) {
const frontendSources = await Promise.all(
const sourceInfo = await Promise.all(
sources
.filter(source => {
return !source.targetFront.isDestroyed();
.filter(sourceFront => {
return !sourceFront.targetFront.isDestroyed();
})
.map(async source => {
const threadFront = await source.targetFront.getFront("thread");
const frontendSource = prepareSourcePayload(threadFront, source);
return frontendSource;
.map(async sourceFront => {
const threadFront = await sourceFront.targetFront.getFront("thread");
// Maintain backward-compat with servers that only return introductionUrl and
// not sourceMapBaseURL.
if (
typeof sourceFront.sourceMapBaseURL === "undefined" &&
typeof sourceFront.introductionUrl !== "undefined"
) {
sourceFront.sourceMapBaseURL =
sourceFront.url || sourceFront.introductionUrl || null;
delete sourceFront.introductionUrl;
}
return { thread: threadFront.actor, sourceFront };
})
);
await actions.newGeneratedSources(frontendSources);
await actions.newGeneratedSources(sourceInfo);
}
async function onThreadStateAvailable(resources) {

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

@ -23,22 +23,6 @@ export function setupCreate(dependencies) {
store = dependencies.store;
}
export function prepareSourcePayload(threadFront, source) {
source = { ...source };
// Maintain backward-compat with servers that only return introductionUrl and
// not sourceMapBaseURL.
if (
typeof source.sourceMapBaseURL === "undefined" &&
typeof source.introductionUrl !== "undefined"
) {
source.sourceMapBaseURL = source.url || source.introductionUrl || null;
delete source.introductionUrl;
}
return { thread: threadFront.actor, source };
}
export async function createFrame(thread, frame, index = 0) {
if (!frame) {
return null;

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

@ -24,6 +24,8 @@ export default function update(state = initial, action) {
switch (action.type) {
case "INSERT_SOURCE_ACTORS": {
const { items } = action;
// The `item` objects are defined from `newGeneratedSources` action:
// https://searchfox.org/mozilla-central/rev/4646b826a25d3825cf209db890862b45fa09ffc3/devtools/client/debugger/src/actions/sources/newSources.js#300-314
state = insertResources(
state,
items.map(item => ({

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

@ -261,6 +261,8 @@ function insertSourceActors(state, action) {
actors: { ...state.actors },
};
// The `sourceActor` objects are defined from `newGeneratedSources` action:
// https://searchfox.org/mozilla-central/rev/4646b826a25d3825cf209db890862b45fa09ffc3/devtools/client/debugger/src/actions/sources/newSources.js#300-314
for (const sourceActor of items) {
state.actors[sourceActor.source] = [
...(state.actors[sourceActor.source] || []),

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

@ -110,7 +110,7 @@ function createMakeSource() {
return {
id: name,
thread: "FakeThread",
source: {
sourceFront: {
actor: `${name}-${index}-actor`,
url: `http://localhost:8000/examples/${name}`,
sourceMapBaseURL: props.sourceMapBaseURL || null,