Skip to content

Commit

Permalink
Remove URL.base (it was removed from the spec)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stjepan Glavina committed Apr 6, 2016
1 parent e36e3be commit 321cfcd
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions components/script/dom/url.rs
Expand Up @@ -13,36 +13,32 @@ use dom::urlhelper::UrlHelper;
use dom::urlsearchparams::URLSearchParams;
use std::borrow::ToOwned;
use std::default::Default;
use url::{Host, ParseResult, Url, UrlParser};
use url::{Host, Url, UrlParser};
use util::str::DOMString;

// https://url.spec.whatwg.org/#url
#[dom_struct]
pub struct URL {
reflector_: Reflector,

// https://url.spec.whatwg.org/#concept-urlutils-url
// https://url.spec.whatwg.org/#concept-url-url
url: DOMRefCell<Url>,

// https://url.spec.whatwg.org/#concept-urlutils-get-the-base
base: Option<Url>,

// https://url.spec.whatwg.org/#dom-url-searchparams
search_params: MutNullableHeap<JS<URLSearchParams>>,
}

impl URL {
fn new_inherited(url: Url, base: Option<Url>) -> URL {
fn new_inherited(url: Url) -> URL {
URL {
reflector_: Reflector::new(),
url: DOMRefCell::new(url),
base: base,
search_params: Default::default(),
}
}

pub fn new(global: GlobalRef, url: Url, base: Option<Url>) -> Root<URL> {
reflect_dom_object(box URL::new_inherited(url, base),
pub fn new(global: GlobalRef, url: Url) -> Root<URL> {
reflect_dom_object(box URL::new_inherited(url),
global, URLBinding::Wrap)
}

Expand Down Expand Up @@ -72,16 +68,22 @@ impl URL {
}
};
// Step 3.
let parsed_url = match parse_with_base(url, parsed_base.as_ref()) {
Ok(url) => url,
Err(error) => {
// Step 4.
return Err(Error::Type(format!("could not parse URL: {}", error)));
let parsed_url = {
let mut parser = UrlParser::new();
if let Some(parsed_base) = parsed_base.as_ref() {
parser.base_url(parsed_base);
}
match parser.parse(&url.0) {
Ok(url) => url,
Err(error) => {
// Step 4.
return Err(Error::Type(format!("could not parse URL: {}", error)));
}
}
};
// Step 5: Skip (see step 8 below).
// Steps 6-7.
let result = URL::new(global, parsed_url, parsed_base);
let result = URL::new(global, parsed_url);
// Step 8: Instead of construcing a new `URLSearchParams` object here, construct it
// on-demand inside `URL::SearchParams`.
// Step 9.
Expand Down Expand Up @@ -140,7 +142,7 @@ impl URLMethods for URL {

// https://url.spec.whatwg.org/#dom-url-href
fn SetHref(&self, value: USVString) -> ErrorResult {
match parse_with_base(value, self.base.as_ref()) {
match Url::parse(&value.0) {
Ok(url) => {
*self.url.borrow_mut() = url;
Ok(())
Expand Down Expand Up @@ -229,11 +231,3 @@ impl URLMethods for URL {
UrlHelper::SetUsername(&mut self.url.borrow_mut(), value);
}
}

fn parse_with_base(input: USVString, base: Option<&Url>) -> ParseResult<Url> {
let mut parser = UrlParser::new();
if let Some(base) = base {
parser.base_url(base);
}
parser.parse(&input.0)
}

0 comments on commit 321cfcd

Please sign in to comment.