Skip to main content

script/dom/webrtc/
rtcerror.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 js::context::JSContext;
7use js::rust::HandleObject;
8use script_bindings::reflector::reflect_dom_object_with_proto;
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(
33                message,
34                DOMString::from_static("OperationError"),
35            ),
36            error_detail: init.errorDetail,
37            sdp_line_number: init.sdpLineNumber,
38            http_request_status_code: init.httpRequestStatusCode,
39            sctp_cause_code: init.sctpCauseCode,
40            received_alert: init.receivedAlert,
41            sent_alert: init.sentAlert,
42        }
43    }
44
45    pub(crate) fn new(
46        cx: &mut JSContext,
47        window: &Window,
48        init: &RTCErrorInit,
49        message: DOMString,
50    ) -> DomRoot<RTCError> {
51        Self::new_with_proto(cx, window, None, init, message)
52    }
53
54    fn new_with_proto(
55        cx: &mut JSContext,
56        window: &Window,
57        proto: Option<HandleObject>,
58        init: &RTCErrorInit,
59        message: DOMString,
60    ) -> DomRoot<RTCError> {
61        reflect_dom_object_with_proto(
62            cx,
63            Box::new(RTCError::new_inherited(init, message)),
64            window,
65            proto,
66        )
67    }
68}
69
70impl RTCErrorMethods<crate::DomTypeHolder> for RTCError {
71    /// <https://www.w3.org/TR/webrtc/#dom-rtcerror-constructor>
72    fn Constructor(
73        cx: &mut JSContext,
74        window: &Window,
75        proto: Option<HandleObject>,
76        init: &RTCErrorInit,
77        message: DOMString,
78    ) -> DomRoot<RTCError> {
79        RTCError::new_with_proto(cx, window, proto, init, message)
80    }
81
82    /// <https://www.w3.org/TR/webrtc/#dom-rtcerror-errordetail>
83    fn ErrorDetail(&self) -> RTCErrorDetailType {
84        self.error_detail
85    }
86
87    /// <https://www.w3.org/TR/webrtc/#dom-rtcerror-sdplinenumber>
88    fn GetSdpLineNumber(&self) -> Option<i32> {
89        self.sdp_line_number
90    }
91
92    /// <https://www.w3.org/TR/webrtc/#dom-rtcerror>
93    fn GetHttpRequestStatusCode(&self) -> Option<i32> {
94        self.http_request_status_code
95    }
96
97    /// <https://www.w3.org/TR/webrtc/#dom-rtcerror-sctpcausecode>
98    fn GetSctpCauseCode(&self) -> Option<i32> {
99        self.sctp_cause_code
100    }
101
102    /// <https://www.w3.org/TR/webrtc/#dom-rtcerror-receivedalert>
103    fn GetReceivedAlert(&self) -> Option<u32> {
104        self.received_alert
105    }
106
107    /// <https://www.w3.org/TR/webrtc/#dom-rtcerror-sentalert>
108    fn GetSentAlert(&self) -> Option<u32> {
109        self.sent_alert
110    }
111}