mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Properly change the kind of the given attribute in SetAttributeNode
The given argument may have special meaning for the element to which we add it, and thus may have a specific representation to which we should switch the attribute current's value. Fixes #18357.
This commit is contained in:
parent
7dcd3ae50d
commit
86285e542a
1 changed files with 10 additions and 5 deletions
|
@ -1649,10 +1649,6 @@ impl ElementMethods for Element {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-element-setattributenode
|
// https://dom.spec.whatwg.org/#dom-element-setattributenode
|
||||||
fn SetAttributeNode(&self, attr: &Attr) -> Fallible<Option<Root<Attr>>> {
|
fn SetAttributeNode(&self, attr: &Attr) -> Fallible<Option<Root<Attr>>> {
|
||||||
// Workaround for https://github.com/servo/servo/issues/17366
|
|
||||||
// This ensures that if this is an "id" attr, its value is an Atom
|
|
||||||
attr.swap_value(&mut self.parse_plain_attribute(attr.local_name(), attr.Value()));
|
|
||||||
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
if let Some(owner) = attr.GetOwnerElement() {
|
if let Some(owner) = attr.GetOwnerElement() {
|
||||||
if &*owner != self {
|
if &*owner != self {
|
||||||
|
@ -1660,6 +1656,15 @@ impl ElementMethods for Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let vtable = vtable_for(self.upcast());
|
||||||
|
|
||||||
|
// This ensures that the attribute is of the expected kind for this
|
||||||
|
// specific element. This is inefficient and should probably be done
|
||||||
|
// differently.
|
||||||
|
attr.swap_value(
|
||||||
|
&mut vtable.parse_plain_attribute(attr.local_name(), attr.Value()),
|
||||||
|
);
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
let position = self.attrs.borrow().iter().position(|old_attr| {
|
let position = self.attrs.borrow().iter().position(|old_attr| {
|
||||||
attr.namespace() == old_attr.namespace() && attr.local_name() == old_attr.local_name()
|
attr.namespace() == old_attr.namespace() && attr.local_name() == old_attr.local_name()
|
||||||
|
@ -1688,7 +1693,7 @@ impl ElementMethods for Element {
|
||||||
self.attrs.borrow_mut()[position] = JS::from_ref(attr);
|
self.attrs.borrow_mut()[position] = JS::from_ref(attr);
|
||||||
old_attr.set_owner(None);
|
old_attr.set_owner(None);
|
||||||
if attr.namespace() == &ns!() {
|
if attr.namespace() == &ns!() {
|
||||||
vtable_for(self.upcast()).attribute_mutated(
|
vtable.attribute_mutated(
|
||||||
&attr, AttributeMutation::Set(Some(&old_attr.value())));
|
&attr, AttributeMutation::Set(Some(&old_attr.value())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue