mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
fix: Handle table.deleteRow with no rows (#32009)
* fix: Handle table.deleteRow with no rows * Respond to review, update legacy layout expectations
This commit is contained in:
parent
e0e3408650
commit
ddbec46e1f
3 changed files with 21 additions and 16 deletions
|
@ -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.
|
||||
if index == -1 {
|
||||
index = rows.Length() as i32 - 1;
|
||||
}
|
||||
// Step 2.
|
||||
if index < 0 || index as u32 >= rows.Length() {
|
||||
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);
|
||||
}
|
||||
// Step 3.
|
||||
|
||||
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 = num_rows - 1;
|
||||
}
|
||||
|
||||
if num_rows == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// 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(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue