Skip to content

Commit

Permalink
add readonly pathname function in location
Browse files Browse the repository at this point in the history
pathname function implemented in UrlHelper
'url is null' check is skip for now
  • Loading branch information
yodalee committed Apr 4, 2015
1 parent db104b7 commit 77f3b25
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/script/dom/location.rs
Expand Up @@ -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
}
Expand Down
11 changes: 10 additions & 1 deletion components/script/dom/urlhelper.rs
Expand Up @@ -4,7 +4,7 @@

use dom::bindings::str::USVString;

use url::Url;
use url::{Url, SchemeData};

use std::borrow::ToOwned;

Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/webidls/URLUtils.webidl
Expand Up @@ -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;
Expand Down

0 comments on commit 77f3b25

Please sign in to comment.