mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 23:09:08 +00:00
LibWeb: Implement HTMLTableSectionElement::deleteRow()
This commit is contained in:
parent
009588eb28
commit
cc2e08d9e9
Notes:
sideshowbarker
2024-07-17 17:32:11 +09:00
Author: https://github.com/IdanHo
Commit: cc2e08d9e9
Pull-request: https://github.com/SerenityOS/serenity/pull/13014
Reviewed-by: https://github.com/awesomekling ✅
3 changed files with 24 additions and 0 deletions
|
@ -59,4 +59,26 @@ DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableSectionElement::in
|
|||
return table_row;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/tables.html#dom-tbody-deleterow
|
||||
DOM::ExceptionOr<void> HTMLTableSectionElement::delete_row(long index)
|
||||
{
|
||||
auto rows_collection = rows();
|
||||
auto rows_collection_size = static_cast<long>(rows_collection->length());
|
||||
|
||||
// 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" DOMException.
|
||||
if (index < -1 || index >= rows_collection_size)
|
||||
return DOM::IndexSizeError::create("Index is negative or greater than or equal to the number of rows");
|
||||
|
||||
// 2. If index is −1, then remove the last element in the rows collection from this element, or do nothing if the rows collection is empty.
|
||||
if (index == -1) {
|
||||
if (rows_collection_size > 0)
|
||||
rows_collection->item(rows_collection_size - 1)->remove();
|
||||
}
|
||||
// 3. Otherwise, remove the indexth element in the rows collection from this element.
|
||||
else {
|
||||
rows_collection->item(index)->remove();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue