mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #25548 - pshaughn:docnamedgetter, r=jdm
Add SupportedPropertyNames to Document (also fix iframe getting) Existing test of named-getting an iframe now succeeds. I added a new test for Object.getOwnPropertyNames(document) based on my understanding of the spec; that test could use a second opinion. UPDATE: This was trying to do too many things in one PR as originally submitted. It is now using #25572 as a base, and I suggest reviewing that PR before this one to avoid duplicating review effort. --- <!-- 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 #7273 for all implemented named getters, fix #25146, and fix the iframe case only of #25145. <!-- 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:
commit
f020536215
11 changed files with 405 additions and 113 deletions
|
@ -1175,6 +1175,10 @@ impl Element {
|
|||
ns!()
|
||||
}
|
||||
|
||||
pub fn name_attribute(&self) -> Option<Atom> {
|
||||
self.rare_data().as_ref()?.name_attribute.clone()
|
||||
}
|
||||
|
||||
pub fn style_attribute(&self) -> &DomRefCell<Option<Arc<Locked<PropertyDeclarationBlock>>>> {
|
||||
&self.style_attribute
|
||||
}
|
||||
|
@ -1424,7 +1428,6 @@ impl Element {
|
|||
.iter()
|
||||
.find(|a| a.name() == name)
|
||||
.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 {
|
||||
|
@ -2802,25 +2805,25 @@ impl VirtualMethods for Element {
|
|||
if let Some(old_value) = old_value {
|
||||
let old_value = old_value.as_atom().clone();
|
||||
if let Some(ref shadow_root) = containing_shadow_root {
|
||||
shadow_root.unregister_named_element(self, old_value);
|
||||
shadow_root.unregister_element_id(self, old_value);
|
||||
} else {
|
||||
doc.unregister_named_element(self, old_value);
|
||||
doc.unregister_element_id(self, old_value);
|
||||
}
|
||||
}
|
||||
if value != atom!("") {
|
||||
if let Some(ref shadow_root) = containing_shadow_root {
|
||||
shadow_root.register_named_element(self, value);
|
||||
shadow_root.register_element_id(self, value);
|
||||
} else {
|
||||
doc.register_named_element(self, value);
|
||||
doc.register_element_id(self, value);
|
||||
}
|
||||
}
|
||||
},
|
||||
AttributeMutation::Removed => {
|
||||
if value != atom!("") {
|
||||
if let Some(ref shadow_root) = containing_shadow_root {
|
||||
shadow_root.unregister_named_element(self, value);
|
||||
shadow_root.unregister_element_id(self, value);
|
||||
} else {
|
||||
doc.unregister_named_element(self, value);
|
||||
doc.unregister_element_id(self, value);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -2838,8 +2841,27 @@ impl VirtualMethods for Element {
|
|||
None
|
||||
}
|
||||
});
|
||||
// TODO: notify the document about the name change
|
||||
// once it has a name_map (#25548)
|
||||
// Keep the document name_map up to date
|
||||
// (if we're not in shadow DOM)
|
||||
if node.is_connected() && node.containing_shadow_root().is_none() {
|
||||
let value = attr.value().as_atom().clone();
|
||||
match mutation {
|
||||
AttributeMutation::Set(old_value) => {
|
||||
if let Some(old_value) = old_value {
|
||||
let old_value = old_value.as_atom().clone();
|
||||
doc.unregister_element_name(self, old_value);
|
||||
}
|
||||
if value != atom!("") {
|
||||
doc.register_element_name(self, value);
|
||||
}
|
||||
},
|
||||
AttributeMutation::Removed => {
|
||||
if value != atom!("") {
|
||||
doc.unregister_element_name(self, value);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
// FIXME(emilio): This is pretty dubious, and should be done in
|
||||
|
@ -2895,11 +2917,17 @@ impl VirtualMethods for Element {
|
|||
|
||||
if let Some(ref value) = *self.id_attribute.borrow() {
|
||||
if let Some(shadow_root) = self.upcast::<Node>().containing_shadow_root() {
|
||||
shadow_root.register_named_element(self, value.clone());
|
||||
shadow_root.register_element_id(self, value.clone());
|
||||
} else {
|
||||
doc.register_named_element(self, value.clone());
|
||||
doc.register_element_id(self, value.clone());
|
||||
}
|
||||
}
|
||||
if let Some(ref value) = self.name_attribute() {
|
||||
if self.upcast::<Node>().containing_shadow_root().is_none() {
|
||||
doc.register_element_name(self, value.clone());
|
||||
}
|
||||
}
|
||||
|
||||
// This is used for layout optimization.
|
||||
doc.increment_dom_count();
|
||||
}
|
||||
|
@ -2932,7 +2960,10 @@ impl VirtualMethods for Element {
|
|||
doc.exit_fullscreen();
|
||||
}
|
||||
if let Some(ref value) = *self.id_attribute.borrow() {
|
||||
doc.unregister_named_element(self, value.clone());
|
||||
doc.unregister_element_id(self, value.clone());
|
||||
}
|
||||
if let Some(ref value) = self.name_attribute() {
|
||||
doc.unregister_element_name(self, value.clone());
|
||||
}
|
||||
// This is used for layout optimization.
|
||||
doc.decrement_dom_count();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue