aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorshanehandley <1322294+shanehandley@users.noreply.github.com>2024-04-08 01:09:22 +1000
committerGitHub <noreply@github.com>2024-04-07 15:09:22 +0000
commitddbec46e1fe6716e2cba5e073f62014c22539589 (patch)
tree6c48e725b06b4c9349443826eab9ce9ef790d6dd /components/script
parente0e34086501068af22f6df00ec9d0d2707a5494c (diff)
downloadservo-ddbec46e1fe6716e2cba5e073f62014c22539589.tar.gz
servo-ddbec46e1fe6716e2cba5e073f62014c22539589.zip
fix: Handle table.deleteRow with no rows (#32009)
* fix: Handle table.deleteRow with no rows * Respond to review, update legacy layout expectations
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/htmltableelement.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs
index bd2294611ed..9194578a96c 100644
--- a/components/script/dom/htmltableelement.rs
+++ b/components/script/dom/htmltableelement.rs
@@ -395,19 +395,32 @@ impl HTMLTableElementMethods for HTMLTableElement {
Ok(new_row)
}
- // https://html.spec.whatwg.org/multipage/#dom-table-deleterow
+ /// <https://html.spec.whatwg.org/multipage/#dom-table-deleterow>
fn DeleteRow(&self, mut index: i32) -> Fallible<()> {
let rows = self.Rows();
- // Step 1.
+ let num_rows = rows.Length() as i32;
+
+ // Step 1: If index is less than −1 or greater than or equal to the number of elements
+ // in the rows collection, then throw an "IndexSizeError".
+ if !(-1..num_rows).contains(&index) {
+ return Err(Error::IndexSize);
+ }
+
+ let num_rows = rows.Length() as i32;
+
+ // Step 2: If index is −1, then remove the last element in the rows collection from its
+ // parent, or do nothing if the rows collection is empty.
if index == -1 {
- index = rows.Length() as i32 - 1;
+ index = num_rows - 1;
}
- // Step 2.
- if index < 0 || index as u32 >= rows.Length() {
- return Err(Error::IndexSize);
+
+ if num_rows == 0 {
+ return Ok(());
}
- // Step 3.
+
+ // Step 3: Otherwise, remove the indexth element in the rows collection from its parent.
DomRoot::upcast::<Node>(rows.Item(index as u32).unwrap()).remove_self();
+
Ok(())
}