mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 17:48:37 +00:00
LibWeb/IDB: Implement IDBCursor::delete
This commit is contained in:
parent
cf84a98bab
commit
9c51326fcb
Notes:
github-actions[bot]
2025-05-13 16:49:53 +00:00
Author: https://github.com/stelar7
Commit: 9c51326fcb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4720
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/shannonbooth
3 changed files with 41 additions and 1 deletions
|
@ -381,4 +381,43 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBCursor::update(JS::Value value)
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#dom-idbcursor-update
|
||||||
|
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBCursor::delete_()
|
||||||
|
{
|
||||||
|
auto& realm = this->realm();
|
||||||
|
|
||||||
|
// 1. Let transaction be this’s transaction.
|
||||||
|
auto transaction = this->transaction();
|
||||||
|
|
||||||
|
// 2. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
||||||
|
if (transaction->state() != IDBTransaction::TransactionState::Active)
|
||||||
|
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while deleting cursor"_string);
|
||||||
|
|
||||||
|
// 3. If transaction is a read-only transaction, throw a "ReadOnlyError" DOMException.
|
||||||
|
if (transaction->is_readonly())
|
||||||
|
return WebIDL::ReadOnlyError::create(realm, "Transaction is read-only while deleting cursor"_string);
|
||||||
|
|
||||||
|
// FIXME: 4. If this’s source or effective object store has been deleted, throw an "InvalidStateError" DOMException.
|
||||||
|
|
||||||
|
// 5. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an "InvalidStateError" DOMException.
|
||||||
|
if (!m_got_value)
|
||||||
|
return WebIDL::InvalidStateError::create(realm, "Cursor is active or EOL while deleting"_string);
|
||||||
|
|
||||||
|
// 6. If this’s key only flag is true, throw an "InvalidStateError" DOMException.
|
||||||
|
if (m_key_only)
|
||||||
|
return WebIDL::InvalidStateError::create(realm, "Cursor is key-only while deleting"_string);
|
||||||
|
|
||||||
|
// 7. Let operation be an algorithm to run delete records from an object store with this’s effective object store and this’s effective key.
|
||||||
|
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [this, &realm] -> WebIDL::ExceptionOr<JS::Value> {
|
||||||
|
auto effective_key = this->effective_key();
|
||||||
|
auto range = IDBKeyRange::create(realm, effective_key, effective_key, IDBKeyRange::LowerOpen::No, IDBKeyRange::UpperOpen::No);
|
||||||
|
return delete_records_from_an_object_store(*this->effective_object_store(), range);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 8. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation.
|
||||||
|
auto request = asynchronously_execute_a_request(realm, GC::Ref(*this), operation);
|
||||||
|
dbgln_if(IDB_DEBUG, "Executing request for cursor delete with uuid {}", request->uuid());
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
WebIDL::ExceptionOr<void> continue_primary_key(JS::Value, JS::Value);
|
WebIDL::ExceptionOr<void> continue_primary_key(JS::Value, JS::Value);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> update(JS::Value);
|
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> update(JS::Value);
|
||||||
|
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> delete_();
|
||||||
|
|
||||||
[[nodiscard]] JS::Value value() { return m_value.value_or(JS::js_undefined()); }
|
[[nodiscard]] JS::Value value() { return m_value.value_or(JS::js_undefined()); }
|
||||||
[[nodiscard]] GC::Ref<IDBKeyRange> range() { return m_range; }
|
[[nodiscard]] GC::Ref<IDBKeyRange> range() { return m_range; }
|
||||||
|
|
|
@ -11,7 +11,7 @@ interface IDBCursor {
|
||||||
undefined continue(optional any key);
|
undefined continue(optional any key);
|
||||||
undefined continuePrimaryKey(any key, any primaryKey);
|
undefined continuePrimaryKey(any key, any primaryKey);
|
||||||
[NewObject] IDBRequest update(any value);
|
[NewObject] IDBRequest update(any value);
|
||||||
[FIXME, NewObject] IDBRequest delete();
|
[NewObject] IDBRequest delete();
|
||||||
};
|
};
|
||||||
|
|
||||||
enum IDBCursorDirection {
|
enum IDBCursorDirection {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue