From c28404e9fa57c134210b92a7736833f3ac04dd28 Mon Sep 17 00:00:00 2001
From: thesecretmaster <15304293+thesecretmaster@users.noreply.github.com>
Date: Tue, 8 Aug 2023 11:30:55 -0500
Subject: [PATCH] Return error when setting invalid
caption (#30020)
* Return error when setting invalid caption
Signed-off-by: thesecretmaster
* Forgot to commit style changes
Signed-off-by: thesecretmaster
---------
Signed-off-by: thesecretmaster
---
components/script/dom/htmltableelement.rs | 10 ++++++----
components/script/dom/webidls/HTMLTableElement.webidl | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs
index 50a1152fb7c..6ce8c0569e1 100644
--- a/components/script/dom/htmltableelement.rs
+++ b/components/script/dom/htmltableelement.rs
@@ -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::().remove_self();
}
if let Some(caption) = new_caption {
let node = self.upcast::();
- 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
},
}
diff --git a/components/script/dom/webidls/HTMLTableElement.webidl b/components/script/dom/webidls/HTMLTableElement.webidl
index 72a151fc858..c9342cc2722 100644
--- a/components/script/dom/webidls/HTMLTableElement.webidl
+++ b/components/script/dom/webidls/HTMLTableElement.webidl
@@ -7,7 +7,7 @@
interface HTMLTableElement : HTMLElement {
[HTMLConstructor] constructor();
- [CEReactions]
+ [CEReactions, SetterThrows]
attribute HTMLTableCaptionElement? caption;
HTMLTableCaptionElement createCaption();
[CEReactions]