servo: Merge #10430 - Remove URL.base (it was removed from the spec) (from stjepang:remove-url-base); r=Ms2ger
authorStjepan Glavina <stjepang@gmail.com>
Thu, 07 Apr 2016 15:09:25 +0500
changeset 338439 7dec983c0b36d3b5c04b44f3ce441c409c2c495e
parent 338438 3a3e291c4b143d1f0ae8405d2a0dcd29b7360554
child 338440 f445583eb05d59aea3226c877aa4798a6e730552
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
servo: Merge #10430 - Remove URL.base (it was removed from the spec) (from stjepang:remove-url-base); r=Ms2ger Spec: https://url.spec.whatwg.org/#concept-url-url Discussion on IRC: http://logs.glob.uno/?c=mozilla%23servo&s=1+Apr+2016&e=1+Apr+2016#c397947 r? @nox Source-Repo: https://github.com/servo/servo Source-Revision: 51766d480432cd9723ef52a710cce5a8308d28a0
servo/components/script/dom/url.rs
--- a/servo/components/script/dom/url.rs
+++ b/servo/components/script/dom/url.rs
@@ -8,46 +8,42 @@ use dom::bindings::error::{Error, ErrorR
 use dom::bindings::global::GlobalRef;
 use dom::bindings::js::{JS, MutNullableHeap, Root};
 use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
 use dom::bindings::str::USVString;
 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)
     }
 
     pub fn set_query(&self, query: String) {
         self.url.borrow_mut().query = Some(query);
     }
 }
 
@@ -67,26 +63,32 @@ impl URL {
                     Ok(base) => Some(base),
                     Err(error) => {
                         // Step 2.2.
                         return Err(Error::Type(format!("could not parse base: {}", error)));
                     }
                 }
         };
         // 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.
         Ok(result)
     }
 
     // https://url.spec.whatwg.org/#dom-url-domaintoasciidomain
     pub fn DomainToASCII(_: GlobalRef, origin: USVString) -> USVString {
@@ -135,17 +137,17 @@ impl URLMethods for URL {
 
     // https://url.spec.whatwg.org/#dom-url-href
     fn Href(&self) -> USVString {
         UrlHelper::Href(&self.url.borrow())
     }
 
     // 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(())
             },
             Err(error) => {
                 Err(Error::Type(format!("could not parse URL: {}", error)))
             },
         }
@@ -224,16 +226,8 @@ impl URLMethods for URL {
         UrlHelper::Username(&self.url.borrow())
     }
 
     // https://url.spec.whatwg.org/#dom-url-username
     fn SetUsername(&self, value: USVString) {
         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)
-}