LibWeb: Implement DataTransferItemList.clear()

This commit is contained in:
Tim Ledbetter 2025-09-05 07:37:05 +01:00 committed by Jelle Raaijmakers
commit 3fc7613bf1
Notes: github-actions[bot] 2025-09-12 10:31:38 +00:00
3 changed files with 11 additions and 1 deletions

View file

@ -125,6 +125,15 @@ WebIDL::ExceptionOr<void> DataTransferItemList::remove(WebIDL::UnsignedLong inde
return {};
}
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-clear
void DataTransferItemList::clear()
{
// The clear() method, if the DataTransferItemList object is in the read/write mode, must remove all the items from
// the drag data store. Otherwise, it must do nothing.
if (m_data_transfer->mode() == DragDataStore::Mode::ReadWrite)
m_data_transfer->clear_data();
}
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-item
Optional<JS::Value> DataTransferItemList::item_value(size_t index) const
{

View file

@ -27,6 +27,7 @@ public:
WebIDL::ExceptionOr<GC::Ptr<DataTransferItem>> add(String const& data, String const& type);
GC::Ptr<DataTransferItem> add(GC::Ref<FileAPI::File>);
WebIDL::ExceptionOr<void> remove(WebIDL::UnsignedLong index);
void clear();
private:
DataTransferItemList(JS::Realm&, GC::Ref<DataTransfer>);

View file

@ -9,5 +9,5 @@ interface DataTransferItemList {
DataTransferItem? add(DOMString data, DOMString type);
DataTransferItem? add(File data);
undefined remove(unsigned long index);
[FIXME] undefined clear();
undefined clear();
};