Skip to content

Conversation

@delan
Copy link
Member

@delan delan commented Jul 29, 2025

to debug the scripts in a page with the SpiderMonkey Debugger API, we need to pass the page’s global object to Debugger.prototype.addDebuggee(). we could pick up the global via the onNewGlobalObject() hook, but if our script system passes the global to the debugger script instead, we can later add details like the PipelineId that will help servo identify debuggees that the API is notifying us about (#38334).

this patch plumbs new Window globals from script into addDebuggee() via the debugger script. to call into the debugger script with structured input, we create a new DOM event type, DebuggerEvent, that the debugger script listens for as the “addDebuggee” event.

Testing: no testable effects yet, but will be used in #37667
Fixes: part of #36027

@delan delan force-pushed the debugger-add-debuggees branch from 90d1e8e to 5865229 Compare July 30, 2025 11:26
@delan delan force-pushed the debugger-add-debuggees branch 5 times, most recently from 95595db to c02c3fd Compare August 4, 2025 11:09
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
@delan delan force-pushed the debugger-add-debuggees branch from c02c3fd to e2eabd4 Compare August 4, 2025 11:53
@delan delan marked this pull request as ready for review August 4, 2025 12:16
@delan delan requested a review from gterzian as a code owner August 4, 2025 12:16
@delan delan requested a review from sagudev August 4, 2025 12:34
Copy link
Member

@sagudev sagudev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks alright at first glance, I will take another look tomorrow with fresh eyes.

/// Event for Rust → JS calls in [`crate::dom::DebuggerGlobalScope`].
pub(crate) struct DebuggerEvent {
event: Event,
global: MutNullableDom<GlobalScope>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use MutNullableDom here? We do not need nor mutability nor null-ability.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason, i just didn’t understand how it’s safe to use Dom<T> here. wouldn’t it momentarily be a forbidden “on-stack value” when used in the struct initialiser, but before moving it to the Box?

in any case, fixed in 11d5a2e

delan added 3 commits August 5, 2025 10:17
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Signed-off-by: Delan Azabani <dazabani@igalia.com>
@delan delan requested review from jdm and sagudev August 5, 2025 02:25
Signed-off-by: Delan Azabani <dazabani@igalia.com>
@delan delan enabled auto-merge August 5, 2025 03:36
@delan delan disabled auto-merge August 5, 2025 03:36
@delan delan added this pull request to the merge queue Aug 5, 2025
Merged via the queue into main with commit 92a9d24 Aug 5, 2025
21 checks passed
@delan delan deleted the debugger-add-debuggees branch August 5, 2025 06:15
github-merge-queue bot pushed a commit that referenced this pull request Aug 5, 2025
#38333 adds new code to the debugger script containing some
console.log() calls, which unlike native rust log messages can’t be
turned off. this patch removes them for now, until we find a better
approach.

Testing: no testable changes in this patch
Fixes: noisy logging as of #38333

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
github-merge-queue bot pushed a commit that referenced this pull request Aug 11, 2025
currently our devtools impl creates source actors in script, when
executing scripts in HTMLScriptElement or DedicatedWorkerGlobalScope.
this approach is cumbersome, and it means that many pathways to running
scripts are missed, such as imported ES modules.

with the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), we can pick
up all of the scripts and all of their sources without any extra code,
as long as we tell it about every global we create (#38333, #38551).
this patch adds a [Debugger#onNewScript()
hook](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.html#onnewscript-script-global)
to the debugger script, which calls
DebuggerGlobalScope#notifyNewSource() to notify our script system when a
new script runs. if the source is relevant to the file tree in the
Sources tab, script tells devtools to create a source actor.

Testing: adds several new automated devtools tests
Fixes: part of #36027

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants