Return error when setting invalid <table> caption (#30020)

* Return error when setting invalid <table> caption

Signed-off-by: thesecretmaster <thesecretmaster@developingtechnician.com>

* Forgot to commit style changes

Signed-off-by: thesecretmaster <thesecretmaster@developingtechnician.com>

---------

Signed-off-by: thesecretmaster <thesecretmaster@developingtechnician.com>
This commit is contained in:
thesecretmaster 2023-08-08 11:30:55 -05:00 committed by GitHub
parent bce7622cde
commit c28404e9fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View file

@ -188,16 +188,17 @@ impl HTMLTableElementMethods for HTMLTableElement {
}
// https://html.spec.whatwg.org/multipage/#dom-table-caption
fn SetCaption(&self, new_caption: Option<&HTMLTableCaptionElement>) {
fn SetCaption(&self, new_caption: Option<&HTMLTableCaptionElement>) -> Fallible<()> {
if let Some(ref caption) = self.GetCaption() {
caption.upcast::<Node>().remove_self();
}
if let Some(caption) = new_caption {
let node = self.upcast::<Node>();
node.InsertBefore(caption.upcast(), node.GetFirstChild().as_deref())
.expect("Insertion failed");
node.InsertBefore(caption.upcast(), node.GetFirstChild().as_deref())?;
}
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-table-createcaption
@ -211,7 +212,8 @@ impl HTMLTableElementMethods for HTMLTableElement {
&document_from_node(self),
None,
);
self.SetCaption(Some(&caption));
self.SetCaption(Some(&caption))
.expect("Generated caption is invalid");
caption
},
}

View file

@ -7,7 +7,7 @@
interface HTMLTableElement : HTMLElement {
[HTMLConstructor] constructor();
[CEReactions]
[CEReactions, SetterThrows]
attribute HTMLTableCaptionElement? caption;
HTMLTableCaptionElement createCaption();
[CEReactions]