script/dom/webrtc/
rtcerror.rs1use dom_struct::dom_struct;
6use js::rust::HandleObject;
7
8use crate::dom::bindings::codegen::Bindings::RTCErrorBinding::{
9 RTCErrorDetailType, RTCErrorInit, RTCErrorMethods,
10};
11use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::bindings::str::DOMString;
14use crate::dom::domexception::DOMException;
15use crate::dom::window::Window;
16use crate::script_runtime::CanGc;
17
18#[dom_struct]
19pub(crate) struct RTCError {
20 exception: DOMException,
21 error_detail: RTCErrorDetailType,
22 sdp_line_number: Option<i32>,
23 http_request_status_code: Option<i32>,
24 sctp_cause_code: Option<i32>,
25 received_alert: Option<u32>,
26 sent_alert: Option<u32>,
27}
28
29impl RTCError {
30 fn new_inherited(init: &RTCErrorInit, message: DOMString) -> RTCError {
31 RTCError {
32 exception: DOMException::new_inherited(message, "OperationError".into()),
33 error_detail: init.errorDetail,
34 sdp_line_number: init.sdpLineNumber,
35 http_request_status_code: init.httpRequestStatusCode,
36 sctp_cause_code: init.sctpCauseCode,
37 received_alert: init.receivedAlert,
38 sent_alert: init.sentAlert,
39 }
40 }
41
42 pub(crate) fn new(
43 window: &Window,
44 init: &RTCErrorInit,
45 message: DOMString,
46 can_gc: CanGc,
47 ) -> DomRoot<RTCError> {
48 Self::new_with_proto(window, None, init, message, can_gc)
49 }
50
51 fn new_with_proto(
52 window: &Window,
53 proto: Option<HandleObject>,
54 init: &RTCErrorInit,
55 message: DOMString,
56 can_gc: CanGc,
57 ) -> DomRoot<RTCError> {
58 reflect_dom_object_with_proto(
59 Box::new(RTCError::new_inherited(init, message)),
60 window,
61 proto,
62 can_gc,
63 )
64 }
65}
66
67impl RTCErrorMethods<crate::DomTypeHolder> for RTCError {
68 fn Constructor(
70 window: &Window,
71 proto: Option<HandleObject>,
72 can_gc: CanGc,
73 init: &RTCErrorInit,
74 message: DOMString,
75 ) -> DomRoot<RTCError> {
76 RTCError::new_with_proto(window, proto, init, message, can_gc)
77 }
78
79 fn ErrorDetail(&self) -> RTCErrorDetailType {
81 self.error_detail
82 }
83
84 fn GetSdpLineNumber(&self) -> Option<i32> {
86 self.sdp_line_number
87 }
88
89 fn GetHttpRequestStatusCode(&self) -> Option<i32> {
91 self.http_request_status_code
92 }
93
94 fn GetSctpCauseCode(&self) -> Option<i32> {
96 self.sctp_cause_code
97 }
98
99 fn GetReceivedAlert(&self) -> Option<u32> {
101 self.received_alert
102 }
103
104 fn GetSentAlert(&self) -> Option<u32> {
106 self.sent_alert
107 }
108}