use dom_struct::dom_struct;
use js::context::JSContext;
use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
use servo_url::{ImmutableOrigin, ServoUrl};
use crate::dom::bindings::codegen::Bindings::WorkerLocationBinding::WorkerLocationMethods;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::USVString;
use crate::dom::urlhelper::UrlHelper;
use crate::dom::workerglobalscope::WorkerGlobalScope;
#[dom_struct]
pub(crate) struct WorkerLocation {
reflector_: Reflector,
#[no_trace]
url: ServoUrl,
}
impl WorkerLocation {
fn new_inherited(url: ServoUrl) -> WorkerLocation {
WorkerLocation {
reflector_: Reflector::new(),
url,
}
}
pub(crate) fn new(
cx: &mut JSContext,
global: &WorkerGlobalScope,
url: ServoUrl,
) -> DomRoot<WorkerLocation> {
reflect_dom_object_with_cx(Box::new(WorkerLocation::new_inherited(url)), global, cx)
}
#[expect(dead_code)]
pub(crate) fn origin(&self) -> ImmutableOrigin {
self.url.origin()
}
}
impl WorkerLocationMethods<crate::DomTypeHolder> for WorkerLocation {
fn Hash(&self) -> USVString {
UrlHelper::Hash(&self.url)
}
fn Host(&self) -> USVString {
UrlHelper::Host(&self.url)
}
fn Hostname(&self) -> USVString {
UrlHelper::Hostname(&self.url)
}
fn Href(&self) -> USVString {
UrlHelper::Href(&self.url)
}
fn Origin(&self) -> USVString {
UrlHelper::Origin(&self.url)
}
fn Pathname(&self) -> USVString {
UrlHelper::Pathname(&self.url)
}
fn Port(&self) -> USVString {
UrlHelper::Port(&self.url)
}
fn Protocol(&self) -> USVString {
UrlHelper::Protocol(&self.url)
}
fn Search(&self) -> USVString {
UrlHelper::Search(&self.url)
}
}