diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index 4f02a7952b7..6c4ba3d8c7a 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -46,6 +46,10 @@ impl<'a> LocationMethods for JSRef<'a, Location> { UrlHelper::Href(&self.get_url()) } + fn Pathname(self) -> USVString { + UrlHelper::Pathname(&self.get_url()) + } + fn Stringify(self) -> DOMString { self.Href().0 } diff --git a/components/script/dom/urlhelper.rs b/components/script/dom/urlhelper.rs index c83e65c98b2..3b53746bd85 100644 --- a/components/script/dom/urlhelper.rs +++ b/components/script/dom/urlhelper.rs @@ -4,7 +4,7 @@ use dom::bindings::str::USVString; -use url::Url; +use url::{Url, SchemeData}; use std::borrow::ToOwned; @@ -31,6 +31,15 @@ impl UrlHelper { }) } + pub fn Pathname(url: &Url) -> USVString { + // https://url.spec.whatwg.org/#dom-urlutils-pathname + // FIXME: Url null check is skipped for now + USVString(match url.scheme_data { + SchemeData::NonRelative(ref scheme_data) => scheme_data.clone(), + SchemeData::Relative(..) => url.serialize_path().unwrap() + }) + } + /// https://html.spec.whatwg.org/multipage/browsers.html#same-origin pub fn SameOrigin(urlA: &Url, urlB: &Url) -> bool { if urlA.host() != urlB.host() { diff --git a/components/script/dom/webidls/URLUtils.webidl b/components/script/dom/webidls/URLUtils.webidl index bdeca5aeabf..29d060c344c 100644 --- a/components/script/dom/webidls/URLUtils.webidl +++ b/components/script/dom/webidls/URLUtils.webidl @@ -16,6 +16,7 @@ interface URLUtils { // attribute USVString hostname; // attribute USVString port; // attribute USVString pathname; + readonly attribute USVString pathname; // attribute USVString search; readonly attribute USVString search; // attribute URLSearchParams searchParams;