diff --git a/src/index.js b/src/index.js index 98f4981f5f..f13737ef8f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ /* 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 React from 'react'; import { render } from 'react-dom'; @@ -12,11 +13,12 @@ import { addDataToWindowObject, logFriendlyPreamble, } from './utils/window-console'; +import { ensureExists } from './utils/flow'; // Mock out Google Analytics for anything that's not production so that we have run-time // code coverage in development and testing. if (process.env.NODE_ENV === 'development') { - window.ga = (event, ...payload) => { + window.ga = (event: string, ...payload: mixed[]) => { const style = 'color: #FF6D00; font-weight: bold'; console.log(`[analytics] %c"${event}"`, style, ...payload); }; @@ -39,7 +41,13 @@ window.geckoProfilerPromise = new Promise(function(resolve) { const store = createStore(); -render(, document.getElementById('root')); +render( + , + ensureExists( + document.getElementById('root'), + 'Unable to find the DOM element to attach the React element to.' + ) +); addDataToWindowObject(store.getState); if (process.env.NODE_ENV === 'production') { diff --git a/src/profile-logic/process-profile.js b/src/profile-logic/process-profile.js index 196efd7d2d..49cbb89d86 100644 --- a/src/profile-logic/process-profile.js +++ b/src/profile-logic/process-profile.js @@ -6,7 +6,6 @@ import { getContainingLibrary } from './symbolication'; import { UniqueStringArray } from '../utils/unique-string-array'; import { resourceTypes, emptyExtensions } from './profile-data'; -import { provideHostSide } from '../utils/promise-worker'; import { immutableUpdate } from '../utils/flow'; import { CURRENT_VERSION, @@ -688,7 +687,7 @@ function _processThread( tid: thread.tid, pid: thread.pid, libs, - pausedRanges, + pausedRanges: pausedRanges || [], frameTable, funcTable, resourceTable, @@ -926,8 +925,3 @@ export class ProfileProcessor { }); } } - -export const ProfileProcessorThreaded = provideHostSide( - 'profile-processor-worker.js', - ['processProfile'] -); diff --git a/src/profile-logic/profile-store.js b/src/profile-logic/profile-store.js index 6269105eb1..5d1fe87a0a 100644 --- a/src/profile-logic/profile-store.js +++ b/src/profile-logic/profile-store.js @@ -1,11 +1,12 @@ /* 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 export function uploadBinaryProfileData( - data, - progressChangeCallback = undefined -) { + data: string, + progressChangeCallback?: number => void +): Promise { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); diff --git a/src/profile-logic/range-filters.js b/src/profile-logic/range-filters.js index 8c159bc655..011930354c 100644 --- a/src/profile-logic/range-filters.js +++ b/src/profile-logic/range-filters.js @@ -1,8 +1,11 @@ /* 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 -export function parseRangeFilters(stringValue = '') { +import type { StartEndRange } from '../types/units'; + +export function parseRangeFilters(stringValue: string = ''): StartEndRange[] { if (!stringValue) { return []; } @@ -11,11 +14,13 @@ export function parseRangeFilters(stringValue = '') { if (!m) { return { start: 0, end: 1000 }; } - return { start: m[1] * 1000, end: m[2] * 1000 }; + return { start: Number(m[1]) * 1000, end: Number(m[2]) * 1000 }; }); } -export function stringifyRangeFilters(arrayValue = []) { +export function stringifyRangeFilters( + arrayValue: StartEndRange[] = [] +): string { return arrayValue .map(({ start, end }) => { const startStr = (start / 1000).toFixed(4); @@ -25,7 +30,7 @@ export function stringifyRangeFilters(arrayValue = []) { .join('~'); } -export function getFormattedTimeLength(length) { +export function getFormattedTimeLength(length: number): string { if (length >= 10000) { return `${(length / 1000).toFixed(0)} sec`; } @@ -35,7 +40,7 @@ export function getFormattedTimeLength(length) { return `${length.toFixed(0)} ms`; } -export function getRangeFilterLabels(rangeFilters) { +export function getRangeFilterLabels(rangeFilters: StartEndRange[]): string[] { const labels = rangeFilters.map(range => getFormattedTimeLength(range.end - range.start) ); diff --git a/src/profile-logic/symbol-store-db-worker.js b/src/profile-logic/symbol-store-db-worker.js deleted file mode 100644 index f2880f781b..0000000000 --- a/src/profile-logic/symbol-store-db-worker.js +++ /dev/null @@ -1,8 +0,0 @@ -/* 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 SymbolStoreDB from './symbol-store-db'; -import { provideWorkerSide } from '../utils/promise-worker'; - -provideWorkerSide(self, SymbolStoreDB); diff --git a/src/test/fixtures/mocks/file-mock.js b/src/test/fixtures/mocks/file-mock.js index 602eb23ee2..acbcda64f1 100644 --- a/src/test/fixtures/mocks/file-mock.js +++ b/src/test/fixtures/mocks/file-mock.js @@ -1 +1,6 @@ +/* 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 export default 'test-file-stub'; diff --git a/src/test/fixtures/mocks/image.js b/src/test/fixtures/mocks/image.js index 95465f468d..c133462c51 100644 --- a/src/test/fixtures/mocks/image.js +++ b/src/test/fixtures/mocks/image.js @@ -2,6 +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/. */ +// @flow export function createImageMock() { function Image() { instances.push(this); diff --git a/src/test/fixtures/mocks/style-mock.js b/src/test/fixtures/mocks/style-mock.js index ff8b4c5632..fc45854879 100644 --- a/src/test/fixtures/mocks/style-mock.js +++ b/src/test/fixtures/mocks/style-mock.js @@ -1 +1,6 @@ +/* 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 export default {}; diff --git a/src/types/globals/Window.js b/src/types/globals/Window.js index 28f526569e..3b222d560f 100644 --- a/src/types/globals/Window.js +++ b/src/types/globals/Window.js @@ -20,6 +20,7 @@ declare class Window extends EventTarget { ga?: GoogleAnalytics; // perf.html and Gecko Profiler Addon geckoProfilerPromise: Promise; + connectToGeckoProfiler: GeckoProfiler => void; geckoProfilerAddonInstalled?: () => void; isGeckoProfilerAddonInstalled?: boolean; InstallTrigger?: { diff --git a/src/profile-logic/profile-processor-worker.js b/src/types/libdef/npm-custom/photon-colors_vx.x.x.js similarity index 56% rename from src/profile-logic/profile-processor-worker.js rename to src/types/libdef/npm-custom/photon-colors_vx.x.x.js index 60d23d644c..98d1b440f6 100644 --- a/src/profile-logic/profile-processor-worker.js +++ b/src/types/libdef/npm-custom/photon-colors_vx.x.x.js @@ -1,8 +1,12 @@ /* 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 { ProfileProcessor } from './process-profile'; -import { provideWorkerSide } from '../utils/promise-worker'; +declare module 'photon-colors' { + declare module.exports: any; +} -provideWorkerSide(self, ProfileProcessor); +declare module 'photon-colors/photon-colors.css' { + declare module.exports: any; +} diff --git a/src/types/libdef/npm/photon-colors_vx.x.x.js b/src/types/libdef/npm/photon-colors_vx.x.x.js deleted file mode 100644 index dff11e1034..0000000000 --- a/src/types/libdef/npm/photon-colors_vx.x.x.js +++ /dev/null @@ -1,39 +0,0 @@ -// flow-typed signature: 2677a4eb39233911257298be43e809dc -// flow-typed version: <>/photon-colors_v2.0.1/flow_v0.66.0 - -/** - * This is an autogenerated libdef stub for: - * - * 'photon-colors' - * - * Fill this stub out by replacing all the `any` types. - * - * Once filled out, we encourage you to share your work with the - * community by sending a pull request to: - * https://github.com/flowtype/flow-typed - */ - -declare module 'photon-colors' { - declare module.exports: any; -} - -/** - * We include stubs for each file inside this npm package in case you need to - * require those files directly. Feel free to delete any files that aren't - * needed. - */ -declare module 'photon-colors/build' { - declare module.exports: any; -} - -declare module 'photon-colors/photon-colors' { - declare module.exports: any; -} - -// Filename aliases -declare module 'photon-colors/build.js' { - declare module.exports: $Exports<'photon-colors/build'>; -} -declare module 'photon-colors/photon-colors.js' { - declare module.exports: $Exports<'photon-colors/photon-colors'>; -} diff --git a/src/types/reducers.js b/src/types/reducers.js index 8ee154db22..97c2c3f69f 100644 --- a/src/types/reducers.js +++ b/src/types/reducers.js @@ -117,11 +117,6 @@ export type ZippedProfilesState = { expandedZipFileIndexes: Array, }; -export type RangeFilterState = { - start: number, - end: number, -}; - export type UrlState = {| dataSource: DataSource, hash: string, @@ -131,7 +126,7 @@ export type UrlState = {| profileSpecific: {| implementation: ImplementationFilter, invertCallstack: boolean, - rangeFilters: RangeFilterState[], + rangeFilters: StartEndRange[], selectedThread: ThreadIndex | null, callTreeSearchString: string, threadOrder: ThreadIndex[],