tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a29b71d7f6f034765a58d90fbeb3db8acfbed6ed
parent def4c11111e9435585c383cc53c7262c683f5277
Author: Alexandre Poirot <poirot.alex@gmail.com>
Date:   Tue,  7 Oct 2025 22:22:11 +0000

Bug 1991698 - [devtools] Use the shared promise middleware in the debugger. r=devtools-reviewers,nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D267187

Diffstat:
Mdevtools/client/debugger/src/actions/breakpoints/index.js | 4+++-
Mdevtools/client/debugger/src/actions/breakpoints/modify.js | 4+++-
Mdevtools/client/debugger/src/actions/expressions.js | 4+++-
Mdevtools/client/debugger/src/actions/pause/commands.js | 4+++-
Mdevtools/client/debugger/src/actions/pause/fetchScopes.js | 4+++-
Mdevtools/client/debugger/src/actions/pause/mapScopes.js | 4+++-
Mdevtools/client/debugger/src/actions/pause/pauseOnDebuggerStatement.js | 4+++-
Mdevtools/client/debugger/src/actions/pause/pauseOnExceptions.js | 4+++-
Mdevtools/client/debugger/src/actions/sources/loadSourceText.js | 4+++-
Mdevtools/client/debugger/src/actions/utils/create-store.js | 4+++-
Mdevtools/client/debugger/src/actions/utils/middleware/moz.build | 1-
Ddevtools/client/debugger/src/actions/utils/middleware/promise.js | 61-------------------------------------------------------------
Mdevtools/client/framework/test/metrics/browser_metrics_debugger.js | 1+
Mdevtools/client/shared/redux/middleware/promise.js | 19++++++++++++-------
14 files changed, 43 insertions(+), 79 deletions(-)

diff --git a/devtools/client/debugger/src/actions/breakpoints/index.js b/devtools/client/debugger/src/actions/breakpoints/index.js @@ -7,7 +7,9 @@ * @module actions/breakpoints */ -import { PROMISE } from "../utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); import { asyncStore } from "../../utils/prefs"; import { createLocation } from "../../utils/location"; import { diff --git a/devtools/client/debugger/src/actions/breakpoints/modify.js b/devtools/client/debugger/src/actions/breakpoints/modify.js @@ -23,7 +23,9 @@ import { import { setBreakpointPositions } from "./breakpointPositions"; import { setSkipPausing } from "../pause/skipPausing"; -import { PROMISE } from "../utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); import { recordEvent } from "../../utils/telemetry"; import { comparePosition } from "../../utils/location"; import { getTextAtPosition, isLineBlackboxed } from "../../utils/source"; diff --git a/devtools/client/debugger/src/actions/expressions.js b/devtools/client/debugger/src/actions/expressions.js @@ -13,7 +13,9 @@ import { getCurrentThread, isMapScopesEnabled, } from "../selectors/index"; -import { PROMISE } from "./utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); import { wrapExpression } from "../utils/expressions"; import { features } from "../utils/prefs"; diff --git a/devtools/client/debugger/src/actions/pause/commands.js b/devtools/client/debugger/src/actions/pause/commands.js @@ -8,7 +8,9 @@ import { getIsCurrentThreadPaused, getIsPaused, } from "../../selectors/index"; -import { PROMISE } from "../utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); import { evaluateExpressions } from "../expressions"; import { selectLocation } from "../sources/index"; import { fetchScopes } from "./fetchScopes"; diff --git a/devtools/client/debugger/src/actions/pause/fetchScopes.js b/devtools/client/debugger/src/actions/pause/fetchScopes.js @@ -9,7 +9,9 @@ import { } from "../../selectors/index"; import { mapScopes } from "./mapScopes"; import { generateInlinePreview } from "./inlinePreview"; -import { PROMISE } from "../utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); import { validateSelectedFrame } from "../../utils/context"; /** diff --git a/devtools/client/debugger/src/actions/pause/mapScopes.js b/devtools/client/debugger/src/actions/pause/mapScopes.js @@ -15,7 +15,9 @@ import { loadGeneratedSourceText, } from "../sources/loadSourceText"; import { validateSelectedFrame } from "../../utils/context"; -import { PROMISE } from "../utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); import { log } from "../../utils/log"; diff --git a/devtools/client/debugger/src/actions/pause/pauseOnDebuggerStatement.js b/devtools/client/debugger/src/actions/pause/pauseOnDebuggerStatement.js @@ -2,7 +2,9 @@ * 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 { PROMISE } from "../utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); export function pauseOnDebuggerStatement(shouldPauseOnDebuggerStatement) { return ({ dispatch, client }) => { diff --git a/devtools/client/debugger/src/actions/pause/pauseOnExceptions.js b/devtools/client/debugger/src/actions/pause/pauseOnExceptions.js @@ -2,7 +2,9 @@ * 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 { PROMISE } from "../utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); import { recordEvent } from "../../utils/telemetry"; /** diff --git a/devtools/client/debugger/src/actions/sources/loadSourceText.js b/devtools/client/debugger/src/actions/sources/loadSourceText.js @@ -2,7 +2,9 @@ * 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 { PROMISE } from "../utils/middleware/promise"; +const { + PROMISE, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); import { getSourceTextContentForSource, getSettledSourceTextContent, diff --git a/devtools/client/debugger/src/actions/utils/create-store.js b/devtools/client/debugger/src/actions/utils/create-store.js @@ -13,7 +13,6 @@ import { applyMiddleware, } from "devtools/client/shared/vendor/redux"; import { log } from "./middleware/log"; -import { promise } from "./middleware/promise"; import { timing } from "./middleware/timing"; import { context } from "./middleware/context"; @@ -21,6 +20,9 @@ const { ignore, } = require("resource://devtools/client/shared/redux/middleware/ignore.js"); const { + promise, +} = require("resource://devtools/client/shared/redux/middleware/promise.js"); +const { thunk, } = require("resource://devtools/client/shared/redux/middleware/thunk.js"); const { diff --git a/devtools/client/debugger/src/actions/utils/middleware/moz.build b/devtools/client/debugger/src/actions/utils/middleware/moz.build @@ -8,6 +8,5 @@ DIRS += [] CompiledModules( "context.js", "log.js", - "promise.js", "timing.js", ) diff --git a/devtools/client/debugger/src/actions/utils/middleware/promise.js b/devtools/client/debugger/src/actions/utils/middleware/promise.js @@ -1,61 +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 { executeSoon } from "../../../utils/DevToolsUtils"; - -import { pending, rejected, fulfilled } from "../../../utils/async-value"; -export function asyncActionAsValue(action) { - if (action.status === "start") { - return pending(); - } - if (action.status === "error") { - return rejected(action.error); - } - return fulfilled(action.value); -} - -let seqIdVal = 1; - -function seqIdGen() { - return seqIdVal++; -} - -function promiseMiddleware({ dispatch }) { - return next => action => { - if (!(PROMISE in action)) { - return next(action); - } - - const seqId = seqIdGen().toString(); - const { [PROMISE]: promiseInst, ...originalActionProperties } = action; - - // Create a new action that doesn't have the promise field and has - // the `seqId` field that represents the sequence id - action = { ...originalActionProperties, seqId }; - - dispatch({ ...action, status: "start" }); - - // Return the promise so action creators can still compose if they - // want to. - return Promise.resolve(promiseInst) - .finally(() => new Promise(resolve => executeSoon(resolve))) - .then( - value => { - dispatch({ ...action, status: "done", value }); - return value; - }, - error => { - dispatch({ - ...action, - status: "error", - error: error.message || error, - }); - return Promise.reject(error); - } - ); - }; -} - -export const PROMISE = "@@dispatch/promise"; -export { promiseMiddleware as promise }; diff --git a/devtools/client/framework/test/metrics/browser_metrics_debugger.js b/devtools/client/framework/test/metrics/browser_metrics_debugger.js @@ -36,6 +36,7 @@ add_task(async function () { "resource://devtools/client/shared/vendor/react-redux.js", "resource://devtools/client/shared/vendor/redux.js", "resource://devtools/client/shared/redux/subscriber.js", + "resource://devtools/client/shared/redux/middleware/promise.js", "resource://devtools/client/shared/redux/middleware/thunk.js", "resource://devtools/client/shared/redux/middleware/wait-service.js", diff --git a/devtools/client/shared/redux/middleware/promise.js b/devtools/client/shared/redux/middleware/promise.js @@ -52,13 +52,18 @@ function promiseMiddleware({ dispatch }) { }, error => { executeSoon(() => { - dispatch( - Object.assign({}, action, { - status: "error", - error: error.message || error, - }) - ); - reject(error); + try { + dispatch( + Object.assign({}, action, { + status: "error", + error: error.message || error, + }) + ); + } finally { + // Ensure rejecting the original promise, + // even if the "error" action also throws + reject(error); + } }); } );