Files
servo/components/script/dom/geolocation/geolocationpositionerror.rs
Ashwin Naren 2c96178ff1 geolocation: Support errorCallback (#42295)
Support `errorCallback` in geolocation position request functions and
throw the necessary errors.

Testing: Passes 3 more WPT tests
Fixes: Partially #38903

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2026-02-03 02:33:39 +00:00

72 lines
2.2 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use script_bindings::codegen::GenericBindings::GeolocationPositionErrorBinding::GeolocationPositionErrorConstants::{PERMISSION_DENIED, POSITION_UNAVAILABLE, TIMEOUT};
use script_bindings::codegen::GenericBindings::GeolocationPositionErrorBinding::GeolocationPositionErrorMethods;
use script_bindings::reflector::Reflector;
use script_bindings::root::DomRoot;
use script_bindings::script_runtime::CanGc;
use script_bindings::str::DOMString;
use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::globalscope::GlobalScope;
#[dom_struct]
pub struct GeolocationPositionError {
reflector_: Reflector,
code: u16,
message: DOMString,
}
impl GeolocationPositionError {
fn new_inherited(code: u16, message: DOMString) -> Self {
GeolocationPositionError {
reflector_: Reflector::new(),
code,
message,
}
}
fn new(global: &GlobalScope, code: u16, message: DOMString, can_gc: CanGc) -> DomRoot<Self> {
reflect_dom_object(Box::new(Self::new_inherited(code, message)), global, can_gc)
}
pub(crate) fn permission_denied(
global: &GlobalScope,
message: DOMString,
can_gc: CanGc,
) -> DomRoot<Self> {
Self::new(global, PERMISSION_DENIED, message, can_gc)
}
pub(crate) fn position_unavailable(
global: &GlobalScope,
message: DOMString,
can_gc: CanGc,
) -> DomRoot<Self> {
Self::new(global, POSITION_UNAVAILABLE, message, can_gc)
}
#[expect(unused)]
pub(crate) fn timeout(
global: &GlobalScope,
message: DOMString,
can_gc: CanGc,
) -> DomRoot<Self> {
Self::new(global, TIMEOUT, message, can_gc)
}
}
impl GeolocationPositionErrorMethods<DomTypeHolder> for GeolocationPositionError {
fn Code(&self) -> u16 {
self.code
}
fn Message(&self) -> DOMString {
self.message.clone()
}
}