mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Remove URL.base (it was removed from the spec)
Spec: https://url.spec.whatwg.org/#concept-url-url
This commit is contained in:
parent
e36e3be855
commit
321cfcd16c
1 changed files with 18 additions and 24 deletions
|
@ -13,7 +13,7 @@ use dom::urlhelper::UrlHelper;
|
||||||
use dom::urlsearchparams::URLSearchParams;
|
use dom::urlsearchparams::URLSearchParams;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use url::{Host, ParseResult, Url, UrlParser};
|
use url::{Host, Url, UrlParser};
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#url
|
// https://url.spec.whatwg.org/#url
|
||||||
|
@ -21,28 +21,24 @@ use util::str::DOMString;
|
||||||
pub struct URL {
|
pub struct URL {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#concept-urlutils-url
|
// https://url.spec.whatwg.org/#concept-url-url
|
||||||
url: DOMRefCell<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
|
// https://url.spec.whatwg.org/#dom-url-searchparams
|
||||||
search_params: MutNullableHeap<JS<URLSearchParams>>,
|
search_params: MutNullableHeap<JS<URLSearchParams>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl URL {
|
impl URL {
|
||||||
fn new_inherited(url: Url, base: Option<Url>) -> URL {
|
fn new_inherited(url: Url) -> URL {
|
||||||
URL {
|
URL {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
url: DOMRefCell::new(url),
|
url: DOMRefCell::new(url),
|
||||||
base: base,
|
|
||||||
search_params: Default::default(),
|
search_params: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(global: GlobalRef, url: Url, base: Option<Url>) -> Root<URL> {
|
pub fn new(global: GlobalRef, url: Url) -> Root<URL> {
|
||||||
reflect_dom_object(box URL::new_inherited(url, base),
|
reflect_dom_object(box URL::new_inherited(url),
|
||||||
global, URLBinding::Wrap)
|
global, URLBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,16 +68,22 @@ impl URL {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Step 3.
|
// Step 3.
|
||||||
let parsed_url = match parse_with_base(url, parsed_base.as_ref()) {
|
let parsed_url = {
|
||||||
Ok(url) => url,
|
let mut parser = UrlParser::new();
|
||||||
Err(error) => {
|
if let Some(parsed_base) = parsed_base.as_ref() {
|
||||||
// Step 4.
|
parser.base_url(parsed_base);
|
||||||
return Err(Error::Type(format!("could not parse URL: {}", error)));
|
}
|
||||||
|
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).
|
// Step 5: Skip (see step 8 below).
|
||||||
// Steps 6-7.
|
// 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
|
// Step 8: Instead of construcing a new `URLSearchParams` object here, construct it
|
||||||
// on-demand inside `URL::SearchParams`.
|
// on-demand inside `URL::SearchParams`.
|
||||||
// Step 9.
|
// Step 9.
|
||||||
|
@ -140,7 +142,7 @@ impl URLMethods for URL {
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#dom-url-href
|
// https://url.spec.whatwg.org/#dom-url-href
|
||||||
fn SetHref(&self, value: USVString) -> ErrorResult {
|
fn SetHref(&self, value: USVString) -> ErrorResult {
|
||||||
match parse_with_base(value, self.base.as_ref()) {
|
match Url::parse(&value.0) {
|
||||||
Ok(url) => {
|
Ok(url) => {
|
||||||
*self.url.borrow_mut() = url;
|
*self.url.borrow_mut() = url;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -229,11 +231,3 @@ impl URLMethods for URL {
|
||||||
UrlHelper::SetUsername(&mut self.url.borrow_mut(), value);
|
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)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue