Skip to main content

script/dom/debugger/
debuggerevalevent.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 dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::reflector::reflect_dom_object_with_cx;
8use script_bindings::str::DOMString;
9
10use crate::dom::bindings::codegen::Bindings::DebuggerEvalEventBinding::DebuggerEvalEventMethods;
11use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
12use crate::dom::bindings::root::{Dom, DomRoot};
13use crate::dom::event::Event;
14use crate::dom::types::{GlobalScope, PipelineId};
15
16#[dom_struct]
17/// Event for Rust → JS calls in [`crate::dom::debugger::DebuggerGlobalScope`].
18pub(crate) struct DebuggerEvalEvent {
19    event: Event,
20    code: DOMString,
21    pipeline_id: Dom<PipelineId>,
22    worker_id: Option<DOMString>,
23    frame_actor_id: Option<DOMString>,
24    eager: bool,
25}
26
27impl DebuggerEvalEvent {
28    pub(crate) fn new(
29        cx: &mut JSContext,
30        debugger_global: &GlobalScope,
31        code: DOMString,
32        pipeline_id: &PipelineId,
33        worker_id: Option<DOMString>,
34        frame_actor_id: Option<DOMString>,
35        eager: bool,
36    ) -> DomRoot<Self> {
37        let result = Box::new(Self {
38            event: Event::new_inherited(),
39            code,
40            pipeline_id: Dom::from_ref(pipeline_id),
41            worker_id,
42            frame_actor_id,
43            eager,
44        });
45        let result = reflect_dom_object_with_cx(result, debugger_global, cx);
46        result.event.init_event("eval".into(), false, false);
47
48        result
49    }
50}
51
52impl DebuggerEvalEventMethods<crate::DomTypeHolder> for DebuggerEvalEvent {
53    // check-tidy: no specs after this line
54    fn Code(&self) -> DOMString {
55        self.code.clone()
56    }
57
58    fn PipelineId(
59        &self,
60    ) -> DomRoot<<crate::DomTypeHolder as script_bindings::DomTypes>::PipelineId> {
61        DomRoot::from_ref(&self.pipeline_id)
62    }
63
64    fn GetWorkerId(&self) -> Option<DOMString> {
65        self.worker_id.clone()
66    }
67
68    fn GetFrameActorId(&self) -> Option<DOMString> {
69        self.frame_actor_id.clone()
70    }
71
72    fn Eager(&self) -> bool {
73        self.eager
74    }
75
76    fn IsTrusted(&self) -> bool {
77        self.event.IsTrusted()
78    }
79}