Auto merge of #25572 - pshaughn:atomnames, r=jdm

Make name content attributes consistently atoms and put them in rare_data for fast access

<!-- Please describe your changes on the following line: -->
All codepaths setting the name content attribute now use an atom, which is also stored in rare_data for direct lookup by a get_name method.

Paralleling the get_name method, I added a get_id method, which makes some internal id-lookup cases nicer.

A new test tests for a name setter on every HTML element type. In addition to its overt and upstreamable purpose of checking IDL property reflection semantics, for us this test also hits some Servo assertions that make sure the name is an atom in every case. If the test doesn't crash, even a failed test case still has the attribute as an atom rather than some other type. The failed cases are for elements that we have unimplemented or completely stubbed; I added a few missing name IDL properties to otherwise implemented elements.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25570 and make progress on #25057

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-02-13 14:04:25 -05:00 committed by GitHub
commit 9c135f0e95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 270 additions and 652 deletions

View file

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

View file

@ -1420,11 +1420,28 @@ impl Element {
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
pub fn get_attribute_by_name(&self, name: DOMString) -> Option<DomRoot<Attr>> {
let name = &self.parsed_name(name);
self.attrs
let maybe_attribute = self
.attrs
.borrow()
.iter()
.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(
@ -1819,6 +1836,14 @@ impl Element {
let other = other.upcast::<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 {
@ -1855,6 +1880,8 @@ impl ElementMethods for Element {
}
// 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 {
self.get_string_attribute(&local_name!("id"))
}
@ -2802,6 +2829,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
// the relevant super-classes.
@ -2820,6 +2861,7 @@ impl VirtualMethods for Element {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&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()),
_ => self
.super_type()

View file

@ -152,7 +152,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
make_getter!(Name, "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
make_getter!(Rev, "rev");

View file

@ -142,7 +142,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
make_getter!(Name, "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
make_getter!(Value, "value");

View file

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

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::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
@ -88,6 +89,12 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement {
// https://html.spec.whatwg.org/multipage/#dom-fieldset-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
fn GetForm(&self) -> Option<DomRoot<HTMLFormElement>> {
self.form_owner()

View file

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

View file

@ -62,10 +62,10 @@ use mime::{self, Mime};
use net_traits::http_percent_encode;
use net_traits::request::Referrer;
use script_traits::{HistoryEntryReplacement, LoadData, LoadOrigin};
use servo_atoms::Atom;
use servo_rand::random;
use std::borrow::ToOwned;
use std::cell::Cell;
use style::attr::AttrValue;
use style::str::split_html_space_chars;
use crate::dom::bindings::codegen::UnionTypes::RadioNodeListOrElement;
@ -86,7 +86,7 @@ pub struct HTMLFormElement {
elements: DomOnceCell<HTMLFormControlsCollection>,
generation_id: Cell<GenerationId>,
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 {
@ -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>() {
match mode {
RadioListMode::ControlsExceptImageInputs => {
@ -127,10 +127,8 @@ impl HTMLFormElement {
.downcast::<HTMLElement>()
.map_or(false, |c| c.is_listed_element())
{
if (child.has_attribute(&local_name!("id")) &&
child.get_string_attribute(&local_name!("id")) == *name) ||
(child.has_attribute(&local_name!("name")) &&
child.get_string_attribute(&local_name!("name")) == *name)
if child.get_id().map_or(false, |i| i == *name) ||
child.get_name().map_or(false, |n| n == *name)
{
if let Some(inp) = child.downcast::<HTMLInputElement>() {
// input, only return it if it's not image-button state
@ -144,16 +142,9 @@ impl HTMLFormElement {
return false;
},
RadioListMode::Images => {
if child.is::<HTMLImageElement>() {
if (child.has_attribute(&local_name!("id")) &&
child.get_string_attribute(&local_name!("id")) == *name) ||
(child.has_attribute(&local_name!("name")) &&
child.get_string_attribute(&local_name!("name")) == *name)
{
return true;
}
}
return false;
return child.is::<HTMLImageElement>() &&
(child.get_id().map_or(false, |i| i == *name) ||
child.get_name().map_or(false, |n| n == *name));
},
}
}
@ -164,7 +155,7 @@ impl HTMLFormElement {
&self,
index: u32,
mode: RadioListMode,
name: &DOMString,
name: &Atom,
) -> Option<DomRoot<Node>> {
self.controls
.borrow()
@ -174,7 +165,7 @@ impl HTMLFormElement {
.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
.borrow()
.iter()
@ -333,14 +324,15 @@ impl HTMLFormElementMethods for HTMLFormElement {
fn NamedGetter(&self, name: DOMString) -> Option<RadioNodeListOrElement> {
let window = window_from_node(self);
let name = Atom::from(name);
// Step 1
let mut candidates =
RadioNodeList::new_controls_except_image_inputs(&window, self, name.clone());
let mut candidates = RadioNodeList::new_controls_except_image_inputs(&window, self, &name);
let mut candidates_length = candidates.Length();
// Step 2
if candidates_length == 0 {
candidates = RadioNodeList::new_images(&window, self, name.clone());
candidates = RadioNodeList::new_images(&window, self, &name);
candidates_length = candidates.Length();
}
@ -399,12 +391,12 @@ impl HTMLFormElementMethods for HTMLFormElement {
}
struct SourcedName {
name: DOMString,
name: Atom,
element: DomRoot<Element>,
source: SourcedNameSource,
}
let mut sourcedNamesVec: Vec<SourcedName> = Vec::new();
let mut sourced_names_vec: Vec<SourcedName> = Vec::new();
let controls = self.controls.borrow();
@ -414,21 +406,21 @@ impl HTMLFormElementMethods for HTMLFormElement {
.downcast::<HTMLElement>()
.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 {
name: child.get_string_attribute(&local_name!("id")),
name: id_atom,
element: DomRoot::from_ref(&*child),
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 {
name: child.get_string_attribute(&local_name!("name")),
name: name_atom,
element: DomRoot::from_ref(&*child),
source: SourcedNameSource::Name,
};
sourcedNamesVec.push(entry);
sourced_names_vec.push(entry);
}
}
}
@ -436,21 +428,21 @@ impl HTMLFormElementMethods for HTMLFormElement {
// Step 3
for child in controls.iter() {
if child.is::<HTMLImageElement>() {
if child.has_attribute(&local_name!("id")) {
if let Some(id_atom) = child.get_id() {
let entry = SourcedName {
name: child.get_string_attribute(&local_name!("id")),
name: id_atom,
element: DomRoot::from_ref(&*child),
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 {
name: child.get_string_attribute(&local_name!("name")),
name: name_atom,
element: DomRoot::from_ref(&*child),
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),
source: SourcedNameSource::Past(now() - val.1), // calculate difference now()-val.1 to find age
};
sourcedNamesVec.push(entry);
sourced_names_vec.push(entry);
}
// 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
// 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
.upcast::<Node>()
.CompareDocumentPosition(b.element.upcast::<Node>()) ==
@ -503,21 +495,21 @@ impl HTMLFormElementMethods for HTMLFormElement {
});
// 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
let mut namesVec: Vec<DOMString> = Vec::new();
for elem in sourcedNamesVec.iter() {
if namesVec
let mut names_vec: Vec<DOMString> = Vec::new();
for elem in sourced_names_vec.iter() {
if names_vec
.iter()
.find(|name| name.to_string() == elem.name.to_string())
.find(|name| &**name == &*elem.name)
.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)
}
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) {
self.super_type().unwrap().unbind_from_tree(context);

View file

@ -58,7 +58,7 @@ impl HTMLHeadElement {
.traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<Element>)
.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| {
elem.get_attribute(&ns!(), &local_name!("content"))
.is_some()

View file

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

View file

@ -1466,10 +1466,13 @@ impl HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#radio-button-group
fn radio_group_name(&self) -> Option<Atom> {
self.upcast::<Element>()
.get_attribute(&ns!(), &local_name!("name"))
.map(|name| name.value().as_atom().clone())
.filter(|name| name != &atom!(""))
self.upcast::<Element>().get_name().and_then(|name| {
if name == atom!("") {
None
} else {
Some(name)
}
})
}
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 {
match name {
&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!("type") => AttrValue::from_atomic(value.into()),
&local_name!("maxlength") => {

View file

@ -26,7 +26,6 @@ use parking_lot::RwLock;
use servo_arc::Arc;
use servo_config::pref;
use std::sync::atomic::AtomicBool;
use style::attr::AttrValue;
use style::media_queries::MediaList;
use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::{CssRule, CssRules, Origin, Stylesheet, StylesheetContents, ViewportRule};
@ -86,8 +85,8 @@ impl HTMLMetaElement {
fn process_attributes(&self) {
let element = self.upcast::<Element>();
if let Some(ref name) = element.get_attribute(&ns!(), &local_name!("name")) {
let name = name.value().to_ascii_lowercase();
if let Some(ref name) = element.get_name() {
let name = name.to_ascii_lowercase();
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
if name == "viewport" {
@ -137,8 +136,8 @@ impl HTMLMetaElement {
fn process_referrer_attribute(&self) {
let element = self.upcast::<Element>();
if let Some(ref name) = element.get_attribute(&ns!(), &local_name!("name")) {
let name = name.value().to_ascii_lowercase();
if let Some(ref name) = element.get_name() {
let name = name.to_ascii_lowercase();
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
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) {
if let Some(s) = self.super_type() {
s.attribute_mutated(attr, mutation);

View file

@ -114,6 +114,12 @@ impl HTMLOutputElementMethods for HTMLOutputElement {
fn Type(&self) -> DOMString {
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 {

View file

@ -234,7 +234,7 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
make_getter!(Name, "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
make_uint_getter!(Size, "size", DEFAULT_SELECT_SIZE);

View file

@ -220,7 +220,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
make_getter!(Name, "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
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::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlformelement::HTMLFormElement;
use crate::dom::node::{ChildrenMutation, Node};
use crate::dom::window::Window;
use dom_struct::dom_struct;
use servo_atoms::Atom;
use std::cell::Cell;
#[derive(JSTraceable, MallocSizeOf)]
@ -381,11 +381,11 @@ pub enum RadioListMode {
pub struct RadioList {
form: Dom<HTMLFormElement>,
mode: RadioListMode,
name: DOMString,
name: Atom,
}
impl RadioList {
pub fn new(form: &HTMLFormElement, mode: RadioListMode, name: DOMString) -> RadioList {
pub fn new(form: &HTMLFormElement, mode: RadioListMode, name: Atom) -> RadioList {
RadioList {
form: Dom::from_ref(form),
mode: mode,

View file

@ -16,6 +16,7 @@ use crate::dom::node::Node;
use crate::dom::nodelist::{NodeList, NodeListType, RadioList, RadioListMode};
use crate::dom::window::Window;
use dom_struct::dom_struct;
use servo_atoms::Atom;
#[dom_struct]
pub struct RadioNodeList {
@ -42,14 +43,14 @@ impl RadioNodeList {
pub fn new_controls_except_image_inputs(
window: &Window,
form: &HTMLFormElement,
name: DOMString,
name: &Atom,
) -> DomRoot<RadioNodeList> {
RadioNodeList::new(
window,
NodeListType::Radio(RadioList::new(
form,
RadioListMode::ControlsExceptImageInputs,
name,
name.clone(),
)),
)
}
@ -57,11 +58,11 @@ impl RadioNodeList {
pub fn new_images(
window: &Window,
form: &HTMLFormElement,
name: DOMString,
name: &Atom,
) -> DomRoot<RadioNodeList> {
RadioNodeList::new(
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::node::UniqueId;
use crate::dom::shadowroot::ShadowRoot;
use servo_atoms::Atom;
use std::rc::Rc;
//XXX(ferjm) Ideally merge NodeRareData and ElementRareData so they share
@ -42,4 +43,7 @@ pub struct ElementRareData {
pub custom_element_definition: Option<Rc<CustomElementDefinition>>,
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
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]
attribute boolean disabled;
readonly attribute HTMLFormElement? form;
// [CEReactions]
// attribute DOMString name;
[CEReactions]
attribute DOMString name;
//readonly attribute DOMString type;

View file

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

View file

@ -24,6 +24,7 @@ interface HTMLTextAreaElement : HTMLElement {
attribute long maxLength;
[CEReactions, SetterThrows]
attribute long minLength;
[CEReactions]
attribute DOMString name;
[CEReactions]
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.
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>,
/// The pipeline id of the currently active document.
/// May be None, when the currently active document is in another script thread.