Use USVString for URLUtils and URLUtilsReadOnly.

This commit is contained in:
Ms2ger 2015-03-13 19:47:17 +01:00
parent bbbdb98897
commit 0593d77b93
5 changed files with 43 additions and 44 deletions

View file

@ -6,6 +6,7 @@ use dom::bindings::codegen::Bindings::LocationBinding;
use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods; use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods;
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::str::USVString;
use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::urlhelper::UrlHelper; use dom::urlhelper::UrlHelper;
use dom::window::Window; use dom::window::Window;
@ -41,19 +42,19 @@ impl<'a> LocationMethods for JSRef<'a, Location> {
self.window.root().r().load_url(url); self.window.root().r().load_url(url);
} }
fn Href(self) -> DOMString { fn Href(self) -> USVString {
UrlHelper::Href(&self.get_url()) UrlHelper::Href(&self.get_url())
} }
fn Stringify(self) -> DOMString { fn Stringify(self) -> DOMString {
self.Href() self.Href().0
} }
fn Search(self) -> DOMString { fn Search(self) -> USVString {
UrlHelper::Search(&self.get_url()) UrlHelper::Search(&self.get_url())
} }
fn Hash(self) -> DOMString { fn Hash(self) -> USVString {
UrlHelper::Hash(&self.get_url()) UrlHelper::Hash(&self.get_url())
} }
} }

View file

@ -2,7 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use util::str::DOMString; use dom::bindings::str::USVString;
use url::Url; use url::Url;
use std::borrow::ToOwned; use std::borrow::ToOwned;
@ -10,24 +11,24 @@ use std::borrow::ToOwned;
pub struct UrlHelper; pub struct UrlHelper;
impl UrlHelper { impl UrlHelper {
pub fn Href(url: &Url) -> DOMString { pub fn Href(url: &Url) -> USVString {
url.serialize() USVString(url.serialize())
} }
pub fn Search(url: &Url) -> DOMString { pub fn Search(url: &Url) -> USVString {
match url.query { USVString(match url.query {
None => "".to_owned(), None => "".to_owned(),
Some(ref query) if query.as_slice() == "" => "".to_owned(), Some(ref query) if query.as_slice() == "" => "".to_owned(),
Some(ref query) => format!("?{}", query) Some(ref query) => format!("?{}", query)
} })
} }
pub fn Hash(url: &Url) -> DOMString { pub fn Hash(url: &Url) -> USVString {
match url.fragment { USVString(match url.fragment {
None => "".to_owned(), None => "".to_owned(),
Some(ref hash) if hash.as_slice() == "" => "".to_owned(), Some(ref hash) if hash.as_slice() == "" => "".to_owned(),
Some(ref hash) => format!("#{}", hash) Some(ref hash) => format!("#{}", hash)
} })
} }
/// https://html.spec.whatwg.org/multipage/browsers.html#same-origin /// https://html.spec.whatwg.org/multipage/browsers.html#same-origin

View file

@ -6,21 +6,21 @@
// http://url.spec.whatwg.org/#urlutils // http://url.spec.whatwg.org/#urlutils
[NoInterfaceObject] [NoInterfaceObject]
interface URLUtils { interface URLUtils {
//stringifier attribute ScalarValueString href; //stringifier attribute USVString href;
readonly attribute DOMString href; readonly attribute USVString href;
//readonly attribute ScalarValueString origin; //readonly attribute USVString origin;
// attribute ScalarValueString protocol; // attribute USVString protocol;
// attribute ScalarValueString username; // attribute USVString username;
// attribute ScalarValueString password; // attribute USVString password;
// attribute ScalarValueString host; // attribute USVString host;
// attribute ScalarValueString hostname; // attribute USVString hostname;
// attribute ScalarValueString port; // attribute USVString port;
// attribute ScalarValueString pathname; // attribute USVString pathname;
// attribute ScalarValueString search; // attribute USVString search;
readonly attribute DOMString search; readonly attribute USVString search;
// attribute URLSearchParams searchParams; // attribute URLSearchParams searchParams;
// attribute ScalarValueString hash; // attribute USVString hash;
readonly attribute DOMString hash; readonly attribute USVString hash;
// This is only doing as well as gecko right now, bug 824857 is on file for // This is only doing as well as gecko right now, bug 824857 is on file for
// adding attribute stringifier support. // adding attribute stringifier support.

View file

@ -7,17 +7,15 @@
[NoInterfaceObject/*, [NoInterfaceObject/*,
Exposed=(Window,Worker)*/] Exposed=(Window,Worker)*/]
interface URLUtilsReadOnly { interface URLUtilsReadOnly {
//stringifier readonly attribute ScalarValueString href; //stringifier readonly attribute USVString href;
readonly attribute DOMString href; readonly attribute USVString href;
//readonly attribute ScalarValueString origin; //readonly attribute USVString origin;
//readonly attribute ScalarValueString protocol; //readonly attribute USVString protocol;
//readonly attribute ScalarValueString host; //readonly attribute USVString host;
//readonly attribute ScalarValueString hostname; //readonly attribute USVString hostname;
//readonly attribute ScalarValueString port; //readonly attribute USVString port;
//readonly attribute ScalarValueString pathname; //readonly attribute USVString pathname;
//readonly attribute ScalarValueString search; readonly attribute USVString search;
readonly attribute DOMString search; readonly attribute USVString hash;
//readonly attribute ScalarValueString hash;
readonly attribute DOMString hash;
}; };

View file

@ -6,12 +6,11 @@ use dom::bindings::codegen::Bindings::WorkerLocationBinding;
use dom::bindings::codegen::Bindings::WorkerLocationBinding::WorkerLocationMethods; use dom::bindings::codegen::Bindings::WorkerLocationBinding::WorkerLocationMethods;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::str::USVString;
use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::urlhelper::UrlHelper; use dom::urlhelper::UrlHelper;
use dom::workerglobalscope::WorkerGlobalScope; use dom::workerglobalscope::WorkerGlobalScope;
use util::str::DOMString;
use url::Url; use url::Url;
#[dom_struct] #[dom_struct]
@ -36,15 +35,15 @@ impl WorkerLocation {
} }
impl<'a> WorkerLocationMethods for JSRef<'a, WorkerLocation> { impl<'a> WorkerLocationMethods for JSRef<'a, WorkerLocation> {
fn Href(self) -> DOMString { fn Href(self) -> USVString {
UrlHelper::Href(&self.url) UrlHelper::Href(&self.url)
} }
fn Search(self) -> DOMString { fn Search(self) -> USVString {
UrlHelper::Search(&self.url) UrlHelper::Search(&self.url)
} }
fn Hash(self) -> DOMString { fn Hash(self) -> USVString {
UrlHelper::Hash(&self.url) UrlHelper::Hash(&self.url)
} }
} }