tor-browser

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

commit d42d760c2d8402a4e6b4939e780693707fc7fce7
parent 1139cba1a7eff8f5f62e842f5dfc359fdda8a6e4
Author: Hubert Boma Manilla <hmanilla@mozilla.com>
Date:   Mon, 20 Oct 2025 13:42:25 +0000

Bug 1994114 - [devtools] Show only one inline preview when binding which are accesible to multiple scopes r=devtools-reviewers,ochameau

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

Diffstat:
Mdevtools/client/debugger/src/actions/pause/inlinePreview.js | 8++++++++
Mdevtools/client/debugger/test/mochitest/browser_dbg-inline-preview.js | 8++++++++
Mdevtools/client/debugger/test/mochitest/examples/inline-preview.js | 15+++++++++++++++
3 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/devtools/client/debugger/src/actions/pause/inlinePreview.js b/devtools/client/debugger/src/actions/pause/inlinePreview.js @@ -86,6 +86,7 @@ async function getPreviews(selectedFrame, scope, thunkArgs) { } const allPreviews = []; + const seenBindings = {}; const bindingReferences = await editor.getBindingReferences( selectedLocation, @@ -95,6 +96,12 @@ async function getPreviews(selectedFrame, scope, thunkArgs) { for (const level in bindingReferences) { for (const name in bindingReferences[level]) { + const valueActorID = bindingReferences[level][name].value?.actor; + // Ignore any binding with the same value which has already been displayed. + // This might occur if a variable gets hoisted and is available to the local and global scope. + if (seenBindings[name] && seenBindings[name] == valueActorID) { + continue; + } const previews = await generatePreviewsForBinding( bindingReferences[level][name], selectedLocation.line, @@ -102,6 +109,7 @@ async function getPreviews(selectedFrame, scope, thunkArgs) { client, selectedFrame.thread ); + seenBindings[name] = valueActorID; allPreviews.push(...previews); } } diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-inline-preview.js b/devtools/client/debugger/test/mochitest/browser_dbg-inline-preview.js @@ -158,6 +158,14 @@ add_task(async function testInlinePreviews() { ], }); + await invokeFunctionAndAssertInlinePreview({ + dbg, + fnName: "innerBlockHoistedFuncDecl", + expectedInlinePreviews: [ + { previews: [{ identifier: "foo:", value: "function foo()" }], line: 90 }, + ], + }); + // Check inline previews for values within a module script await invokeFunctionAndAssertInlinePreview({ dbg, diff --git a/devtools/client/debugger/test/mochitest/examples/inline-preview.js b/devtools/client/debugger/test/mochitest/examples/inline-preview.js @@ -79,3 +79,18 @@ function protoVar() { const __proto__ = "lemon"; debugger; } + +// Test case to help assert that same binding in two different scope +// does not show duplicate inline previews. +// The func declaration `foo` will get hoisted (in non strict mode), +// so it'll be available in both the block scope and the parnet function +// scope. +function innerBlockHoistedFuncDecl() { + { + function foo() { + console.trace(); + } + foo(); + debugger; + } +}