devtools: implement clearBreakpoint (#42154)

Add an event listener for `clearBreakpoint` to `debugger.js` and the
necessary glue to access it from the `devtools` crate.

Testing: `./mach test-devtools` and manual testing.
Fixes: Part of: https://github.com/servo/servo/issues/36027

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: eri <eri@igalia.com>
This commit is contained in:
atbrakhi
2026-01-27 21:16:54 +05:30
committed by GitHub
parent 33bb35c5da
commit e28a0f6d6c
9 changed files with 174 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ use crate::{ActorMsg, EmptyReplyMsg};
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SetBreakpointRequestLocation {
pub struct BreakpointRequestLocation {
pub line: u32,
pub column: u32,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -22,8 +22,8 @@ pub struct SetBreakpointRequestLocation {
}
#[derive(Deserialize)]
struct SetBreakpointRequest {
location: SetBreakpointRequestLocation,
struct BreakpointRequest {
location: BreakpointRequestLocation,
}
pub(crate) struct BreakpointListActor {
@@ -49,9 +49,9 @@ impl Actor for BreakpointListActor {
// Seems to be infallible, unlike the thread actors `setBreakpoint`.
// <https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#breakpoints>
"setBreakpoint" => {
let msg: SetBreakpointRequest =
let msg: BreakpointRequest =
serde_json::from_value(msg.clone().into()).map_err(|_| ActorError::Internal)?;
let SetBreakpointRequestLocation {
let BreakpointRequestLocation {
line,
column,
source_url,
@@ -84,6 +84,33 @@ impl Actor for BreakpointListActor {
request.reply_final(&msg)?
},
"removeBreakpoint" => {
let msg: BreakpointRequest =
serde_json::from_value(msg.clone().into()).map_err(|_| ActorError::Internal)?;
let BreakpointRequestLocation {
line,
column,
source_url,
} = msg.location;
let source_url = source_url.ok_or(ActorError::Internal)?;
let browsing_context =
registry.find::<BrowsingContextActor>(&self.browsing_context);
let thread = registry.find::<ThreadActor>(&browsing_context.thread);
let source = thread
.source_manager
.find_source(registry, &source_url)
.ok_or(ActorError::Internal)?;
let (script_id, offset) = source.find_offset(line, column);
source
.script_sender
.send(DevtoolScriptControlMsg::ClearBreakpoint(
source.spidermonkey_id,
script_id,
offset,
))
.map_err(|_| ActorError::Internal)?;
let msg = EmptyReplyMsg { from: self.name() };
request.reply_final(&msg)?
},

View File

@@ -15,7 +15,7 @@ use servo_url::ServoUrl;
use crate::StreamId;
use crate::actor::{Actor, ActorError, ActorRegistry, DowncastableActorArc};
use crate::actors::breakpoint::SetBreakpointRequestLocation;
use crate::actors::breakpoint::BreakpointRequestLocation;
use crate::protocol::ClientRequest;
/// A `sourceForm` as used in responses to thread `sources` requests.
@@ -131,8 +131,8 @@ struct GetBreakpointPositionsCompressedReply {
#[derive(Deserialize)]
struct GetBreakpointPositionsQuery {
start: SetBreakpointRequestLocation,
end: SetBreakpointRequestLocation,
start: BreakpointRequestLocation,
end: BreakpointRequestLocation,
}
#[derive(Deserialize)]

View File

@@ -0,0 +1,76 @@
/* 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 https://mozilla.org/MPL/2.0/. */
use std::fmt::Debug;
use dom_struct::dom_struct;
use script_bindings::codegen::GenericBindings::DebuggerClearBreakpointEventBinding::DebuggerClearBreakpointEventMethods;
use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::event::Event;
use crate::dom::types::GlobalScope;
use crate::script_runtime::CanGc;
#[dom_struct]
/// Event for Rust → JS calls in [`crate::dom::DebuggerGlobalScope`].
pub(crate) struct DebuggerClearBreakpointEvent {
event: Event,
spidermonkey_id: u32,
script_id: u32,
offset: u32,
}
impl DebuggerClearBreakpointEvent {
pub(crate) fn new(
debugger_global: &GlobalScope,
spidermonkey_id: u32,
script_id: u32,
offset: u32,
can_gc: CanGc,
) -> DomRoot<Self> {
let result = Box::new(Self {
event: Event::new_inherited(),
spidermonkey_id,
script_id,
offset,
});
let result = reflect_dom_object(result, debugger_global, can_gc);
result
.event
.init_event("clearBreakpoint".into(), false, false);
result
}
}
impl DebuggerClearBreakpointEventMethods<crate::DomTypeHolder> for DebuggerClearBreakpointEvent {
// check-tidy: no specs after this line
fn SpidermonkeyId(&self) -> u32 {
self.spidermonkey_id
}
fn ScriptId(&self) -> u32 {
self.script_id
}
fn Offset(&self) -> u32 {
self.offset
}
fn IsTrusted(&self) -> bool {
self.event.IsTrusted()
}
}
impl Debug for DebuggerClearBreakpointEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DebuggerClearBreakpointEvent")
.field("spidermonkey_id", &self.spidermonkey_id)
.field("script_id", &self.script_id)
.field("offset", &self.offset)
.finish()
}
}

View File

@@ -31,6 +31,7 @@ use crate::dom::bindings::error::report_pending_exception;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::utils::define_all_exposed_interfaces;
use crate::dom::debuggerclearbreakpointevent::DebuggerClearBreakpointEvent;
use crate::dom::debuggerpauseevent::DebuggerPauseEvent;
use crate::dom::debuggersetbreakpointevent::DebuggerSetBreakpointEvent;
use crate::dom::globalscope::GlobalScope;
@@ -225,6 +226,26 @@ impl DebuggerGlobalScope {
"Guaranteed by DebuggerPauseEvent::new"
);
}
pub(crate) fn fire_clear_breakpoint(
&self,
can_gc: CanGc,
spidermonkey_id: u32,
script_id: u32,
offset: u32,
) {
let event = DomRoot::upcast::<Event>(DebuggerClearBreakpointEvent::new(
self.upcast(),
spidermonkey_id,
script_id,
offset,
can_gc,
));
assert!(
event.fire(self.upcast(), can_gc),
"Guaranteed by DebuggerClearBreakpointEvent::new"
);
}
}
impl DebuggerGlobalScopeMethods<crate::DomTypeHolder> for DebuggerGlobalScope {

View File

@@ -255,6 +255,7 @@ pub(crate) mod datatransfer;
pub(crate) mod datatransferitem;
pub(crate) mod datatransferitemlist;
pub(crate) mod debuggeradddebuggeeevent;
pub(crate) mod debuggerclearbreakpointevent;
pub(crate) mod debuggergetpossiblebreakpointsevent;
pub(crate) mod debuggerglobalscope;
pub(crate) mod debuggerpauseevent;

View File

@@ -2181,6 +2181,14 @@ impl ScriptThread {
offset,
);
},
DevtoolScriptControlMsg::ClearBreakpoint(spidermonkey_id, script_id, offset) => {
self.debugger_global.fire_clear_breakpoint(
CanGc::from_cx(cx),
spidermonkey_id,
script_id,
offset,
);
},
DevtoolScriptControlMsg::Pause(result_sender) => {
self.debugger_global
.fire_pause(CanGc::from_cx(cx), result_sender);

View File

@@ -0,0 +1,12 @@
/* 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 https://mozilla.org/MPL/2.0/. */
// This interface is entirely internal to Servo, and should not be accessible to
// web pages.
[Exposed=DebuggerGlobalScope]
interface DebuggerClearBreakpointEvent : Event {
readonly attribute unsigned long spidermonkeyId;
readonly attribute unsigned long scriptId;
readonly attribute unsigned long offset;
};

View File

@@ -309,6 +309,7 @@ pub enum DevtoolScriptControlMsg {
GetPossibleBreakpoints(u32, GenericSender<Vec<RecommendedBreakpointLocation>>),
SetBreakpoint(u32, u32, u32),
ClearBreakpoint(u32, u32, u32),
Pause(GenericSender<PauseFrameResult>),
}

View File

@@ -98,3 +98,23 @@ addEventListener("pause", event => {
getFrameResult(event, result);
};
});
// <https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html#clearbreakpoint-handler-offset>
// There may be more than one breakpoint at the same offset with different handlers, but we dont handle that case for now.
addEventListener("clearBreakpoint", event => {
const {spidermonkeyId, scriptId, offset} = event;
const script = sourceIdsToScripts.get(spidermonkeyId);
function setClearBreakpointRecursive(script) {
if (script.sourceStart == scriptId) {
// <https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html#clearallbreakpoints-offset>
// If the instance refers to a JSScript, remove all breakpoints set in this script at that offset.
script.clearAllBreakpoints(offset);
return;
}
for (const child of script.getChildScripts()) {
setClearBreakpointRecursive(child);
}
}
setClearBreakpointRecursive(script);
});