Skip to main content

script/dom/debugger/
debuggerresumeevent.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 std::fmt::Debug;
6
7use dom_struct::dom_struct;
8use js::context::JSContext;
9use script_bindings::domstring::TracedDOMString;
10use script_bindings::reflector::reflect_dom_object;
11use script_bindings::str::DOMString;
12
13use crate::dom::bindings::codegen::Bindings::DebuggerResumeEventBinding::DebuggerResumeEventMethods;
14use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
15use crate::dom::bindings::root::DomRoot;
16use crate::dom::event::Event;
17use crate::dom::types::GlobalScope;
18
19#[dom_struct]
20/// Event for Rust → JS calls in [`crate::dom::debugger::DebuggerGlobalScope`].
21pub(crate) struct DebuggerResumeEvent {
22    event: Event,
23    resume_limit_type: Option<TracedDOMString>,
24    frame_actor_id: Option<TracedDOMString>,
25}
26
27impl DebuggerResumeEvent {
28    pub(crate) fn new(
29        cx: &mut JSContext,
30        debugger_global: &GlobalScope,
31        resume_limit_type: Option<DOMString>,
32        frame_actor_id: Option<DOMString>,
33    ) -> DomRoot<Self> {
34        let result = Box::new(Self {
35            event: Event::new_inherited(),
36            resume_limit_type: resume_limit_type.map(|domstring| domstring.traced()),
37            frame_actor_id: frame_actor_id.map(|domstring| domstring.traced()),
38        });
39        let result = reflect_dom_object(cx, result, debugger_global);
40        result.event.init_event("resume".into(), false, false);
41
42        result
43    }
44}
45
46impl DebuggerResumeEventMethods<crate::DomTypeHolder> for DebuggerResumeEvent {
47    // check-tidy: no specs after this line
48    fn IsTrusted(&self) -> bool {
49        self.event.IsTrusted()
50    }
51
52    fn GetResumeLimitType(&self) -> Option<DOMString> {
53        self.resume_limit_type
54            .clone()
55            .map(|domstring| domstring.root())
56    }
57
58    fn GetFrameActorID(&self) -> Option<DOMString> {
59        self.frame_actor_id
60            .clone()
61            .map(|domstring| domstring.root())
62    }
63}
64
65impl Debug for DebuggerResumeEvent {
66    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67        f.debug_struct("DebuggerResumeEvent").finish()
68    }
69}