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}
24
25impl DebuggerEvalEvent {
26    pub(crate) fn new(
27        debugger_global: &GlobalScope,
28        code: DOMString,
29        pipeline_id: &PipelineId,
30        worker_id: Option<DOMString>,
31        can_gc: CanGc,
32    ) -> DomRoot<Self> {
33        let result = Box::new(Self {
34            event: Event::new_inherited(),
35            code,
36            pipeline_id: Dom::from_ref(pipeline_id),
37            worker_id,
38        });
39        let result = reflect_dom_object(result, debugger_global, can_gc);
40        result.event.init_event("eval".into(), false, false);
41
42        result
43    }
44}
45
46impl DebuggerEvalEventMethods<crate::DomTypeHolder> for DebuggerEvalEvent {
47    // check-tidy: no specs after this line
48    fn Code(&self) -> DOMString {
49        self.code.clone()
50    }
51
52    fn PipelineId(
53        &self,
54    ) -> DomRoot<<crate::DomTypeHolder as script_bindings::DomTypes>::PipelineId> {
55        DomRoot::from_ref(&self.pipeline_id)
56    }
57
58    fn GetWorkerId(&self) -> Option<DOMString> {
59        self.worker_id.clone()
60    }
61
62    fn IsTrusted(&self) -> bool {
63        self.event.IsTrusted()
64    }
65}