script: Create a debugger script for the SpiderMonkey Debugger API (#38331)

to use the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), we need to
call it from an internal debugger script that we will supply. this
script must run in the same runtime as the debuggee(s), but in a
separate
[compartment](https://udn.realityripple.com/docs/Mozilla/Projects/SpiderMonkey/Compartments)
([more
details](https://hacks.mozilla.org/2020/03/future-proofing-firefoxs-javascript-debugger-implementation/)).

this patch defines a new DebuggerGlobalScope type and a new debugger
script resource. when creating each script thread, we create a debugger
global, load the debugger script from resources/debugger.js, and run
that script in the global to initialise the Debugger API.

subsequent patches will use the debugger script as an RPC mechanism for
the Debugger API.

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

---------

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
shuppy 2025-07-31 14:17:23 +08:00 committed by GitHub
parent 8e27fd48cc
commit c09e117bfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 184 additions and 6 deletions

View file

@ -133,6 +133,7 @@ use crate::dom::htmlslotelement::HTMLSlotElement;
use crate::dom::mutationobserver::MutationObserver;
use crate::dom::node::{Node, NodeTraits, ShadowIncluding};
use crate::dom::servoparser::{ParserContext, ServoParser};
use crate::dom::types::DebuggerGlobalScope;
#[cfg(feature = "webgpu")]
use crate::dom::webgpu::identityhub::IdentityHub;
use crate::dom::window::Window;
@ -348,6 +349,8 @@ pub struct ScriptThread {
/// itself is managing animations the the timer fired triggering a [`ScriptThread`]-based
/// animation tick.
has_pending_animation_tick: Arc<AtomicBool>,
debugger_global: Dom<DebuggerGlobalScope>,
}
struct BHMExitSignal {
@ -928,6 +931,30 @@ impl ScriptThread {
content_process_shutdown_sender: state.content_process_shutdown_sender,
};
let microtask_queue = runtime.microtask_queue.clone();
let js_runtime = Rc::new(runtime);
#[cfg(feature = "webgpu")]
let gpu_id_hub = Arc::new(IdentityHub::default());
let pipeline_id = PipelineId::new();
let script_to_constellation_chan = ScriptToConstellationChan {
sender: senders.pipeline_to_constellation_sender.clone(),
pipeline_id,
};
let debugger_global = DebuggerGlobalScope::new(
&js_runtime.clone(),
senders.self_sender.clone(),
senders.devtools_server_sender.clone(),
senders.memory_profiler_sender.clone(),
senders.time_profiler_sender.clone(),
script_to_constellation_chan,
state.resource_threads.clone(),
#[cfg(feature = "webgpu")]
gpu_id_hub.clone(),
CanGc::note(),
);
debugger_global.execute(CanGc::note());
ScriptThread {
documents: DomRefCell::new(DocumentCollection::default()),
last_render_opportunity_time: Default::default(),
@ -942,8 +969,8 @@ impl ScriptThread {
background_hang_monitor,
closing,
timer_scheduler: Default::default(),
microtask_queue: runtime.microtask_queue.clone(),
js_runtime: Rc::new(runtime),
microtask_queue,
js_runtime,
topmost_mouse_over_target: MutNullableDom::new(Default::default()),
closed_pipelines: DomRefCell::new(HashSet::new()),
mutation_observer_microtask_queued: Default::default(),
@ -967,12 +994,13 @@ impl ScriptThread {
pipeline_to_node_ids: Default::default(),
is_user_interacting: Cell::new(false),
#[cfg(feature = "webgpu")]
gpu_id_hub: Arc::new(IdentityHub::default()),
gpu_id_hub,
inherited_secure_context: state.inherited_secure_context,
layout_factory,
relative_mouse_down_point: Cell::new(Point2D::zero()),
scheduled_script_thread_animation_timer: Default::default(),
has_pending_animation_tick: Arc::new(AtomicBool::new(false)),
debugger_global: debugger_global.as_traced(),
}
}