Bug 1541631 - Part 2: Convert Source to be a generic minimal Source interface. r=jlast
authorLogan Smyth <loganfsmyth@gmail.com>
Thu, 15 Aug 2019 21:44:45 +0000
changeset 488389 98dd6077c4d543f87e1e0841a430747b1c9913ac
parent 488388 a080eb120278775f4d3df680ad6656be2250a882
child 488390 4600340598aa1823ef007a8a6610404ecfac0c4b
push id113908
push userccoroiu@mozilla.com
push dateFri, 16 Aug 2019 09:57:53 +0000
treeherdermozilla-inbound@83fad6abe38a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1541631
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1541631 - Part 2: Convert Source to be a generic minimal Source interface. r=jlast Differential Revision: https://phabricator.services.mozilla.com/D42027
devtools/client/debugger/src/actions/sources/prettyPrint.js
devtools/client/debugger/src/actions/types/SourceAction.js
devtools/client/debugger/src/reducers/sources.js
devtools/client/debugger/src/reducers/tests/sources.spec.js
devtools/client/debugger/src/types.js
devtools/client/debugger/src/utils/test-mockup.js
--- a/devtools/client/debugger/src/actions/sources/prettyPrint.js
+++ b/devtools/client/debugger/src/actions/sources/prettyPrint.js
@@ -61,17 +61,17 @@ export async function prettyPrintSource(
 }
 
 export function createPrettySource(cx: Context, sourceId: string) {
   return async ({ dispatch, getState, sourceMaps }: ThunkArgs) => {
     const source = getSourceFromId(getState(), sourceId);
     const url = getPrettySourceURL(source.url);
     const id = generatedToOriginalId(sourceId, url);
 
-    const prettySource: Source = {
+    const prettySource = {
       id,
       url,
       relativeUrl: url,
       isBlackBoxed: false,
       isPrettyPrinted: true,
       isWasm: false,
       introductionUrl: null,
       introductionType: undefined,
--- a/devtools/client/debugger/src/actions/types/SourceAction.js
+++ b/devtools/client/debugger/src/actions/types/SourceAction.js
@@ -1,16 +1,17 @@
 /* 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/>. */
 
 // @flow
 
 import type { SourceId, Source, SourceLocation, Context } from "../../types";
 import type { PromiseAction } from "../utils/middleware/promise";
+import type { SourceBase } from "../../reducers/sources";
 
 export type LoadSourceAction = PromiseAction<
   {|
     +type: "LOAD_SOURCE_TEXT",
     +cx: Context,
     +sourceId: string,
     +epoch: number,
   |},
@@ -19,22 +20,22 @@ export type LoadSourceAction = PromiseAc
     contentType: string | void,
   }
 >;
 export type SourceAction =
   | LoadSourceAction
   | {|
       +type: "ADD_SOURCE",
       +cx: Context,
-      +source: Source,
+      +source: SourceBase,
     |}
   | {|
       +type: "ADD_SOURCES",
       +cx: Context,
-      +sources: Array<Source>,
+      +sources: Array<SourceBase>,
     |}
   | {|
       +type: "CLEAR_SOURCE_MAP_URL",
       +cx: Context,
       +sourceId: SourceId,
     |}
   | {|
       +type: "SET_SELECTED_LOCATION",
--- a/devtools/client/debugger/src/reducers/sources.js
+++ b/devtools/client/debugger/src/reducers/sources.js
@@ -72,18 +72,32 @@ type SourcesContentMap = {
 export type SourcesMapByThread = { [ThreadId]: SourcesMap };
 
 export type BreakpointPositionsMap = { [SourceId]: BreakpointPositions };
 type SourceActorMap = { [SourceId]: Array<SourceActorId> };
 
 type UrlsMap = { [string]: SourceId[] };
 type PlainUrlsMap = { [string]: string[] };
 
+export type SourceBase = {|
+  +id: SourceId,
+  +url: string,
+  +sourceMapURL?: string,
+  +isBlackBoxed: boolean,
+  +isPrettyPrinted: boolean,
+  +relativeUrl: string,
+  +introductionUrl: ?string,
+  +introductionType: ?string,
+  +extensionName: ?string,
+  +isExtension: boolean,
+  +isWasm: boolean,
+|};
+
 type SourceResource = Resource<{
-  ...Source,
+  ...SourceBase,
 }>;
 export type SourceResourceState = ResourceState<SourceResource>;
 
 export type SourcesState = {
   epoch: number,
 
   // All known sources.
   sources: SourceResourceState,
@@ -236,25 +250,25 @@ function update(
     case "SET_FOCUSED_SOURCE_ITEM":
       return { ...state, focusedItem: action.item };
   }
 
   return state;
 }
 
 function resourceAsSource(r: SourceResource): Source {
-  return r;
+  return { ...r };
 }
 
 /*
  * Add sources to the sources store
  * - Add the source to the sources store
  * - Add the source URL to the urls map
  */
-function addSources(state: SourcesState, sources: Source[]): SourcesState {
+function addSources(state: SourcesState, sources: SourceBase[]): SourcesState {
   state = {
     ...state,
     content: { ...state.content },
     urls: { ...state.urls },
     plainUrls: { ...state.plainUrls },
   };
 
   state.sources = insertResources(state.sources, sources);
@@ -348,17 +362,17 @@ function updateProjectDirectoryRoot(stat
   return updateRootRelativeValues({
     ...state,
     projectDirectoryRoot: root,
   });
 }
 
 function updateRootRelativeValues(
   state: SourcesState,
-  sources?: Array<Source>
+  sources?: $ReadOnlyArray<Source>
 ) {
   const ids = sources
     ? sources.map(source => source.id)
     : getResourceIds(state.sources);
 
   state = {
     ...state,
   };
--- a/devtools/client/debugger/src/reducers/tests/sources.spec.js
+++ b/devtools/client/debugger/src/reducers/tests/sources.spec.js
@@ -5,17 +5,17 @@
 // @flow
 declare var describe: (name: string, func: () => void) => void;
 declare var it: (desc: string, func: () => void) => void;
 declare var expect: (value: any) => any;
 
 import update, { initialSourcesState, getDisplayedSources } from "../sources";
 import { initialDebuggeeState } from "../debuggee";
 import updateSourceActors from "../source-actors";
-import type { Source, SourceActor } from "../../types";
+import type { SourceActor } from "../../types";
 import { prefs } from "../../utils/prefs";
 import { makeMockSource, mockcx } from "../../utils/test-mockup";
 import { getResourceIds } from "../../utils/resource";
 
 const extensionSource = {
   ...makeMockSource(),
   id: "extensionId",
   url: "http://example.com/script.js",
@@ -77,17 +77,17 @@ describe("sources reducer", () => {
 describe("sources selectors", () => {
   it("should return all extensions when chrome preference enabled", () => {
     prefs.chromeAndExtenstionsEnabled = true;
     let state = initialSourcesState();
     state = {
       sources: update(state, {
         type: "ADD_SOURCES",
         cx: mockcx,
-        sources: ((mockedSources: any): Source[]),
+        sources: mockedSources,
       }),
       sourceActors: undefined,
     };
     const insertAction = {
       type: "INSERT_SOURCE_ACTORS",
       items: mockSourceActors,
     };
     state = {
@@ -101,17 +101,17 @@ describe("sources selectors", () => {
 
   it("should omit all extensions when chrome preference enabled", () => {
     prefs.chromeAndExtenstionsEnabled = false;
     let state = initialSourcesState();
     state = {
       sources: update(state, {
         type: "ADD_SOURCES",
         cx: mockcx,
-        sources: ((mockedSources: any): Source[]),
+        sources: mockedSources,
       }),
       sourceActors: undefined,
     };
 
     const insertAction = {
       type: "INSERT_SOURCE_ACTORS",
       items: mockSourceActors,
     };
--- a/devtools/client/debugger/src/types.js
+++ b/devtools/client/debugger/src/types.js
@@ -392,29 +392,29 @@ export type SourceWithContentAndType<+Co
 
 /**
  * Source
  *
  * @memberof types
  * @static
  */
 
-export type Source = {|
+export type Source = {
   +id: SourceId,
   +url: string,
   +sourceMapURL?: string,
   +isBlackBoxed: boolean,
   +isPrettyPrinted: boolean,
   +relativeUrl: string,
   +introductionUrl: ?string,
   +introductionType: ?string,
   +extensionName: ?string,
   +isExtension: boolean,
   +isWasm: boolean,
-|};
+};
 
 /**
  * Script
  * This describes scripts which are sent to the debug server to be eval'd
  * @memberof types
  * @static
  * FIXME: This needs a real type definition
  */
--- a/devtools/client/debugger/src/utils/test-mockup.js
+++ b/devtools/client/debugger/src/utils/test-mockup.js
@@ -22,18 +22,22 @@ import type {
   SourceId,
   SourceWithContentAndType,
   SourceWithContent,
   TextSourceContent,
   WasmSourceContent,
   Why,
 } from "../types";
 import * as asyncValue from "./async-value";
+import type { SourceBase } from "../reducers/sources";
 
-function makeMockSource(url: string = "url", id: SourceId = "source"): Source {
+function makeMockSource(
+  url: string = "url",
+  id: SourceId = "source"
+): SourceBase {
   return {
     id,
     url,
     isBlackBoxed: false,
     isPrettyPrinted: false,
     relativeUrl: url,
     introductionUrl: null,
     introductionType: undefined,