Names should now be consistently atoms

This commit is contained in:
Patrick Shaughnessy 2020-01-21 11:06:31 -05:00
parent 43c558fa59
commit f29e22f131
32 changed files with 270 additions and 652 deletions

View file

@ -84,6 +84,7 @@ radio
range range
ratechange ratechange
readystatechange readystatechange
referrer
reftest-wait reftest-wait
rejectionhandled rejectionhandled
removetrack removetrack

View file

@ -823,6 +823,7 @@ impl Document {
} }
fn get_anchor_by_name(&self, name: &str) -> Option<DomRoot<Element>> { fn get_anchor_by_name(&self, name: &str) -> Option<DomRoot<Element>> {
// TODO faster name lookups (see #25548)
let check_anchor = |node: &HTMLAnchorElement| { let check_anchor = |node: &HTMLAnchorElement| {
let elem = node.upcast::<Element>(); let elem = node.upcast::<Element>();
elem.get_attribute(&ns!(), &local_name!("name")) elem.get_attribute(&ns!(), &local_name!("name"))
@ -4091,9 +4092,7 @@ impl DocumentMethods for Document {
if element.namespace() != &ns!(html) { if element.namespace() != &ns!(html) {
return false; return false;
} }
element element.get_name().map_or(false, |atom| *atom == *name)
.get_attribute(&ns!(), &local_name!("name"))
.map_or(false, |attr| &**attr.value() == &*name)
}) })
} }
@ -4303,6 +4302,7 @@ impl DocumentMethods for Document {
} }
// https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter // https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter
fn filter_by_name(name: &Atom, node: &Node) -> bool { fn filter_by_name(name: &Atom, node: &Node) -> bool {
// TODO faster name lookups (see #25548)
let html_elem_type = match node.type_id() { let html_elem_type = match node.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_, NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_,
_ => return false, _ => return false,

View file

@ -1401,11 +1401,28 @@ impl Element {
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name // https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
pub fn get_attribute_by_name(&self, name: DOMString) -> Option<DomRoot<Attr>> { pub fn get_attribute_by_name(&self, name: DOMString) -> Option<DomRoot<Attr>> {
let name = &self.parsed_name(name); let name = &self.parsed_name(name);
self.attrs let maybe_attribute = self
.attrs
.borrow() .borrow()
.iter() .iter()
.find(|a| a.name() == name) .find(|a| a.name() == name)
.map(|js| DomRoot::from_ref(&**js)) .map(|js| DomRoot::from_ref(&**js));
fn id_and_name_must_be_atoms(name: &LocalName, maybe_attr: &Option<DomRoot<Attr>>) -> bool {
if *name == local_name!("id") || *name == local_name!("name") {
match maybe_attr {
None => true,
Some(ref attr) => match *attr.value() {
AttrValue::Atom(_) => true,
_ => false,
},
}
} else {
true
}
}
debug_assert!(id_and_name_must_be_atoms(name, &maybe_attribute));
maybe_attribute
} }
pub fn set_attribute_from_parser( pub fn set_attribute_from_parser(
@ -1800,6 +1817,14 @@ impl Element {
let other = other.upcast::<Element>(); let other = other.upcast::<Element>();
self.root_element() == other.root_element() self.root_element() == other.root_element()
} }
pub fn get_id(&self) -> Option<Atom> {
self.id_attribute.borrow().clone()
}
pub fn get_name(&self) -> Option<Atom> {
self.rare_data().as_ref()?.name_attribute.clone()
}
} }
impl ElementMethods for Element { impl ElementMethods for Element {
@ -1836,6 +1861,8 @@ impl ElementMethods for Element {
} }
// https://dom.spec.whatwg.org/#dom-element-id // https://dom.spec.whatwg.org/#dom-element-id
// This always returns a string; if you'd rather see None
// on a null id, call get_id
fn Id(&self) -> DOMString { fn Id(&self) -> DOMString {
self.get_string_attribute(&local_name!("id")) self.get_string_attribute(&local_name!("id"))
} }
@ -2783,6 +2810,20 @@ impl VirtualMethods for Element {
} }
} }
}, },
&local_name!("name") => {
// Keep the name in rare data for fast access
self.ensure_rare_data().name_attribute =
mutation.new_value(attr).and_then(|value| {
let value = value.as_atom();
if value != &atom!("") {
Some(value.clone())
} else {
None
}
});
// TODO: notify the document about the name change
// once it has a name_map (#25548)
},
_ => { _ => {
// FIXME(emilio): This is pretty dubious, and should be done in // FIXME(emilio): This is pretty dubious, and should be done in
// the relevant super-classes. // the relevant super-classes.
@ -2801,6 +2842,7 @@ impl VirtualMethods for Element {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name { match name {
&local_name!("id") => AttrValue::from_atomic(value.into()), &local_name!("id") => AttrValue::from_atomic(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("class") => AttrValue::from_serialized_tokenlist(value.into()), &local_name!("class") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self _ => self
.super_type() .super_type()

View file

@ -152,7 +152,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
make_getter!(Name, "name"); make_getter!(Name, "name");
// https://html.spec.whatwg.org/multipage/#dom-a-name // https://html.spec.whatwg.org/multipage/#dom-a-name
make_setter!(SetName, "name"); make_atomic_setter!(SetName, "name");
// https://html.spec.whatwg.org/multipage/#dom-a-rev // https://html.spec.whatwg.org/multipage/#dom-a-rev
make_getter!(Rev, "rev"); make_getter!(Rev, "rev");

View file

@ -142,7 +142,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
make_getter!(Name, "name"); make_getter!(Name, "name");
// https://html.spec.whatwg.org/multipage/#dom-fe-name // https://html.spec.whatwg.org/multipage/#dom-fe-name
make_setter!(SetName, "name"); make_atomic_setter!(SetName, "name");
// https://html.spec.whatwg.org/multipage/#dom-button-value // https://html.spec.whatwg.org/multipage/#dom-button-value
make_getter!(Value, "value"); make_getter!(Value, "value");

View file

@ -366,11 +366,12 @@ impl HTMLCollectionMethods for HTMLCollection {
return None; return None;
} }
let key = Atom::from(key);
// Step 2. // Step 2.
self.elements_iter().find(|elem| { self.elements_iter().find(|elem| {
elem.get_string_attribute(&local_name!("id")) == key || elem.get_id().map_or(false, |id| id == key) ||
(elem.namespace() == &ns!(html) && (elem.namespace() == &ns!(html) && elem.get_name().map_or(false, |id| id == key))
elem.get_string_attribute(&local_name!("name")) == key)
}) })
} }
@ -392,17 +393,20 @@ impl HTMLCollectionMethods for HTMLCollection {
// Step 2 // Step 2
for elem in self.elements_iter() { for elem in self.elements_iter() {
// Step 2.1 // Step 2.1
let id_attr = elem.get_string_attribute(&local_name!("id")); if let Some(id_atom) = elem.get_id() {
if !id_attr.is_empty() && !result.contains(&id_attr) { let id_str = DOMString::from(&*id_atom);
result.push(id_attr) if !result.contains(&id_str) {
result.push(id_str);
}
} }
// Step 2.2 // Step 2.2
let name_attr = elem.get_string_attribute(&local_name!("name")); if *elem.namespace() == ns!(html) {
if !name_attr.is_empty() && if let Some(name_atom) = elem.get_name() {
!result.contains(&name_attr) && let name_str = DOMString::from(&*name_atom);
*elem.namespace() == ns!(html) if !result.contains(&name_str) {
{ result.push(name_str)
result.push(name_attr) }
}
} }
} }

View file

@ -7,6 +7,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding;
use crate::dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods; use crate::dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods;
use crate::dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use crate::dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document; use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element}; use crate::dom::element::{AttributeMutation, Element};
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection}; use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
@ -88,6 +89,12 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement {
// https://html.spec.whatwg.org/multipage/#dom-fieldset-disabled // https://html.spec.whatwg.org/multipage/#dom-fieldset-disabled
make_bool_setter!(SetDisabled, "disabled"); make_bool_setter!(SetDisabled, "disabled");
// https://html.spec.whatwg.org/multipage/#dom-fe-name
make_atomic_setter!(SetName, "name");
// https://html.spec.whatwg.org/multipage/#dom-fe-name
make_getter!(Name, "name");
// https://html.spec.whatwg.org/multipage/#dom-fae-form // https://html.spec.whatwg.org/multipage/#dom-fae-form
fn GetForm(&self) -> Option<DomRoot<HTMLFormElement>> { fn GetForm(&self) -> Option<DomRoot<HTMLFormElement>> {
self.form_owner() self.form_owner()

View file

@ -18,6 +18,7 @@ use crate::dom::node::Node;
use crate::dom::radionodelist::RadioNodeList; use crate::dom::radionodelist::RadioNodeList;
use crate::dom::window::Window; use crate::dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use servo_atoms::Atom;
#[dom_struct] #[dom_struct]
pub struct HTMLFormControlsCollection { pub struct HTMLFormControlsCollection {
@ -67,9 +68,11 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection {
return None; return None;
} }
let name = Atom::from(name);
let mut filter_map = self.collection.elements_iter().filter_map(|elem| { let mut filter_map = self.collection.elements_iter().filter_map(|elem| {
if elem.get_string_attribute(&local_name!("name")) == name || if elem.get_name().map_or(false, |n| n == name) ||
elem.get_string_attribute(&local_name!("id")) == name elem.get_id().map_or(false, |i| i == name)
{ {
Some(elem) Some(elem)
} else { } else {
@ -90,7 +93,7 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection {
// specifically HTMLFormElement::Elements(), // specifically HTMLFormElement::Elements(),
// and the collection filter excludes image inputs. // and the collection filter excludes image inputs.
Some(RadioNodeListOrElement::RadioNodeList( Some(RadioNodeListOrElement::RadioNodeList(
RadioNodeList::new_controls_except_image_inputs(window, &*self.form, name), RadioNodeList::new_controls_except_image_inputs(window, &*self.form, &name),
)) ))
} }
// Step 3 // Step 3

View file

@ -62,10 +62,10 @@ use mime::{self, Mime};
use net_traits::http_percent_encode; use net_traits::http_percent_encode;
use net_traits::request::Referrer; use net_traits::request::Referrer;
use script_traits::{HistoryEntryReplacement, LoadData, LoadOrigin}; use script_traits::{HistoryEntryReplacement, LoadData, LoadOrigin};
use servo_atoms::Atom;
use servo_rand::random; use servo_rand::random;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::Cell; use std::cell::Cell;
use style::attr::AttrValue;
use style::str::split_html_space_chars; use style::str::split_html_space_chars;
use crate::dom::bindings::codegen::UnionTypes::RadioNodeListOrElement; use crate::dom::bindings::codegen::UnionTypes::RadioNodeListOrElement;
@ -86,7 +86,7 @@ pub struct HTMLFormElement {
elements: DomOnceCell<HTMLFormControlsCollection>, elements: DomOnceCell<HTMLFormControlsCollection>,
generation_id: Cell<GenerationId>, generation_id: Cell<GenerationId>,
controls: DomRefCell<Vec<Dom<Element>>>, controls: DomRefCell<Vec<Dom<Element>>>,
past_names_map: DomRefCell<HashMap<DOMString, (Dom<Element>, Tm)>>, past_names_map: DomRefCell<HashMap<Atom, (Dom<Element>, Tm)>>,
} }
impl HTMLFormElement { impl HTMLFormElement {
@ -119,7 +119,7 @@ impl HTMLFormElement {
) )
} }
fn filter_for_radio_list(mode: RadioListMode, child: &Element, name: &DOMString) -> bool { fn filter_for_radio_list(mode: RadioListMode, child: &Element, name: &Atom) -> bool {
if let Some(child) = child.downcast::<Element>() { if let Some(child) = child.downcast::<Element>() {
match mode { match mode {
RadioListMode::ControlsExceptImageInputs => { RadioListMode::ControlsExceptImageInputs => {
@ -127,10 +127,8 @@ impl HTMLFormElement {
.downcast::<HTMLElement>() .downcast::<HTMLElement>()
.map_or(false, |c| c.is_listed_element()) .map_or(false, |c| c.is_listed_element())
{ {
if (child.has_attribute(&local_name!("id")) && if child.get_id().map_or(false, |i| i == *name) ||
child.get_string_attribute(&local_name!("id")) == *name) || child.get_name().map_or(false, |n| n == *name)
(child.has_attribute(&local_name!("name")) &&
child.get_string_attribute(&local_name!("name")) == *name)
{ {
if let Some(inp) = child.downcast::<HTMLInputElement>() { if let Some(inp) = child.downcast::<HTMLInputElement>() {
// input, only return it if it's not image-button state // input, only return it if it's not image-button state
@ -144,16 +142,9 @@ impl HTMLFormElement {
return false; return false;
}, },
RadioListMode::Images => { RadioListMode::Images => {
if child.is::<HTMLImageElement>() { return child.is::<HTMLImageElement>() &&
if (child.has_attribute(&local_name!("id")) && (child.get_id().map_or(false, |i| i == *name) ||
child.get_string_attribute(&local_name!("id")) == *name) || child.get_name().map_or(false, |n| n == *name));
(child.has_attribute(&local_name!("name")) &&
child.get_string_attribute(&local_name!("name")) == *name)
{
return true;
}
}
return false;
}, },
} }
} }
@ -164,7 +155,7 @@ impl HTMLFormElement {
&self, &self,
index: u32, index: u32,
mode: RadioListMode, mode: RadioListMode,
name: &DOMString, name: &Atom,
) -> Option<DomRoot<Node>> { ) -> Option<DomRoot<Node>> {
self.controls self.controls
.borrow() .borrow()
@ -174,7 +165,7 @@ impl HTMLFormElement {
.and_then(|n| Some(DomRoot::from_ref(n.upcast::<Node>()))) .and_then(|n| Some(DomRoot::from_ref(n.upcast::<Node>())))
} }
pub fn count_for_radio_list(&self, mode: RadioListMode, name: &DOMString) -> u32 { pub fn count_for_radio_list(&self, mode: RadioListMode, name: &Atom) -> u32 {
self.controls self.controls
.borrow() .borrow()
.iter() .iter()
@ -333,14 +324,15 @@ impl HTMLFormElementMethods for HTMLFormElement {
fn NamedGetter(&self, name: DOMString) -> Option<RadioNodeListOrElement> { fn NamedGetter(&self, name: DOMString) -> Option<RadioNodeListOrElement> {
let window = window_from_node(self); let window = window_from_node(self);
let name = Atom::from(name);
// Step 1 // Step 1
let mut candidates = let mut candidates = RadioNodeList::new_controls_except_image_inputs(&window, self, &name);
RadioNodeList::new_controls_except_image_inputs(&window, self, name.clone());
let mut candidates_length = candidates.Length(); let mut candidates_length = candidates.Length();
// Step 2 // Step 2
if candidates_length == 0 { if candidates_length == 0 {
candidates = RadioNodeList::new_images(&window, self, name.clone()); candidates = RadioNodeList::new_images(&window, self, &name);
candidates_length = candidates.Length(); candidates_length = candidates.Length();
} }
@ -399,12 +391,12 @@ impl HTMLFormElementMethods for HTMLFormElement {
} }
struct SourcedName { struct SourcedName {
name: DOMString, name: Atom,
element: DomRoot<Element>, element: DomRoot<Element>,
source: SourcedNameSource, source: SourcedNameSource,
} }
let mut sourcedNamesVec: Vec<SourcedName> = Vec::new(); let mut sourced_names_vec: Vec<SourcedName> = Vec::new();
let controls = self.controls.borrow(); let controls = self.controls.borrow();
@ -414,21 +406,21 @@ impl HTMLFormElementMethods for HTMLFormElement {
.downcast::<HTMLElement>() .downcast::<HTMLElement>()
.map_or(false, |c| c.is_listed_element()) .map_or(false, |c| c.is_listed_element())
{ {
if child.has_attribute(&local_name!("id")) { if let Some(id_atom) = child.get_id() {
let entry = SourcedName { let entry = SourcedName {
name: child.get_string_attribute(&local_name!("id")), name: id_atom,
element: DomRoot::from_ref(&*child), element: DomRoot::from_ref(&*child),
source: SourcedNameSource::Id, source: SourcedNameSource::Id,
}; };
sourcedNamesVec.push(entry); sourced_names_vec.push(entry);
} }
if child.has_attribute(&local_name!("name")) { if let Some(name_atom) = child.get_name() {
let entry = SourcedName { let entry = SourcedName {
name: child.get_string_attribute(&local_name!("name")), name: name_atom,
element: DomRoot::from_ref(&*child), element: DomRoot::from_ref(&*child),
source: SourcedNameSource::Name, source: SourcedNameSource::Name,
}; };
sourcedNamesVec.push(entry); sourced_names_vec.push(entry);
} }
} }
} }
@ -436,21 +428,21 @@ impl HTMLFormElementMethods for HTMLFormElement {
// Step 3 // Step 3
for child in controls.iter() { for child in controls.iter() {
if child.is::<HTMLImageElement>() { if child.is::<HTMLImageElement>() {
if child.has_attribute(&local_name!("id")) { if let Some(id_atom) = child.get_id() {
let entry = SourcedName { let entry = SourcedName {
name: child.get_string_attribute(&local_name!("id")), name: id_atom,
element: DomRoot::from_ref(&*child), element: DomRoot::from_ref(&*child),
source: SourcedNameSource::Id, source: SourcedNameSource::Id,
}; };
sourcedNamesVec.push(entry); sourced_names_vec.push(entry);
} }
if child.has_attribute(&local_name!("name")) { if let Some(name_atom) = child.get_name() {
let entry = SourcedName { let entry = SourcedName {
name: child.get_string_attribute(&local_name!("name")), name: name_atom,
element: DomRoot::from_ref(&*child), element: DomRoot::from_ref(&*child),
source: SourcedNameSource::Name, source: SourcedNameSource::Name,
}; };
sourcedNamesVec.push(entry); sourced_names_vec.push(entry);
} }
} }
} }
@ -463,7 +455,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
element: DomRoot::from_ref(&*val.0), element: DomRoot::from_ref(&*val.0),
source: SourcedNameSource::Past(now() - val.1), // calculate difference now()-val.1 to find age source: SourcedNameSource::Past(now() - val.1), // calculate difference now()-val.1 to find age
}; };
sourcedNamesVec.push(entry); sourced_names_vec.push(entry);
} }
// Step 5 // Step 5
@ -477,7 +469,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
// (this can be checked by bitwise operations) then b would follow a in tree order and // (this can be checked by bitwise operations) then b would follow a in tree order and
// Ordering::Less should be returned in the closure else Ordering::Greater // Ordering::Less should be returned in the closure else Ordering::Greater
sourcedNamesVec.sort_by(|a, b| { sourced_names_vec.sort_by(|a, b| {
if a.element if a.element
.upcast::<Node>() .upcast::<Node>()
.CompareDocumentPosition(b.element.upcast::<Node>()) == .CompareDocumentPosition(b.element.upcast::<Node>()) ==
@ -503,21 +495,21 @@ impl HTMLFormElementMethods for HTMLFormElement {
}); });
// Step 6 // Step 6
sourcedNamesVec.retain(|sn| !sn.name.to_string().is_empty()); sourced_names_vec.retain(|sn| !sn.name.to_string().is_empty());
// Step 7-8 // Step 7-8
let mut namesVec: Vec<DOMString> = Vec::new(); let mut names_vec: Vec<DOMString> = Vec::new();
for elem in sourcedNamesVec.iter() { for elem in sourced_names_vec.iter() {
if namesVec if names_vec
.iter() .iter()
.find(|name| name.to_string() == elem.name.to_string()) .find(|name| &**name == &*elem.name)
.is_none() .is_none()
{ {
namesVec.push(elem.name.clone()); names_vec.push(DOMString::from(&*elem.name));
} }
} }
return namesVec; return names_vec;
} }
} }
@ -1519,16 +1511,6 @@ impl VirtualMethods for HTMLFormElement {
Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods) Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
} }
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&local_name!("name") => AttrValue::from_atomic(value.into()),
_ => self
.super_type()
.unwrap()
.parse_plain_attribute(name, value),
}
}
fn unbind_from_tree(&self, context: &UnbindContext) { fn unbind_from_tree(&self, context: &UnbindContext) {
self.super_type().unwrap().unbind_from_tree(context); self.super_type().unwrap().unbind_from_tree(context);

View file

@ -58,7 +58,7 @@ impl HTMLHeadElement {
.traverse_preorder(ShadowIncluding::No) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<Element>) .filter_map(DomRoot::downcast::<Element>)
.filter(|elem| elem.is::<HTMLMetaElement>()) .filter(|elem| elem.is::<HTMLMetaElement>())
.filter(|elem| elem.get_string_attribute(&local_name!("name")) == "referrer") .filter(|elem| elem.get_name() == Some(atom!("referrer")))
.filter(|elem| { .filter(|elem| {
elem.get_attribute(&ns!(), &local_name!("content")) elem.get_attribute(&ns!(), &local_name!("content"))
.is_some() .is_some()

View file

@ -81,7 +81,6 @@ pub struct HTMLIFrameElement {
sandbox_allowance: Cell<Option<SandboxAllowance>>, sandbox_allowance: Cell<Option<SandboxAllowance>>,
load_blocker: DomRefCell<Option<LoadBlocker>>, load_blocker: DomRefCell<Option<LoadBlocker>>,
visibility: Cell<bool>, visibility: Cell<bool>,
name: DomRefCell<DOMString>,
} }
impl HTMLIFrameElement { impl HTMLIFrameElement {
@ -265,7 +264,11 @@ impl HTMLIFrameElement {
// when the iframe attributes are first processed. // when the iframe attributes are first processed.
if mode == ProcessingMode::FirstTime { if mode == ProcessingMode::FirstTime {
if let Some(window) = self.GetContentWindow() { if let Some(window) = self.GetContentWindow() {
window.set_name(self.name.borrow().clone()) window.set_name(
self.upcast::<Element>()
.get_name()
.map_or(DOMString::from(""), |n| DOMString::from(&*n)),
);
} }
} }
@ -389,7 +392,6 @@ impl HTMLIFrameElement {
sandbox_allowance: Cell::new(None), sandbox_allowance: Cell::new(None),
load_blocker: DomRefCell::new(None), load_blocker: DomRefCell::new(None),
visibility: Cell::new(true), visibility: Cell::new(true),
name: DomRefCell::new(DOMString::new()),
} }
} }
@ -569,21 +571,14 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
make_setter!(SetFrameBorder, "frameborder"); make_setter!(SetFrameBorder, "frameborder");
// https://html.spec.whatwg.org/multipage/#dom-iframe-name // https://html.spec.whatwg.org/multipage/#dom-iframe-name
fn SetName(&self, name: DOMString) { // A child browsing context checks the name of its iframe only at the time
*self.name.borrow_mut() = name.clone(); // it is created; subsequent name sets have no special effect.
if let Some(window) = self.GetContentWindow() { make_atomic_setter!(SetName, "name");
window.set_name(name)
}
}
// https://html.spec.whatwg.org/multipage/#dom-iframe-name // https://html.spec.whatwg.org/multipage/#dom-iframe-name
fn Name(&self) -> DOMString { // This is specified as reflecting the name content attribute of the
if let Some(window) = self.GetContentWindow() { // element, not the name of the child browsing context.
window.get_name() make_getter!(Name, "name");
} else {
self.name.borrow().clone()
}
}
} }
impl VirtualMethods for HTMLIFrameElement { impl VirtualMethods for HTMLIFrameElement {
@ -642,11 +637,6 @@ impl VirtualMethods for HTMLIFrameElement {
self.process_the_iframe_attributes(ProcessingMode::NotFirstTime); self.process_the_iframe_attributes(ProcessingMode::NotFirstTime);
} }
}, },
&local_name!("name") => {
let new_value = mutation.new_value(attr);
let value = new_value.as_ref().map_or("", |v| &v);
self.SetName(DOMString::from(value.to_owned()));
},
_ => {}, _ => {},
} }
} }

View file

@ -1313,8 +1313,8 @@ impl HTMLImageElement {
.filter_map(DomRoot::downcast::<HTMLMapElement>) .filter_map(DomRoot::downcast::<HTMLMapElement>)
.find(|n| { .find(|n| {
n.upcast::<Element>() n.upcast::<Element>()
.get_string_attribute(&local_name!("name")) == .get_name()
last .map_or(false, |n| *n == *last)
}); });
useMapElements.map(|mapElem| mapElem.get_area_elements()) useMapElements.map(|mapElem| mapElem.get_area_elements())
@ -1649,7 +1649,6 @@ impl VirtualMethods for HTMLImageElement {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name { match name {
&local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("width") | &local_name!("height") => { &local_name!("width") | &local_name!("height") => {
AttrValue::from_dimension(value.into()) AttrValue::from_dimension(value.into())
}, },

View file

@ -1466,10 +1466,13 @@ impl HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#radio-button-group // https://html.spec.whatwg.org/multipage/#radio-button-group
fn radio_group_name(&self) -> Option<Atom> { fn radio_group_name(&self) -> Option<Atom> {
self.upcast::<Element>() self.upcast::<Element>().get_name().and_then(|name| {
.get_attribute(&ns!(), &local_name!("name")) if name == atom!("") {
.map(|name| name.value().as_atom().clone()) None
.filter(|name| name != &atom!("")) } else {
Some(name)
}
})
} }
fn update_checked_state(&self, checked: bool, dirty: bool) { fn update_checked_state(&self, checked: bool, dirty: bool) {
@ -2158,7 +2161,6 @@ impl VirtualMethods for HTMLInputElement {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name { match name {
&local_name!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()), &local_name!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE), &local_name!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE),
&local_name!("type") => AttrValue::from_atomic(value.into()), &local_name!("type") => AttrValue::from_atomic(value.into()),
&local_name!("maxlength") => { &local_name!("maxlength") => {

View file

@ -26,7 +26,6 @@ use parking_lot::RwLock;
use servo_arc::Arc; use servo_arc::Arc;
use servo_config::pref; use servo_config::pref;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use style::attr::AttrValue;
use style::media_queries::MediaList; use style::media_queries::MediaList;
use style::str::HTML_SPACE_CHARACTERS; use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::{CssRule, CssRules, Origin, Stylesheet, StylesheetContents, ViewportRule}; use style::stylesheets::{CssRule, CssRules, Origin, Stylesheet, StylesheetContents, ViewportRule};
@ -86,8 +85,8 @@ impl HTMLMetaElement {
fn process_attributes(&self) { fn process_attributes(&self) {
let element = self.upcast::<Element>(); let element = self.upcast::<Element>();
if let Some(ref name) = element.get_attribute(&ns!(), &local_name!("name")) { if let Some(ref name) = element.get_name() {
let name = name.value().to_ascii_lowercase(); let name = name.to_ascii_lowercase();
let name = name.trim_matches(HTML_SPACE_CHARACTERS); let name = name.trim_matches(HTML_SPACE_CHARACTERS);
if name == "viewport" { if name == "viewport" {
@ -137,8 +136,8 @@ impl HTMLMetaElement {
fn process_referrer_attribute(&self) { fn process_referrer_attribute(&self) {
let element = self.upcast::<Element>(); let element = self.upcast::<Element>();
if let Some(ref name) = element.get_attribute(&ns!(), &local_name!("name")) { if let Some(ref name) = element.get_name() {
let name = name.value().to_ascii_lowercase(); let name = name.to_ascii_lowercase();
let name = name.trim_matches(HTML_SPACE_CHARACTERS); let name = name.trim_matches(HTML_SPACE_CHARACTERS);
if name == "referrer" { if name == "referrer" {
@ -186,16 +185,6 @@ impl VirtualMethods for HTMLMetaElement {
} }
} }
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&local_name!("name") => AttrValue::from_atomic(value.into()),
_ => self
.super_type()
.unwrap()
.parse_plain_attribute(name, value),
}
}
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
if let Some(s) = self.super_type() { if let Some(s) = self.super_type() {
s.attribute_mutated(attr, mutation); s.attribute_mutated(attr, mutation);

View file

@ -114,6 +114,12 @@ impl HTMLOutputElementMethods for HTMLOutputElement {
fn Type(&self) -> DOMString { fn Type(&self) -> DOMString {
return DOMString::from("output"); return DOMString::from("output");
} }
// https://html.spec.whatwg.org/multipage/#dom-fe-name
make_atomic_setter!(SetName, "name");
// https://html.spec.whatwg.org/multipage/#dom-fe-name
make_getter!(Name, "name");
} }
impl VirtualMethods for HTMLOutputElement { impl VirtualMethods for HTMLOutputElement {

View file

@ -234,7 +234,7 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
make_getter!(Name, "name"); make_getter!(Name, "name");
// https://html.spec.whatwg.org/multipage/#dom-fe-name // https://html.spec.whatwg.org/multipage/#dom-fe-name
make_setter!(SetName, "name"); make_atomic_setter!(SetName, "name");
// https://html.spec.whatwg.org/multipage/#dom-select-size // https://html.spec.whatwg.org/multipage/#dom-select-size
make_uint_getter!(Size, "size", DEFAULT_SELECT_SIZE); make_uint_getter!(Size, "size", DEFAULT_SELECT_SIZE);

View file

@ -220,7 +220,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
make_getter!(Name, "name"); make_getter!(Name, "name");
// https://html.spec.whatwg.org/multipage/#attr-fe-name // https://html.spec.whatwg.org/multipage/#attr-fe-name
make_setter!(SetName, "name"); make_atomic_setter!(SetName, "name");
// https://html.spec.whatwg.org/multipage/#dom-textarea-placeholder // https://html.spec.whatwg.org/multipage/#dom-textarea-placeholder
make_getter!(Placeholder, "placeholder"); make_getter!(Placeholder, "placeholder");

View file

@ -7,12 +7,12 @@ use crate::dom::bindings::codegen::Bindings::NodeListBinding;
use crate::dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods; use crate::dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom}; use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::htmlelement::HTMLElement; use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlformelement::HTMLFormElement; use crate::dom::htmlformelement::HTMLFormElement;
use crate::dom::node::{ChildrenMutation, Node}; use crate::dom::node::{ChildrenMutation, Node};
use crate::dom::window::Window; use crate::dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use servo_atoms::Atom;
use std::cell::Cell; use std::cell::Cell;
#[derive(JSTraceable, MallocSizeOf)] #[derive(JSTraceable, MallocSizeOf)]
@ -381,11 +381,11 @@ pub enum RadioListMode {
pub struct RadioList { pub struct RadioList {
form: Dom<HTMLFormElement>, form: Dom<HTMLFormElement>,
mode: RadioListMode, mode: RadioListMode,
name: DOMString, name: Atom,
} }
impl RadioList { impl RadioList {
pub fn new(form: &HTMLFormElement, mode: RadioListMode, name: DOMString) -> RadioList { pub fn new(form: &HTMLFormElement, mode: RadioListMode, name: Atom) -> RadioList {
RadioList { RadioList {
form: Dom::from_ref(form), form: Dom::from_ref(form),
mode: mode, mode: mode,

View file

@ -16,6 +16,7 @@ use crate::dom::node::Node;
use crate::dom::nodelist::{NodeList, NodeListType, RadioList, RadioListMode}; use crate::dom::nodelist::{NodeList, NodeListType, RadioList, RadioListMode};
use crate::dom::window::Window; use crate::dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use servo_atoms::Atom;
#[dom_struct] #[dom_struct]
pub struct RadioNodeList { pub struct RadioNodeList {
@ -42,14 +43,14 @@ impl RadioNodeList {
pub fn new_controls_except_image_inputs( pub fn new_controls_except_image_inputs(
window: &Window, window: &Window,
form: &HTMLFormElement, form: &HTMLFormElement,
name: DOMString, name: &Atom,
) -> DomRoot<RadioNodeList> { ) -> DomRoot<RadioNodeList> {
RadioNodeList::new( RadioNodeList::new(
window, window,
NodeListType::Radio(RadioList::new( NodeListType::Radio(RadioList::new(
form, form,
RadioListMode::ControlsExceptImageInputs, RadioListMode::ControlsExceptImageInputs,
name, name.clone(),
)), )),
) )
} }
@ -57,11 +58,11 @@ impl RadioNodeList {
pub fn new_images( pub fn new_images(
window: &Window, window: &Window,
form: &HTMLFormElement, form: &HTMLFormElement,
name: DOMString, name: &Atom,
) -> DomRoot<RadioNodeList> { ) -> DomRoot<RadioNodeList> {
RadioNodeList::new( RadioNodeList::new(
window, window,
NodeListType::Radio(RadioList::new(form, RadioListMode::Images, name)), NodeListType::Radio(RadioList::new(form, RadioListMode::Images, name.clone())),
) )
} }

View file

@ -9,6 +9,7 @@ use crate::dom::customelementregistry::{
use crate::dom::mutationobserver::RegisteredObserver; use crate::dom::mutationobserver::RegisteredObserver;
use crate::dom::node::UniqueId; use crate::dom::node::UniqueId;
use crate::dom::shadowroot::ShadowRoot; use crate::dom::shadowroot::ShadowRoot;
use servo_atoms::Atom;
use std::rc::Rc; use std::rc::Rc;
//XXX(ferjm) Ideally merge NodeRareData and ElementRareData so they share //XXX(ferjm) Ideally merge NodeRareData and ElementRareData so they share
@ -42,4 +43,7 @@ pub struct ElementRareData {
pub custom_element_definition: Option<Rc<CustomElementDefinition>>, pub custom_element_definition: Option<Rc<CustomElementDefinition>>,
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state> /// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
pub custom_element_state: CustomElementState, pub custom_element_state: CustomElementState,
/// The "name" content attribute; not used as frequently as id, but used
/// in named getter loops so it's worth looking up quickly when present
pub name_attribute: Option<Atom>,
} }

View file

@ -10,8 +10,8 @@ interface HTMLFieldSetElement : HTMLElement {
[CEReactions] [CEReactions]
attribute boolean disabled; attribute boolean disabled;
readonly attribute HTMLFormElement? form; readonly attribute HTMLFormElement? form;
// [CEReactions] [CEReactions]
// attribute DOMString name; attribute DOMString name;
//readonly attribute DOMString type; //readonly attribute DOMString type;

View file

@ -9,8 +9,8 @@ interface HTMLOutputElement : HTMLElement {
// [SameObject, PutForwards=value] readonly attribute DOMTokenList htmlFor; // [SameObject, PutForwards=value] readonly attribute DOMTokenList htmlFor;
readonly attribute HTMLFormElement? form; readonly attribute HTMLFormElement? form;
// [CEReactions] [CEReactions]
// attribute DOMString name; attribute DOMString name;
[Pure] readonly attribute DOMString type; [Pure] readonly attribute DOMString type;
[CEReactions] [CEReactions]

View file

@ -24,6 +24,7 @@ interface HTMLTextAreaElement : HTMLElement {
attribute long maxLength; attribute long maxLength;
[CEReactions, SetterThrows] [CEReactions, SetterThrows]
attribute long minLength; attribute long minLength;
[CEReactions]
attribute DOMString name; attribute DOMString name;
[CEReactions] [CEReactions]
attribute DOMString placeholder; attribute DOMString placeholder;

View file

@ -81,7 +81,8 @@ pub struct WindowProxy {
/// In the case that this is a top-level window, this is our id. /// In the case that this is a top-level window, this is our id.
top_level_browsing_context_id: TopLevelBrowsingContextId, top_level_browsing_context_id: TopLevelBrowsingContextId,
/// The name of the browsing context /// The name of the browsing context (sometimes, but not always,
/// equal to the name of a container element)
name: DomRefCell<DOMString>, name: DomRefCell<DOMString>,
/// The pipeline id of the currently active document. /// The pipeline id of the currently active document.
/// May be None, when the currently active document is in another script thread. /// May be None, when the currently active document is in another script thread.

View file

@ -364131,6 +364131,12 @@
{} {}
] ]
], ],
"html/dom/elements/name-content-attribute-and-property.html": [
[
"html/dom/elements/name-content-attribute-and-property.html",
{}
]
],
"html/dom/elements/the-innertext-idl-attribute/dynamic-getter.html": [ "html/dom/elements/the-innertext-idl-attribute/dynamic-getter.html": [
[ [
"html/dom/elements/the-innertext-idl-attribute/dynamic-getter.html", "html/dom/elements/the-innertext-idl-attribute/dynamic-getter.html",
@ -682833,6 +682839,10 @@
"d781172bbadcc51c4b203200f1a0adfe50ae4246", "d781172bbadcc51c4b203200f1a0adfe50ae4246",
"manual" "manual"
], ],
"html/dom/elements/name-content-attribute-and-property.html": [
"bcfbd29c33c1e8e68c6f712ad7e2f3ded8cc6686",
"testharness"
],
"html/dom/elements/requirements-relating-to-bidirectional-algorithm-formatting-characters/dir-isolation-001a.html": [ "html/dom/elements/requirements-relating-to-bidirectional-algorithm-formatting-characters/dir-isolation-001a.html": [
"16a308a2f7792a142ed69505f33d111831a063f9", "16a308a2f7792a142ed69505f33d111831a063f9",
"reftest" "reftest"

View file

@ -1,7 +0,0 @@
[HTMLFieldSetElement.html]
[name on HTMLFieldSetElement must enqueue an attributeChanged reaction when adding a new attribute]
expected: FAIL
[name on HTMLFieldSetElement must enqueue an attributeChanged reaction when replacing an existing attribute]
expected: FAIL

View file

@ -9,39 +9,21 @@
[same-origin <frame name=>] [same-origin <frame name=>]
expected: TIMEOUT expected: TIMEOUT
[cross-origin <iframe name=initialvalue>]
expected: FAIL
[cross-origin <embed name=initialvalue>] [cross-origin <embed name=initialvalue>]
expected: TIMEOUT expected: TIMEOUT
[same-origin <iframe name=>]
expected: FAIL
[same-origin <embed>] [same-origin <embed>]
expected: TIMEOUT expected: TIMEOUT
[cross-origin <iframe>]
expected: FAIL
[cross-origin <frame name=initialvalue>] [cross-origin <frame name=initialvalue>]
expected: TIMEOUT expected: TIMEOUT
[cross-origin <iframe name=>]
expected: FAIL
[same-origin <object name=initialvalue>] [same-origin <object name=initialvalue>]
expected: TIMEOUT expected: TIMEOUT
[cross-origin <object name=initialvalue>] [cross-origin <object name=initialvalue>]
expected: TIMEOUT expected: TIMEOUT
[same-origin <iframe>]
expected: FAIL
[same-origin <iframe name=initialvalue>]
expected: FAIL
[same-origin <object name=>] [same-origin <object name=>]
expected: TIMEOUT expected: TIMEOUT

View file

@ -0,0 +1,18 @@
[name-content-attribute-and-property.html]
[embed element\'s name property reflects its content attribute]
expected: FAIL
[frame element\'s name property reflects its content attribute]
expected: FAIL
[map element\'s name property reflects its content attribute]
expected: FAIL
[object element\'s name property reflects its content attribute]
expected: FAIL
[param element\'s name property reflects its content attribute]
expected: FAIL
[slot element\'s name property reflects its content attribute]
expected: FAIL

View file

@ -2241,9 +2241,6 @@
[HTMLInputElement interface: createInput("image") must inherit property "align" with the proper type] [HTMLInputElement interface: createInput("image") must inherit property "align" with the proper type]
expected: FAIL expected: FAIL
[HTMLOutputElement interface: attribute name]
expected: FAIL
[HTMLInputElement interface: createInput("url") must inherit property "reportValidity()" with the proper type] [HTMLInputElement interface: createInput("url") must inherit property "reportValidity()" with the proper type]
expected: FAIL expected: FAIL
@ -3009,9 +3006,6 @@
[HTMLImageElement interface: document.createElement("img") must inherit property "referrerPolicy" with the proper type] [HTMLImageElement interface: document.createElement("img") must inherit property "referrerPolicy" with the proper type]
expected: FAIL expected: FAIL
[HTMLOutputElement interface: document.createElement("output") must inherit property "name" with the proper type]
expected: FAIL
[HTMLElement interface: document.createElement("noscript") must inherit property "dir" with the proper type] [HTMLElement interface: document.createElement("noscript") must inherit property "dir" with the proper type]
expected: FAIL expected: FAIL
@ -3417,9 +3411,6 @@
[HTMLInputElement interface: calling setCustomValidity(DOMString) on createInput("range") with too few arguments must throw TypeError] [HTMLInputElement interface: calling setCustomValidity(DOMString) on createInput("range") with too few arguments must throw TypeError]
expected: FAIL expected: FAIL
[HTMLFieldSetElement interface: attribute name]
expected: FAIL
[HTMLInputElement interface: createInput("time") must inherit property "reportValidity()" with the proper type] [HTMLInputElement interface: createInput("time") must inherit property "reportValidity()" with the proper type]
expected: FAIL expected: FAIL
@ -4466,4 +4457,3 @@
[HTMLElement interface: document.createElement("noscript") must inherit property "onwebkittransitionend" with the proper type] [HTMLElement interface: document.createElement("noscript") must inherit property "onwebkittransitionend" with the proper type]
expected: FAIL expected: FAIL

View file

@ -12,9 +12,6 @@
[form.dir: 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] [form.dir: 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 expected: FAIL
[form.dir: setAttribute() to undefined followed by IDL get]
expected: FAIL
[form.dir: setAttribute() to 7 followed by IDL get] [form.dir: setAttribute() to 7 followed by IDL get]
expected: FAIL expected: FAIL
@ -1188,135 +1185,6 @@
[fieldset.tabIndex: IDL set to -2147483648 followed by getAttribute()] [fieldset.tabIndex: IDL set to -2147483648 followed by getAttribute()]
expected: FAIL expected: FAIL
[fieldset.name: typeof IDL attribute]
expected: FAIL
[fieldset.name: IDL get with DOM attribute unset]
expected: FAIL
[fieldset.name: setAttribute() to "" followed by IDL get]
expected: FAIL
[fieldset.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
[fieldset.name: setAttribute() to undefined followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to 7 followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to 1.5 followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to true followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to false followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to object "[object Object\]" followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to NaN followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to Infinity followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to -Infinity followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to "\\0" followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to null followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to object "test-toString" followed by IDL get]
expected: FAIL
[fieldset.name: setAttribute() to object "test-valueOf" followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to "" followed by getAttribute()]
expected: FAIL
[fieldset.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
[fieldset.name: IDL set to undefined followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to undefined followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to 7 followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to 7 followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to 1.5 followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to 1.5 followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to true followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to true followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to false followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to false followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to object "[object Object\]" followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to object "[object Object\]" followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to NaN followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to NaN followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to Infinity followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to Infinity followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to -Infinity followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to -Infinity followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to "\\0" followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to null followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to null followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to object "test-toString" followed by getAttribute()]
expected: FAIL
[fieldset.name: IDL set to object "test-toString" followed by IDL get]
expected: FAIL
[fieldset.name: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL
[fieldset.itemScope: typeof IDL attribute] [fieldset.itemScope: typeof IDL attribute]
expected: FAIL expected: FAIL
@ -12261,135 +12129,6 @@
[output.tabIndex: IDL set to -2147483648 followed by getAttribute()] [output.tabIndex: IDL set to -2147483648 followed by getAttribute()]
expected: FAIL expected: FAIL
[output.name: typeof IDL attribute]
expected: FAIL
[output.name: IDL get with DOM attribute unset]
expected: FAIL
[output.name: setAttribute() to "" followed by IDL get]
expected: FAIL
[output.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
[output.name: setAttribute() to undefined followed by IDL get]
expected: FAIL
[output.name: setAttribute() to 7 followed by IDL get]
expected: FAIL
[output.name: setAttribute() to 1.5 followed by IDL get]
expected: FAIL
[output.name: setAttribute() to true followed by IDL get]
expected: FAIL
[output.name: setAttribute() to false followed by IDL get]
expected: FAIL
[output.name: setAttribute() to object "[object Object\]" followed by IDL get]
expected: FAIL
[output.name: setAttribute() to NaN followed by IDL get]
expected: FAIL
[output.name: setAttribute() to Infinity followed by IDL get]
expected: FAIL
[output.name: setAttribute() to -Infinity followed by IDL get]
expected: FAIL
[output.name: setAttribute() to "\\0" followed by IDL get]
expected: FAIL
[output.name: setAttribute() to null followed by IDL get]
expected: FAIL
[output.name: setAttribute() to object "test-toString" followed by IDL get]
expected: FAIL
[output.name: setAttribute() to object "test-valueOf" followed by IDL get]
expected: FAIL
[output.name: IDL set to "" followed by getAttribute()]
expected: FAIL
[output.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
[output.name: IDL set to undefined followed by getAttribute()]
expected: FAIL
[output.name: IDL set to undefined followed by IDL get]
expected: FAIL
[output.name: IDL set to 7 followed by getAttribute()]
expected: FAIL
[output.name: IDL set to 7 followed by IDL get]
expected: FAIL
[output.name: IDL set to 1.5 followed by getAttribute()]
expected: FAIL
[output.name: IDL set to 1.5 followed by IDL get]
expected: FAIL
[output.name: IDL set to true followed by getAttribute()]
expected: FAIL
[output.name: IDL set to true followed by IDL get]
expected: FAIL
[output.name: IDL set to false followed by getAttribute()]
expected: FAIL
[output.name: IDL set to false followed by IDL get]
expected: FAIL
[output.name: IDL set to object "[object Object\]" followed by getAttribute()]
expected: FAIL
[output.name: IDL set to object "[object Object\]" followed by IDL get]
expected: FAIL
[output.name: IDL set to NaN followed by getAttribute()]
expected: FAIL
[output.name: IDL set to NaN followed by IDL get]
expected: FAIL
[output.name: IDL set to Infinity followed by getAttribute()]
expected: FAIL
[output.name: IDL set to Infinity followed by IDL get]
expected: FAIL
[output.name: IDL set to -Infinity followed by getAttribute()]
expected: FAIL
[output.name: IDL set to -Infinity followed by IDL get]
expected: FAIL
[output.name: IDL set to "\\0" followed by getAttribute()]
expected: FAIL
[output.name: IDL set to null followed by getAttribute()]
expected: FAIL
[output.name: IDL set to null followed by IDL get]
expected: FAIL
[output.name: IDL set to object "test-toString" followed by getAttribute()]
expected: FAIL
[output.name: IDL set to object "test-toString" followed by IDL get]
expected: FAIL
[output.name: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL
[output.itemScope: typeof IDL attribute] [output.itemScope: typeof IDL attribute]
expected: FAIL expected: FAIL
@ -16842,96 +16581,6 @@
[fieldset.tabIndex: IDL set to -2147483648] [fieldset.tabIndex: IDL set to -2147483648]
expected: FAIL expected: FAIL
[fieldset.name: setAttribute() to ""]
expected: FAIL
[fieldset.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 "]
expected: FAIL
[fieldset.name: setAttribute() to undefined]
expected: FAIL
[fieldset.name: setAttribute() to 7]
expected: FAIL
[fieldset.name: setAttribute() to 1.5]
expected: FAIL
[fieldset.name: setAttribute() to true]
expected: FAIL
[fieldset.name: setAttribute() to false]
expected: FAIL
[fieldset.name: setAttribute() to object "[object Object\]"]
expected: FAIL
[fieldset.name: setAttribute() to NaN]
expected: FAIL
[fieldset.name: setAttribute() to Infinity]
expected: FAIL
[fieldset.name: setAttribute() to -Infinity]
expected: FAIL
[fieldset.name: setAttribute() to "\\0"]
expected: FAIL
[fieldset.name: setAttribute() to null]
expected: FAIL
[fieldset.name: setAttribute() to object "test-toString"]
expected: FAIL
[fieldset.name: setAttribute() to object "test-valueOf"]
expected: FAIL
[fieldset.name: IDL set to ""]
expected: FAIL
[fieldset.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 "]
expected: FAIL
[fieldset.name: IDL set to undefined]
expected: FAIL
[fieldset.name: IDL set to 7]
expected: FAIL
[fieldset.name: IDL set to 1.5]
expected: FAIL
[fieldset.name: IDL set to true]
expected: FAIL
[fieldset.name: IDL set to false]
expected: FAIL
[fieldset.name: IDL set to object "[object Object\]"]
expected: FAIL
[fieldset.name: IDL set to NaN]
expected: FAIL
[fieldset.name: IDL set to Infinity]
expected: FAIL
[fieldset.name: IDL set to -Infinity]
expected: FAIL
[fieldset.name: IDL set to "\\0"]
expected: FAIL
[fieldset.name: IDL set to null]
expected: FAIL
[fieldset.name: IDL set to object "test-toString"]
expected: FAIL
[fieldset.name: IDL set to object "test-valueOf"]
expected: FAIL
[legend.dir: setAttribute() to ""] [legend.dir: setAttribute() to ""]
expected: FAIL expected: FAIL
@ -22830,96 +22479,6 @@
[output.tabIndex: IDL set to -2147483648] [output.tabIndex: IDL set to -2147483648]
expected: FAIL expected: FAIL
[output.name: setAttribute() to ""]
expected: FAIL
[output.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 "]
expected: FAIL
[output.name: setAttribute() to undefined]
expected: FAIL
[output.name: setAttribute() to 7]
expected: FAIL
[output.name: setAttribute() to 1.5]
expected: FAIL
[output.name: setAttribute() to true]
expected: FAIL
[output.name: setAttribute() to false]
expected: FAIL
[output.name: setAttribute() to object "[object Object\]"]
expected: FAIL
[output.name: setAttribute() to NaN]
expected: FAIL
[output.name: setAttribute() to Infinity]
expected: FAIL
[output.name: setAttribute() to -Infinity]
expected: FAIL
[output.name: setAttribute() to "\\0"]
expected: FAIL
[output.name: setAttribute() to null]
expected: FAIL
[output.name: setAttribute() to object "test-toString"]
expected: FAIL
[output.name: setAttribute() to object "test-valueOf"]
expected: FAIL
[output.name: IDL set to ""]
expected: FAIL
[output.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 "]
expected: FAIL
[output.name: IDL set to undefined]
expected: FAIL
[output.name: IDL set to 7]
expected: FAIL
[output.name: IDL set to 1.5]
expected: FAIL
[output.name: IDL set to true]
expected: FAIL
[output.name: IDL set to false]
expected: FAIL
[output.name: IDL set to object "[object Object\]"]
expected: FAIL
[output.name: IDL set to NaN]
expected: FAIL
[output.name: IDL set to Infinity]
expected: FAIL
[output.name: IDL set to -Infinity]
expected: FAIL
[output.name: IDL set to "\\0"]
expected: FAIL
[output.name: IDL set to null]
expected: FAIL
[output.name: IDL set to object "test-toString"]
expected: FAIL
[output.name: IDL set to object "test-valueOf"]
expected: FAIL
[progress.dir: setAttribute() to ""] [progress.dir: setAttribute() to ""]
expected: FAIL expected: FAIL
@ -24135,9 +23694,6 @@
[button.autofocus: IDL set to "5%"] [button.autofocus: IDL set to "5%"]
expected: FAIL expected: FAIL
[fieldset.name: setAttribute() to "5%"]
expected: FAIL
[button.accessKey: IDL set to "5%"] [button.accessKey: IDL set to "5%"]
expected: FAIL expected: FAIL
@ -24153,9 +23709,6 @@
[form.accessKey: setAttribute() to "5%"] [form.accessKey: setAttribute() to "5%"]
expected: FAIL expected: FAIL
[fieldset.name: IDL set to "5%"]
expected: FAIL
[textarea.autofocus: setAttribute() to "5%"] [textarea.autofocus: setAttribute() to "5%"]
expected: FAIL expected: FAIL
@ -24231,8 +23784,6 @@
[option.accessKey: IDL set to "5%"] [option.accessKey: IDL set to "5%"]
expected: FAIL expected: FAIL
[output.name: IDL set to "5%"]
expected: FAIL
[select.accessKey: setAttribute() to "5%"] [select.accessKey: setAttribute() to "5%"]
expected: FAIL expected: FAIL
@ -24249,9 +23800,6 @@
[textarea.autofocus: IDL set to "5%"] [textarea.autofocus: IDL set to "5%"]
expected: FAIL expected: FAIL
[output.name: setAttribute() to "5%"]
expected: FAIL
[meter.accessKey: setAttribute() to "5%"] [meter.accessKey: setAttribute() to "5%"]
expected: FAIL expected: FAIL
@ -24513,9 +24061,6 @@
[select.autocomplete: IDL set to "+100"] [select.autocomplete: IDL set to "+100"]
expected: FAIL expected: FAIL
[fieldset.name: IDL set to ".5"]
expected: FAIL
[optgroup.dir: setAttribute() to ".5"] [optgroup.dir: setAttribute() to ".5"]
expected: FAIL expected: FAIL
@ -24567,9 +24112,6 @@
[form.dir: IDL set to ".5"] [form.dir: IDL set to ".5"]
expected: FAIL expected: FAIL
[output.name: IDL set to "+100"]
expected: FAIL
[textarea.accessKey: setAttribute() to ".5"] [textarea.accessKey: setAttribute() to ".5"]
expected: FAIL expected: FAIL
@ -24594,9 +24136,6 @@
[input.accessKey: IDL set to "+100"] [input.accessKey: IDL set to "+100"]
expected: FAIL expected: FAIL
[fieldset.name: IDL set to "+100"]
expected: FAIL
[optgroup.dir: setAttribute() to "+100"] [optgroup.dir: setAttribute() to "+100"]
expected: FAIL expected: FAIL
@ -24672,9 +24211,6 @@
[button.dir: IDL set to ".5"] [button.dir: IDL set to ".5"]
expected: FAIL expected: FAIL
[output.name: setAttribute() to ".5"]
expected: FAIL
[form.accessKey: setAttribute() to ".5"] [form.accessKey: setAttribute() to ".5"]
expected: FAIL expected: FAIL
@ -24687,9 +24223,6 @@
[textarea.autocomplete: IDL set to "+100"] [textarea.autocomplete: IDL set to "+100"]
expected: FAIL expected: FAIL
[output.name: IDL set to ".5"]
expected: FAIL
[button.dir: IDL set to "+100"] [button.dir: IDL set to "+100"]
expected: FAIL expected: FAIL
@ -24702,9 +24235,6 @@
[textarea.dir: setAttribute() to "+100"] [textarea.dir: setAttribute() to "+100"]
expected: FAIL expected: FAIL
[output.name: setAttribute() to "+100"]
expected: FAIL
[progress.accessKey: IDL set to ".5"] [progress.accessKey: IDL set to ".5"]
expected: FAIL expected: FAIL
@ -24816,9 +24346,6 @@
[label.dir: IDL set to "+100"] [label.dir: IDL set to "+100"]
expected: FAIL expected: FAIL
[fieldset.name: setAttribute() to "+100"]
expected: FAIL
[legend.align: setAttribute() to ".5"] [legend.align: setAttribute() to ".5"]
expected: FAIL expected: FAIL
@ -24837,9 +24364,6 @@
[label.dir: setAttribute() to ".5"] [label.dir: setAttribute() to ".5"]
expected: FAIL expected: FAIL
[fieldset.name: setAttribute() to ".5"]
expected: FAIL
[meter.accessKey: setAttribute() to "+100"] [meter.accessKey: setAttribute() to "+100"]
expected: FAIL expected: FAIL

View file

@ -1,5 +0,0 @@
[form-elements-nameditem-01.html]
type: testharness
[elements collection should include fieldsets]
expected: FAIL

View file

@ -0,0 +1,74 @@
<!DOCTYPE html>
<title>Only certain HTML elements reflect the name content attribute as a property</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
function doesReflect(tagName) {
var element = document.createElement(tagName);
element.setAttribute("name", "foo");
assert_equals(element.getAttribute("name"), "foo", "setAttribute should change content attribute");
element.name = "bar";
assert_equals(element.getAttribute("name"), "bar", "assignment to .name should change content attribute");
}
function doesNotReflect(tagName) {
var element = document.createElement(tagName);
element.setAttribute("name", "foo");
assert_equals(element.getAttribute("name"), "foo", "setAttribute should change content attribute");
element.name = "bar";
assert_equals(element.getAttribute("name"), "foo", "assignment to .name should not change content attribute");
}
var nonReflectingTagNames = [
"abbr", "acronym", "address", "area", "article", "aside", "audio",
"b", "base", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body","br",
"canvas", "caption", "center", "cite", "code", "col", "colgroup",
"data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt",
"em",
"figcaption", "figure", "font", "footer", "frameset",
"h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html",
"i", "ins", "isindex",
"kbd",
"label", "legend", "li", "link", "listing",
"main", "mark", "marquee", "meter", "multicol",
"nav", "nextid", "nobr", "noframes", "noscript",
"option",
"p", "picture", "plaintext", "pre", "progress",
"q",
"rp", "rt", "ruby",
"s", "samp", "script", "section", "small", "source", "spacer",
"span", "strike", "strong", "style", "sub", "summary", "sup",
"table", "tbody", "td", "template", "tfoot",
"th", "thead", "time", "title", "tr", "tt", "track",
"u", "ul",
"var", "video",
"wbr",
"xmp",
"unknown"
];
var reflectingTagNames = [
"a", "button", "embed",
"fieldset", "form", "frame",
"iframe", "img", "input",
"map", "meta",
"object", "output",
"param",
"select", "slot",
"textarea",
];
reflectingTagNames.forEach(function(tagName) {
test(function() {
doesReflect(tagName)
}, tagName + " element's name property reflects its content attribute");
});
nonReflectingTagNames.forEach(function(tagName) {
test(function() {
doesNotReflect(tagName)
}, tagName + " element's name property does not reflect its content attribute");
});
</script>