devtools/actors/
breakpoint.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use serde::Serialize;
6
7use crate::EmptyReplyMsg;
8use crate::actor::{Actor, ActorError};
9use crate::protocol::ClientRequest;
10
11#[derive(Serialize)]
12pub struct BreakpointListActorMsg {
13    actor: String,
14}
15
16pub struct BreakpointListActor {
17    name: String,
18}
19
20impl Actor for BreakpointListActor {
21    fn name(&self) -> String {
22        self.name.clone()
23    }
24
25    fn handle_message(
26        &self,
27        request: ClientRequest,
28        _registry: &crate::actor::ActorRegistry,
29        msg_type: &str,
30        _msg: &serde_json::Map<String, serde_json::Value>,
31        _stream_id: crate::StreamId,
32    ) -> Result<(), ActorError> {
33        match msg_type {
34            // Client wants to set a breakpoint.
35            // Seems to be infallible, unlike the thread actor’s `setBreakpoint`.
36            // <https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#breakpoints>
37            "setBreakpoint" => {
38                let msg = EmptyReplyMsg { from: self.name() };
39                request.reply_final(&msg)?
40            },
41            "setActiveEventBreakpoints" => {
42                let msg = EmptyReplyMsg { from: self.name() };
43                request.reply_final(&msg)?
44            },
45            "removeBreakpoint" => {
46                let msg = EmptyReplyMsg { from: self.name() };
47                request.reply_final(&msg)?
48            },
49            _ => return Err(ActorError::UnrecognizedPacketType),
50        };
51        Ok(())
52    }
53}
54
55impl BreakpointListActor {
56    pub fn new(name: String) -> Self {
57        Self { name }
58    }
59
60    pub fn encodable(&self) -> BreakpointListActorMsg {
61        BreakpointListActorMsg { actor: self.name() }
62    }
63}