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]