mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +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)
|
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<()> {
|
fn DeleteRow(&self, mut index: i32) -> Fallible<()> {
|
||||||
let rows = self.Rows();
|
let rows = self.Rows();
|
||||||
// Step 1.
|
let num_rows = rows.Length() as i32;
|
||||||
if index == -1 {
|
|
||||||
index = rows.Length() as i32 - 1;
|
// 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".
|
||||||
// Step 2.
|
if !(-1..num_rows).contains(&index) {
|
||||||
if index < 0 || index as u32 >= rows.Length() {
|
|
||||||
return Err(Error::IndexSize);
|
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();
|
DomRoot::upcast::<Node>(rows.Item(index as u32).unwrap()).remove_self();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[remove-row.html]
|
|
||||||
type: testharness
|
|
||||||
[deleteRow(-1) with no rows]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[remove-row.html]
|
|
||||||
[deleteRow(-1) with no rows]
|
|
||||||
expected: FAIL
|
|
Loading…
Add table
Add a link
Reference in a new issue