servo: Merge #10512 - Implement HTMLBaseElement attributes (from KiChjang:base-element-attr); r=Ms2ger
authorKeith Yeung <kungfukeith11@gmail.com>
Wed, 13 Apr 2016 18:22:12 +0500
changeset 338505 38338b9e8f3b2f6fbab5f326720f377aebe2c69d
parent 338504 e2508ae8a5f3480c17f1d22bc58c51471def389b
child 338506 99ef6b195fe3005b0914eecc4c148415bfebcb16
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 #10512 - Implement HTMLBaseElement attributes (from KiChjang:base-element-attr); r=Ms2ger The remaining test failure in `base_multiple.html` looks like there's a problem with the test itself (it does not have a `<base>` tag at all). Source-Repo: https://github.com/servo/servo Source-Revision: 3ad1b9134f17803f04ac94754e640e7f876799d8
servo/components/script/dom/htmlbaseelement.rs
servo/components/script/dom/webidls/HTMLBaseElement.webidl
--- a/servo/components/script/dom/htmlbaseelement.rs
+++ b/servo/components/script/dom/htmlbaseelement.rs
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
-use dom::attr::Attr;
+use dom::attr::{Attr, AttrValue};
 use dom::bindings::codegen::Bindings::HTMLBaseElementBinding;
+use dom::bindings::codegen::Bindings::HTMLBaseElementBinding::HTMLBaseElementMethods;
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::Root;
 use dom::document::Document;
 use dom::element::{AttributeMutation, Element};
 use dom::htmlelement::HTMLElement;
 use dom::node::{Node, UnbindContext, document_from_node};
 use dom::virtualmethods::VirtualMethods;
 use string_cache::Atom;
@@ -55,16 +56,43 @@ impl HTMLBaseElement {
 
         if self.upcast::<Element>().has_attribute(&atom!("href")) {
             let document = document_from_node(self);
             document.refresh_base_element();
         }
     }
 }
 
+impl HTMLBaseElementMethods for HTMLBaseElement {
+    // https://html.spec.whatwg.org/multipage/#dom-base-href
+    fn Href(&self) -> DOMString {
+        let document = document_from_node(self);
+
+        // Step 1.
+        if !self.upcast::<Element>().has_attribute(&atom!("href")) {
+            return DOMString::from(document.base_url().serialize());
+        }
+
+        // Step 2.
+        let fallback_base_url = document.fallback_base_url();
+
+        // Step 3.
+        let url = self.upcast::<Element>().get_url_attribute(&atom!("href"));
+
+        // Step 4.
+        let url_record = fallback_base_url.join(&*url);
+
+        // Step 5, 6.
+        DOMString::from(url_record.ok().map_or("".to_owned(), |record| record.serialize()))
+    }
+
+    // https://html.spec.whatwg.org/multipage/#dom-base-href
+    make_url_setter!(SetHref, "href");
+}
+
 impl VirtualMethods for HTMLBaseElement {
     fn super_type(&self) -> Option<&VirtualMethods> {
         Some(self.upcast::<HTMLElement>() as &VirtualMethods)
     }
 
     fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
         self.super_type().unwrap().attribute_mutated(attr, mutation);
         if *attr.local_name() == atom!("href") {
--- a/servo/components/script/dom/webidls/HTMLBaseElement.webidl
+++ b/servo/components/script/dom/webidls/HTMLBaseElement.webidl
@@ -1,10 +1,10 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 // https://html.spec.whatwg.org/multipage/#htmlbaseelement
 interface HTMLBaseElement : HTMLElement {
-  //         attribute DOMString href;
-  //         attribute DOMString target;
+           attribute DOMString href;
+//           attribute DOMString target;
 };