script/dom/webrtc/
rtcerror.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use js::rust::HandleObject;
8use script_bindings::reflector::reflect_dom_object_with_proto_and_cx;
9
10use crate::dom::bindings::codegen::Bindings::RTCErrorBinding::{
11 RTCErrorDetailType, RTCErrorInit, RTCErrorMethods,
12};
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::bindings::str::DOMString;
15use crate::dom::domexception::DOMException;
16use crate::dom::window::Window;
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 cx: &mut JSContext,
44 window: &Window,
45 init: &RTCErrorInit,
46 message: DOMString,
47 ) -> DomRoot<RTCError> {
48 Self::new_with_proto(cx, window, None, init, message)
49 }
50
51 fn new_with_proto(
52 cx: &mut JSContext,
53 window: &Window,
54 proto: Option<HandleObject>,
55 init: &RTCErrorInit,
56 message: DOMString,
57 ) -> DomRoot<RTCError> {
58 reflect_dom_object_with_proto_and_cx(
59 Box::new(RTCError::new_inherited(init, message)),
60 window,
61 proto,
62 cx,
63 )
64 }
65}
66
67impl RTCErrorMethods<crate::DomTypeHolder> for RTCError {
68 fn Constructor(
70 cx: &mut JSContext,
71 window: &Window,
72 proto: Option<HandleObject>,
73 init: &RTCErrorInit,
74 message: DOMString,
75 ) -> DomRoot<RTCError> {
76 RTCError::new_with_proto(cx, window, proto, init, message)
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}