script/dom/webrtc/
rtcerrorevent.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use js::rust::HandleObject;
8use script_bindings::reflector::reflect_dom_object_with_proto_and_cx;
9use stylo_atoms::Atom;
10
11use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
12use crate::dom::bindings::codegen::Bindings::RTCErrorEventBinding::{
13 RTCErrorEventInit, RTCErrorEventMethods,
14};
15use crate::dom::bindings::inheritance::Castable;
16use crate::dom::bindings::root::{Dom, DomRoot};
17use crate::dom::bindings::str::DOMString;
18use crate::dom::event::Event;
19use crate::dom::rtcerror::RTCError;
20use crate::dom::window::Window;
21
22#[dom_struct]
23pub(crate) struct RTCErrorEvent {
24 event: Event,
25 error: Dom<RTCError>,
26}
27
28impl RTCErrorEvent {
29 fn new_inherited(error: &RTCError) -> RTCErrorEvent {
30 RTCErrorEvent {
31 event: Event::new_inherited(),
32 error: Dom::from_ref(error),
33 }
34 }
35
36 pub(crate) fn new(
37 cx: &mut JSContext,
38 window: &Window,
39 type_: Atom,
40 bubbles: bool,
41 cancelable: bool,
42 error: &RTCError,
43 ) -> DomRoot<RTCErrorEvent> {
44 Self::new_with_proto(cx, window, None, type_, bubbles, cancelable, error)
45 }
46
47 fn new_with_proto(
48 cx: &mut JSContext,
49 window: &Window,
50 proto: Option<HandleObject>,
51 type_: Atom,
52 bubbles: bool,
53 cancelable: bool,
54 error: &RTCError,
55 ) -> DomRoot<RTCErrorEvent> {
56 let event = reflect_dom_object_with_proto_and_cx(
57 Box::new(RTCErrorEvent::new_inherited(error)),
58 window,
59 proto,
60 cx,
61 );
62 {
63 let event = event.upcast::<Event>();
64 event.init_event(type_, bubbles, cancelable);
65 }
66 event
67 }
68}
69
70impl RTCErrorEventMethods<crate::DomTypeHolder> for RTCErrorEvent {
71 fn Constructor(
73 cx: &mut JSContext,
74 window: &Window,
75 proto: Option<HandleObject>,
76 type_: DOMString,
77 init: &RTCErrorEventInit,
78 ) -> DomRoot<RTCErrorEvent> {
79 RTCErrorEvent::new_with_proto(
80 cx,
81 window,
82 proto,
83 Atom::from(type_),
84 init.parent.bubbles,
85 init.parent.cancelable,
86 &init.error,
87 )
88 }
89
90 fn Error(&self) -> DomRoot<RTCError> {
92 DomRoot::from_ref(&*self.error)
93 }
94
95 fn IsTrusted(&self) -> bool {
97 self.event.IsTrusted()
98 }
99}