Skip to main content

script/dom/geolocation/
geolocationpositionerror.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 script_bindings::codegen::GenericBindings::GeolocationPositionErrorBinding::GeolocationPositionErrorConstants::{PERMISSION_DENIED, POSITION_UNAVAILABLE, TIMEOUT};
8use script_bindings::codegen::GenericBindings::GeolocationPositionErrorBinding::GeolocationPositionErrorMethods;
9use script_bindings::domstring::TracedDOMString;
10use script_bindings::reflector::{Reflector, reflect_dom_object};
11use script_bindings::root::DomRoot;
12use script_bindings::str::DOMString;
13
14use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder;
15use crate::dom::globalscope::GlobalScope;
16
17#[dom_struct]
18pub struct GeolocationPositionError {
19    reflector_: Reflector,
20    code: u16,
21    message: TracedDOMString,
22}
23
24impl GeolocationPositionError {
25    fn new_inherited(code: u16, message: DOMString) -> Self {
26        GeolocationPositionError {
27            reflector_: Reflector::new(),
28            code,
29            message: message.traced(),
30        }
31    }
32
33    fn new(
34        cx: &mut JSContext,
35        global: &GlobalScope,
36        code: u16,
37        message: DOMString,
38    ) -> DomRoot<Self> {
39        reflect_dom_object(cx, Box::new(Self::new_inherited(code, message)), global)
40    }
41
42    pub(crate) fn permission_denied(
43        cx: &mut JSContext,
44        global: &GlobalScope,
45        message: DOMString,
46    ) -> DomRoot<Self> {
47        Self::new(cx, global, PERMISSION_DENIED, message)
48    }
49
50    pub(crate) fn position_unavailable(
51        cx: &mut JSContext,
52        global: &GlobalScope,
53        message: DOMString,
54    ) -> DomRoot<Self> {
55        Self::new(cx, global, POSITION_UNAVAILABLE, message)
56    }
57
58    #[expect(unused)]
59    pub(crate) fn timeout(
60        cx: &mut JSContext,
61        global: &GlobalScope,
62        message: DOMString,
63    ) -> DomRoot<Self> {
64        Self::new(cx, global, TIMEOUT, message)
65    }
66}
67
68impl GeolocationPositionErrorMethods<DomTypeHolder> for GeolocationPositionError {
69    fn Code(&self) -> u16 {
70        self.code
71    }
72
73    fn Message(&self) -> DOMString {
74        self.message.clone().root()
75    }
76}