devtools: Fix available breakpoint positions with nested scripts (#38826)

in the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), there is a
separate
[Debugger.Script](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html)
object for each function in a script, forming a tree of Script objects.
since we were only issuing
[getPossibleBreakpoints()](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html#getpossiblebreakpoints-query)
queries to the [root Script
object](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.html#onnewscript-script-global)
for each script, we were failing to report locations inside functions as
available for setting breakpoints.

this patch fixes that by recursively issuing the
getPossibleBreakpoints() requests over the
[getChildScripts()](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html#getchildscripts)
tree.

Testing: this patch adds a new devtools test

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
shuppy 2025-08-21 19:00:32 +08:00 committed by GitHub
parent 7b4032e972
commit 4ba34b038c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 1 deletions

View file

@ -38,5 +38,15 @@ addEventListener("addDebuggee", event => {
addEventListener("getPossibleBreakpoints", event => {
const {spidermonkeyId} = event;
getPossibleBreakpointsResult(event, sourceIdsToScripts.get(spidermonkeyId).getPossibleBreakpoints(/* TODO: `query` */));
const script = sourceIdsToScripts.get(spidermonkeyId);
function getPossibleBreakpointsRecursive(script) {
const result = script.getPossibleBreakpoints(/* TODO: `query` */);
for (const child of script.getChildScripts()) {
for (const location of getPossibleBreakpointsRecursive(child)) {
result.push(location);
}
}
return result;
}
getPossibleBreakpointsResult(event, getPossibleBreakpointsRecursive(script));
});