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