Implement trusted types for remaining attribute sinks (#38784)

Additionally, several methods were updated with
spec comments. That's because the "adopt the document
from the element document" step was missing.

By adding these spec comments, I also restructured
some code to avoid duplication of mutation records
and custom element reaction queueing.

Node.textContent doesn't propagate the error yet,
as that method has a lot of separate callers of
elements that wouldn't fail. I will refactor those
in a follow-up PR to keep things manageable.

This implements part of the DOM integration from
https://github.com/whatwg/dom/pull/1268

Part of #36258

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
This commit is contained in:
Tim van der Lippe 2025-08-21 07:37:34 +02:00 committed by GitHub
parent dd7b2a5ee2
commit 3c89763b77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 223 additions and 1349 deletions

View file

@ -3340,18 +3340,19 @@ impl NodeMethods<crate::DomTypeHolder> for Node {
}
/// <https://dom.spec.whatwg.org/#dom-node-nodevalue>
fn SetNodeValue(&self, val: Option<DOMString>, can_gc: CanGc) {
fn SetNodeValue(&self, val: Option<DOMString>, can_gc: CanGc) -> Fallible<()> {
match self.type_id() {
NodeTypeId::Attr => {
let attr = self.downcast::<Attr>().unwrap();
attr.SetValue(val.unwrap_or_default(), can_gc);
attr.SetValue(val.unwrap_or_default(), can_gc)?;
},
NodeTypeId::CharacterData(_) => {
let character_data = self.downcast::<CharacterData>().unwrap();
character_data.SetData(val.unwrap_or_default());
},
_ => {},
}
};
Ok(())
}
/// <https://dom.spec.whatwg.org/#dom-node-textcontent>
@ -3390,7 +3391,8 @@ impl NodeMethods<crate::DomTypeHolder> for Node {
},
NodeTypeId::Attr => {
let attr = self.downcast::<Attr>().unwrap();
attr.SetValue(value, can_gc);
// TODO(#36258): Propagate failure to callers
let _ = attr.SetValue(value, can_gc);
},
NodeTypeId::CharacterData(..) => {
let characterdata = self.downcast::<CharacterData>().unwrap();