From 2176aab6425d3350bd9893fdb5bec6b53614a918 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 2 May 2015 12:52:47 +0200 Subject: [PATCH 1/5] Import string_cache::Atom into the attributes' macros --- components/script/dom/htmlbodyelement.rs | 1 - components/script/dom/htmlbuttonelement.rs | 1 - components/script/dom/htmldialogelement.rs | 1 - components/script/dom/htmlfieldsetelement.rs | 1 - components/script/dom/htmlmetaelement.rs | 1 - components/script/dom/htmlobjectelement.rs | 1 - components/script/dom/htmloptgroupelement.rs | 1 - components/script/dom/htmloptionelement.rs | 1 - components/script/dom/macros.rs | 21 +++++++++----------- 9 files changed, 9 insertions(+), 20 deletions(-) diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 817da5043f0..c716be93d39 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -19,7 +19,6 @@ use dom::virtualmethods::VirtualMethods; use dom::window::WindowHelpers; use cssparser::RGBA; -use string_cache::Atom; use util::str::{self, DOMString}; use std::borrow::ToOwned; diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 280a92c99b2..38ed9b26e74 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -26,7 +26,6 @@ use std::ascii::OwnedAsciiExt; use std::borrow::ToOwned; use util::str::DOMString; use std::cell::Cell; -use string_cache::Atom; #[jstraceable] #[derive(PartialEq, Copy, Clone)] diff --git a/components/script/dom/htmldialogelement.rs b/components/script/dom/htmldialogelement.rs index febfbc38f81..6d332530f55 100644 --- a/components/script/dom/htmldialogelement.rs +++ b/components/script/dom/htmldialogelement.rs @@ -14,7 +14,6 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; use util::str::DOMString; -use string_cache::Atom; use std::borrow::ToOwned; diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index 84c6d926bb6..27feed8eb3a 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -20,7 +20,6 @@ use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; use util::str::{DOMString, StaticStringVec}; -use string_cache::Atom; #[dom_struct] pub struct HTMLFieldSetElement { diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index 9b12cd20e4e..00390c615cc 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -12,7 +12,6 @@ use dom::element::ElementTypeId; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; use util::str::DOMString; -use string_cache::Atom; #[dom_struct] pub struct HTMLMetaElement { diff --git a/components/script/dom/htmlobjectelement.rs b/components/script/dom/htmlobjectelement.rs index bb56ee67092..df2c98ecfda 100644 --- a/components/script/dom/htmlobjectelement.rs +++ b/components/script/dom/htmlobjectelement.rs @@ -24,7 +24,6 @@ use dom::virtualmethods::VirtualMethods; use net_traits::image::base::Image; use util::str::DOMString; use std::sync::Arc; -use string_cache::Atom; #[dom_struct] pub struct HTMLObjectElement { diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs index 4b3f3baf560..f259eccf5bc 100644 --- a/components/script/dom/htmloptgroupelement.rs +++ b/components/script/dom/htmloptgroupelement.rs @@ -18,7 +18,6 @@ use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use util::str::DOMString; -use string_cache::Atom; #[dom_struct] pub struct HTMLOptGroupElement { diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index 232e5ec2dec..29ef5040641 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -22,7 +22,6 @@ use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use util::str::{DOMString, split_html_space_chars}; -use string_cache::Atom; #[dom_struct] pub struct HTMLOptionElement { diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index d66190ffada..176feb927b9 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -8,8 +8,7 @@ macro_rules! make_getter( fn $attr(self) -> DOMString { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef = ElementCast::from_ref(self); element.get_string_attribute(&Atom::from_slice($htmlname)) } @@ -25,8 +24,7 @@ macro_rules! make_bool_getter( fn $attr(self) -> bool { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. element.has_attribute(&Atom::from_slice($htmlname)) @@ -43,8 +41,7 @@ macro_rules! make_uint_getter( fn $attr(self) -> u32 { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. element.get_uint_attribute(&Atom::from_slice($htmlname), $default) @@ -64,8 +61,7 @@ macro_rules! make_url_getter( fn $attr(self) -> DOMString { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. element.get_url_attribute(&Atom::from_slice($htmlname)) @@ -84,8 +80,7 @@ macro_rules! make_url_or_base_getter( use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::window::WindowHelpers; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; let element: JSRef = ElementCast::from_ref(self); let url = element.get_url_attribute(&Atom::from_slice($htmlname)); if url.is_empty() { @@ -107,8 +102,7 @@ macro_rules! make_enumerated_getter( fn $attr(self) -> DOMString { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; - #[allow(unused_imports)] - use std::ascii::AsciiExt; + use string_cache::Atom; use std::borrow::ToOwned; let element: JSRef = ElementCast::from_ref(self); let val = element.get_string_attribute(&Atom::from_slice($htmlname)) @@ -133,6 +127,7 @@ macro_rules! make_setter( fn $attr(self, value: DOMString) { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; let element: JSRef = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not at runtime. element.set_string_attribute(&Atom::from_slice($htmlname), value) @@ -146,6 +141,7 @@ macro_rules! make_bool_setter( fn $attr(self, value: bool) { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; let element: JSRef = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not at runtime. element.set_bool_attribute(&Atom::from_slice($htmlname), value) @@ -159,6 +155,7 @@ macro_rules! make_uint_setter( fn $attr(self, value: u32) { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; let value = if value > 2147483647 { $default } else { From b86672af0c16d234150ac79297458f199c853825 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 2 May 2015 12:27:42 +0200 Subject: [PATCH 2/5] Implement HTMLAppletElement.name --- components/script/dom/htmlappletelement.rs | 27 +++- components/script/dom/macros.rs | 14 ++ components/script/dom/virtualmethods.rs | 4 + .../dom/webidls/HTMLAppletElement.webidl | 2 +- .../wpt/metadata/html/dom/interfaces.html.ini | 6 - .../html/dom/reflection-obsolete.html.ini | 129 ------------------ 6 files changed, 45 insertions(+), 137 deletions(-) diff --git a/components/script/dom/htmlappletelement.rs b/components/script/dom/htmlappletelement.rs index 4ef0bc6cd2e..585df5d5273 100644 --- a/components/script/dom/htmlappletelement.rs +++ b/components/script/dom/htmlappletelement.rs @@ -3,13 +3,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::HTMLAppletElementBinding; +use dom::bindings::codegen::Bindings::HTMLAppletElementBinding::HTMLAppletElementMethods; + +use dom::attr::AttrValue; use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived; +use dom::bindings::codegen::InheritTypes::HTMLElementCast; use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; -use dom::element::ElementTypeId; +use dom::element::{AttributeHandlers, ElementTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; +use dom::virtualmethods::VirtualMethods; + +use string_cache::Atom; use util::str::DOMString; #[dom_struct] @@ -37,3 +44,21 @@ impl HTMLAppletElement { } } +impl<'a> HTMLAppletElementMethods for JSRef<'a, HTMLAppletElement> { + // https://html.spec.whatwg.org/#the-applet-element:dom-applet-name + make_getter!(Name); + make_atomic_setter!(SetName, "name"); +} + +impl<'a> VirtualMethods for JSRef<'a, HTMLAppletElement> { + fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> { + Some(HTMLElementCast::from_borrowed_ref(self) as &VirtualMethods) + } + + fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + match name { + &atom!("name") => AttrValue::from_atomic(value), + _ => self.super_type().unwrap().parse_plain_attribute(name, value), + } + } +} diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 176feb927b9..97a8e7a74d7 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -199,6 +199,20 @@ macro_rules! make_limited_uint_setter( }; ); +#[macro_export] +macro_rules! make_atomic_setter( + ( $attr:ident, $htmlname:expr ) => ( + fn $attr(self, value: DOMString) { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; + let element: JSRef = ElementCast::from_ref(self); + // FIXME(pcwalton): Do this at compile time, not at runtime. + element.set_atomic_attribute(&Atom::from_slice($htmlname), value) + } + ); +); + /// For use on non-jsmanaged types /// Use #[jstraceable] on JS managed types macro_rules! no_jsmanaged_fields( diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index 05bd23307a2..a4ceb09e026 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -6,6 +6,7 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast; use dom::bindings::codegen::InheritTypes::HTMLAreaElementCast; +use dom::bindings::codegen::InheritTypes::HTMLAppletElementCast; use dom::bindings::codegen::InheritTypes::HTMLBodyElementCast; use dom::bindings::codegen::InheritTypes::HTMLButtonElementCast; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementCast; @@ -144,6 +145,9 @@ pub fn vtable_for<'a>(node: &'a JSRef<'a, Node>) -> &'a (VirtualMethods + 'a) { let element: &'a JSRef<'a, HTMLAnchorElement> = HTMLAnchorElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) } + NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAppletElement)) => { + HTMLAppletElementCast::to_borrowed_ref(node).unwrap() as &'a (VirtualMethods + 'a) + } NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) => { let element: &'a JSRef<'a, HTMLAreaElement> = HTMLAreaElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) diff --git a/components/script/dom/webidls/HTMLAppletElement.webidl b/components/script/dom/webidls/HTMLAppletElement.webidl index ff86973dac4..b7f6350de53 100644 --- a/components/script/dom/webidls/HTMLAppletElement.webidl +++ b/components/script/dom/webidls/HTMLAppletElement.webidl @@ -12,7 +12,7 @@ interface HTMLAppletElement : HTMLElement { // attribute DOMString codeBase; // attribute DOMString height; // attribute unsigned long hspace; - // attribute DOMString name; + attribute DOMString name; // attribute DOMString _object; // the underscore is not part of the identifier // attribute unsigned long vspace; // attribute DOMString width; diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 6c68c5ffa9d..baa79ddb115 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -8967,9 +8967,6 @@ [HTMLAppletElement interface: attribute hspace] expected: FAIL - [HTMLAppletElement interface: attribute name] - expected: FAIL - [HTMLAppletElement interface: attribute object] expected: FAIL @@ -9000,9 +8997,6 @@ [HTMLAppletElement interface: document.createElement("applet") must inherit property "hspace" with the proper type (6)] expected: FAIL - [HTMLAppletElement interface: document.createElement("applet") must inherit property "name" with the proper type (7)] - expected: FAIL - [HTMLAppletElement interface: document.createElement("applet") must inherit property "object" with the proper type (8)] expected: FAIL diff --git a/tests/wpt/metadata/html/dom/reflection-obsolete.html.ini b/tests/wpt/metadata/html/dom/reflection-obsolete.html.ini index 92fde45eabd..9cf4851242b 100644 --- a/tests/wpt/metadata/html/dom/reflection-obsolete.html.ini +++ b/tests/wpt/metadata/html/dom/reflection-obsolete.html.ini @@ -1452,135 +1452,6 @@ [applet.hspace: IDL set to "-0" followed by IDL get] expected: FAIL - [applet.name: typeof IDL attribute] - expected: FAIL - - [applet.name: IDL get with DOM attribute unset] - expected: FAIL - - [applet.name: setAttribute() to "" followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to undefined followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to 7 followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to 1.5 followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to true followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to false followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to object "[object Object\]" followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to NaN followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to Infinity followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to -Infinity followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to "\\0" followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to null followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to object "test-toString" followed by IDL get] - expected: FAIL - - [applet.name: setAttribute() to object "test-valueOf" followed by IDL get] - expected: FAIL - - [applet.name: IDL set to "" followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to undefined followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to undefined followed by IDL get] - expected: FAIL - - [applet.name: IDL set to 7 followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to 7 followed by IDL get] - expected: FAIL - - [applet.name: IDL set to 1.5 followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to 1.5 followed by IDL get] - expected: FAIL - - [applet.name: IDL set to true followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to true followed by IDL get] - expected: FAIL - - [applet.name: IDL set to false followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to false followed by IDL get] - expected: FAIL - - [applet.name: IDL set to object "[object Object\]" followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to object "[object Object\]" followed by IDL get] - expected: FAIL - - [applet.name: IDL set to NaN followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to NaN followed by IDL get] - expected: FAIL - - [applet.name: IDL set to Infinity followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to Infinity followed by IDL get] - expected: FAIL - - [applet.name: IDL set to -Infinity followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to -Infinity followed by IDL get] - expected: FAIL - - [applet.name: IDL set to "\\0" followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to null followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to null followed by IDL get] - expected: FAIL - - [applet.name: IDL set to object "test-toString" followed by getAttribute()] - expected: FAIL - - [applet.name: IDL set to object "test-toString" followed by IDL get] - expected: FAIL - - [applet.name: IDL set to object "test-valueOf" followed by IDL get] - expected: FAIL - [applet.object: typeof IDL attribute] expected: FAIL From 70e67d5e11751159fd85555d3f08cc173e321e41 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 2 May 2015 12:45:07 +0200 Subject: [PATCH 3/5] Make HTMLImageElement name attribute use an atom --- components/script/dom/htmlimageelement.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 760f5942aa0..a88f4b5ea7b 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -229,9 +229,9 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { image.is_some() } + // https://html.spec.whatwg.org/#dom-img-name make_getter!(Name); - - make_setter!(SetName, "name"); + make_atomic_setter!(SetName, "name"); make_getter!(Align); @@ -288,6 +288,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { match name { + &atom!("name") => AttrValue::from_atomic(value), &atom!("width") | &atom!("height") | &atom!("hspace") | &atom!("vspace") => AttrValue::from_u32(value, 0), _ => self.super_type().unwrap().parse_plain_attribute(name, value), From 69220dfc10537ac935fbdefec8906f0e12657f0f Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 2 May 2015 13:39:54 +0200 Subject: [PATCH 4/5] Make HTMLFormElement name attribute use an atom --- components/script/dom/htmlformelement.rs | 29 +++++++++++++++++++----- components/script/dom/virtualmethods.rs | 4 ++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index f926b521f5c..3d6ad028ab7 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -2,15 +2,20 @@ * 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::AttrValue; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLFormElementBinding; use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods; -use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLFormElementDerived, NodeCast}; -use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, HTMLTextAreaElementCast}; -use dom::bindings::codegen::InheritTypes::{HTMLFormElementCast, HTMLDataListElementCast}; +use dom::bindings::codegen::InheritTypes::EventTargetCast; +use dom::bindings::codegen::InheritTypes::HTMLDataListElementCast; +use dom::bindings::codegen::InheritTypes::HTMLElementCast; +use dom::bindings::codegen::InheritTypes::HTMLFormElementCast; +use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; +use dom::bindings::codegen::InheritTypes::HTMLInputElementCast; +use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementCast, NodeCast}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JSRef, OptionalRootable, Rootable, Temporary}; use dom::document::{Document, DocumentHelpers}; @@ -23,6 +28,7 @@ use dom::htmlinputelement::{HTMLInputElement, HTMLInputElementHelpers}; use dom::htmlbuttonelement::{HTMLButtonElement}; use dom::htmltextareaelement::HTMLTextAreaElementHelpers; use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node}; +use dom::virtualmethods::VirtualMethods; use hyper::method::Method; use hyper::header::ContentType; use hyper::mime; @@ -107,9 +113,7 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { // https://html.spec.whatwg.org/multipage/#dom-form-name make_getter!(Name); - - // https://html.spec.whatwg.org/multipage/#dom-form-name - make_setter!(SetName, "name"); + make_atomic_setter!(SetName, "name"); // https://html.spec.whatwg.org/multipage/#dom-fs-novalidate make_bool_getter!(NoValidate); @@ -559,3 +563,16 @@ pub trait FormControl<'a> : Copy + Sized { fn to_element(self) -> JSRef<'a, Element>; } + +impl<'a> VirtualMethods for JSRef<'a, HTMLFormElement> { + fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> { + Some(HTMLElementCast::from_borrowed_ref(self) as &VirtualMethods) + } + + fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + match name { + &atom!("name") => AttrValue::from_atomic(value), + _ => self.super_type().unwrap().parse_plain_attribute(name, value), + } + } +} diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index a4ceb09e026..2147ee07c48 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -12,6 +12,7 @@ use dom::bindings::codegen::InheritTypes::HTMLButtonElementCast; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementCast; use dom::bindings::codegen::InheritTypes::HTMLElementCast; use dom::bindings::codegen::InheritTypes::HTMLFieldSetElementCast; +use dom::bindings::codegen::InheritTypes::HTMLFormElementCast; use dom::bindings::codegen::InheritTypes::HTMLHeadElementCast; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::codegen::InheritTypes::HTMLImageElementCast; @@ -168,6 +169,9 @@ pub fn vtable_for<'a>(node: &'a JSRef<'a, Node>) -> &'a (VirtualMethods + 'a) { let element: &'a JSRef<'a, HTMLFieldSetElement> = HTMLFieldSetElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) } + NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFormElement)) => { + HTMLFormElementCast::to_borrowed_ref(node).unwrap() as &'a (VirtualMethods + 'a) + } NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadElement)) => { let element: &'a JSRef<'a, HTMLHeadElement> = HTMLHeadElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) From 0e8bd5dd98bceb3bbb3bd24e11f5d15d6b4a66f7 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 2 May 2015 13:02:23 +0200 Subject: [PATCH 5/5] Partially implement getter of Document --- components/script/dom/document.rs | 92 ++++++++++++++++++- components/script/dom/webidls/Document.webidl | 2 +- .../dom-tree-accessors/nameditem-01.html.ini | 5 - .../dom-tree-accessors/nameditem-03.html.ini | 26 ------ .../dom-tree-accessors/nameditem-04.html.ini | 17 ---- .../dom-tree-accessors/nameditem-06.html.ini | 20 ---- 6 files changed, 92 insertions(+), 70 deletions(-) delete mode 100644 tests/wpt/metadata/html/dom/documents/dom-tree-accessors/nameditem-01.html.ini delete mode 100644 tests/wpt/metadata/html/dom/documents/dom-tree-accessors/nameditem-03.html.ini delete mode 100644 tests/wpt/metadata/html/dom/documents/dom-tree-accessors/nameditem-04.html.ini delete mode 100644 tests/wpt/metadata/html/dom/documents/dom-tree-accessors/nameditem-06.html.ini diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index e08e47f85fe..19901c43796 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -23,6 +23,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLAreaElementDerived, HTMLEmbedElem use dom::bindings::codegen::InheritTypes::{HTMLFormElementDerived, HTMLImageElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived, HTMLTitleElementDerived}; use dom::bindings::codegen::UnionTypes::NodeOrString; +use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error::{NotSupported, InvalidCharacter, Security}; use dom::bindings::error::Error::HierarchyRequest; @@ -84,7 +85,7 @@ use html5ever::tree_builder::{QuirksMode, NoQuirks, LimitedQuirks, Quirks}; use layout_interface::{LayoutChan, Msg}; use string_cache::{Atom, QualName}; use url::Url; -use js::jsapi::JSRuntime; +use js::jsapi::{JSContext, JSObject, JSRuntime}; use num::ToPrimitive; use std::iter::FromIterator; @@ -94,6 +95,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::ascii::AsciiExt; use std::cell::{Cell, Ref, RefMut, RefCell}; use std::default::Default; +use std::ptr; use std::sync::mpsc::{Receiver, channel}; use time; @@ -1661,6 +1663,94 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { self.set_body_attribute(&atom!("bgcolor"), value) } + // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter + fn NamedGetter(self, cx: *mut JSContext, name: DOMString, found: &mut bool) + -> *mut JSObject { + #[jstraceable] + struct NamedElementFilter { + name: Atom, + } + impl CollectionFilter for NamedElementFilter { + fn filter(&self, elem: JSRef, _root: JSRef) -> bool { + filter_by_name(&self.name, NodeCast::from_ref(elem)) + } + } + // https://html.spec.whatwg.org/#dom-document-nameditem-filter + fn filter_by_name(name: &Atom, node: JSRef) -> bool { + let html_elem_type = match node.type_id() { + NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_, + _ => return false, + }; + let elem = match ElementCast::to_ref(node) { + Some(elem) => elem, + None => return false, + }; + match html_elem_type { + HTMLElementTypeId::HTMLAppletElement => { + match elem.get_attribute(&ns!(""), &atom!("name")).root() { + Some(ref attr) if attr.r().value().atom() == Some(name) => true, + _ => { + match elem.get_attribute(&ns!(""), &atom!("id")).root() { + Some(ref attr) => attr.r().value().atom() == Some(name), + None => false, + } + }, + } + }, + HTMLElementTypeId::HTMLFormElement => { + match elem.get_attribute(&ns!(""), &atom!("name")).root() { + Some(ref attr) => attr.r().value().atom() == Some(name), + None => false, + } + }, + HTMLElementTypeId::HTMLImageElement => { + match elem.get_attribute(&ns!(""), &atom!("name")).root() { + Some(ref attr) => { + if attr.r().value().atom() == Some(name) { + true + } else { + match elem.get_attribute(&ns!(""), &atom!("id")).root() { + Some(ref attr) => attr.r().value().atom() == Some(name), + None => false, + } + } + }, + None => false, + } + }, + // TODO: Handle ,