Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 8, 2014
1 parent 3a1f9bd commit 1484acb
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 45 deletions.
15 changes: 13 additions & 2 deletions components/script/dom/element.rs
Expand Up @@ -41,6 +41,7 @@ use std::cell::RefCell;
use std::default::Default;
use std::mem;
use string_cache::{Atom, Namespace};
use url::UrlParser;

#[jstraceable]
#[must_root]
Expand Down Expand Up @@ -458,8 +459,18 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {

fn get_url_attribute(self, name: &str) -> DOMString {
assert!(name == name.to_ascii_lower().as_slice());
// XXX Resolve URL.
self.get_string_attribute(name)
if !self.has_attribute(name) {
return "".to_string();
}
let url = self.get_string_attribute(name);
let doc = document_from_node(self).root();
let base = doc.url();
// https://html.spec.whatwg.org/multipage/infrastructure.html#reflect
// XXXManishearth this doesn't handle `javascript:` urls properly
match UrlParser::new().base_url(base).parse(url.as_slice()) {
Ok(parsed) => parsed.serialize(),
Err(_) => "".to_string()
}
}
fn set_url_attribute(self, name: &str, value: DOMString) {
self.set_string_attribute(name, value);
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlbuttonelement.rs
Expand Up @@ -4,12 +4,12 @@

use dom::bindings::codegen::Bindings::HTMLButtonElementBinding;
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLButtonElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, HTMLButtonElementTypeId};
use dom::element::{AttributeHandlers, HTMLButtonElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, window_from_node};
Expand Down
15 changes: 13 additions & 2 deletions components/script/dom/htmlformelement.rs
Expand Up @@ -11,7 +11,7 @@ use dom::document::Document;
use dom::element::{Element, AttributeHandlers, HTMLFormElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId};
use dom::node::{Node, ElementNodeTypeId, window_from_node};
use servo_util::str::DOMString;
use std::ascii::OwnedStrAsciiExt;

Expand Down Expand Up @@ -50,7 +50,17 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> {
make_setter!(SetAcceptCharset, "accept-charset")

// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-action
make_url_getter!(Action)
fn Action(self) -> DOMString {
let element: JSRef<Element> = ElementCast::from_ref(self);
let url = element.get_url_attribute("src");
match url.as_slice() {
"" => {
let window = window_from_node(self).root();
window.get_url().serialize()
},
_ => url
}
}

// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-action
make_setter!(SetAction, "action")
Expand Down Expand Up @@ -126,6 +136,7 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> {
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-target
make_setter!(SetTarget, "target")
}

impl Reflectable for HTMLFormElement {
fn reflector<'a>(&'a self) -> &'a Reflector {
self.htmlelement.reflector()
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlimageelement.rs
Expand Up @@ -106,7 +106,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {

make_getter!(UseMap)

make_bool_setter!(SetUseMap, "usemap")
make_setter!(SetUseMap, "usemap")

make_bool_getter!(IsMap)

Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {

make_uint_getter!(Vspace)

make_uint_setter!(SetVspace, "Vspace")
make_uint_setter!(SetVspace, "vspace")

make_getter!(LongDesc)

Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmloptgroupelement.rs
Expand Up @@ -4,12 +4,12 @@

use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding;
use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding::HTMLOptGroupElementMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLOptGroupElementDerived, HTMLOptionElementDerived};
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, HTMLOptGroupElementTypeId};
use dom::element::{AttributeHandlers, HTMLOptGroupElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId};
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlselectelement.rs
Expand Up @@ -4,14 +4,14 @@

use dom::bindings::codegen::Bindings::HTMLSelectElementBinding;
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLSelectElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::HTMLElementOrLong;
use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement::HTMLOptionElementOrHTMLOptGroupElement;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, HTMLSelectElementTypeId};
use dom::element::{AttributeHandlers, HTMLSelectElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, window_from_node};
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmltextareaelement.rs
Expand Up @@ -4,12 +4,12 @@

use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding;
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, HTMLTextAreaElementTypeId};
use dom::element::{AttributeHandlers, HTMLTextAreaElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId};
Expand Down
15 changes: 2 additions & 13 deletions components/script/dom/macros.rs
Expand Up @@ -59,21 +59,10 @@ macro_rules! make_url_getter(
fn $attr(self) -> DOMString {
use dom::element::{Element, AttributeHandlers};
use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::document::DocumentHelpers;
use dom::node::document_from_node;
use url::UrlParser;
#[allow(unused_imports)]
use std::ascii::StrAsciiExt;
let elem: JSRef<Element> = ElementCast::from_ref(self);
let action = elem.get_string_attribute($htmlname);
let doc = document_from_node(self).root();
let base = doc.url();
// https://html.spec.whatwg.org/multipage/infrastructure.html#reflect
// XXXManishearth this doesn't handle `javascript:` urls properly
match UrlParser::new().base_url(base).parse(action.as_slice()) {
Ok(parsed) => parsed.serialize(),
Err(_) => base.serialize()
}
let element: JSRef<Element> = ElementCast::from_ref(self);
element.get_url_attribute($htmlname)
}
);
($attr:ident) => {
Expand Down
18 changes: 0 additions & 18 deletions tests/content/test_script_src_attribute.html

This file was deleted.

5 comments on commit 1484acb

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at Manishearth@1484acb

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Manishearth/servo/form-stuff = 1484acb into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manishearth/servo/form-stuff = 1484acb merged ok, testing candidate = 9473127

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9473127

Please sign in to comment.