mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-15 13:31:54 +00:00
LibWeb/IDB: Implement IDBObjectStore::clear
This commit is contained in:
parent
637f35c0eb
commit
fa207c8fc6
Notes:
github-actions[bot]
2025-05-08 13:14:20 +00:00
Author: https://github.com/stelar7
Commit: fa207c8fc6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4650
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 34 additions and 1 deletions
|
@ -474,4 +474,36 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::delete_(JS::Value query
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-clear
|
||||||
|
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::clear()
|
||||||
|
{
|
||||||
|
auto& realm = this->realm();
|
||||||
|
|
||||||
|
// 1. Let transaction be this’s transaction.
|
||||||
|
auto transaction = this->transaction();
|
||||||
|
|
||||||
|
// 2. Let store be this’s object store.
|
||||||
|
auto store = this->store();
|
||||||
|
|
||||||
|
// FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException.
|
||||||
|
|
||||||
|
// 4. 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 clearing object store"_string);
|
||||||
|
|
||||||
|
// 5. 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 clearing object store"_string);
|
||||||
|
|
||||||
|
// 6. Let operation be an algorithm to run clear an object store with store.
|
||||||
|
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [store] -> WebIDL::ExceptionOr<JS::Value> {
|
||||||
|
return clear_an_object_store(store);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation.
|
||||||
|
auto result = asynchronously_execute_a_request(realm, GC::Ref(*this), operation);
|
||||||
|
dbgln_if(IDB_DEBUG, "Executing request for clear with uuid {}", result->uuid());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ public:
|
||||||
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get(JS::Value);
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get(JS::Value);
|
||||||
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next);
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next);
|
||||||
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> delete_(JS::Value);
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> delete_(JS::Value);
|
||||||
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> clear();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
||||||
|
|
|
@ -13,7 +13,7 @@ interface IDBObjectStore {
|
||||||
[NewObject] IDBRequest put(any value, optional any key);
|
[NewObject] IDBRequest put(any value, optional any key);
|
||||||
[NewObject] IDBRequest add(any value, optional any key);
|
[NewObject] IDBRequest add(any value, optional any key);
|
||||||
[NewObject] IDBRequest delete(any query);
|
[NewObject] IDBRequest delete(any query);
|
||||||
[FIXME, NewObject] IDBRequest clear();
|
[NewObject] IDBRequest clear();
|
||||||
[NewObject] IDBRequest get(any query);
|
[NewObject] IDBRequest get(any query);
|
||||||
[FIXME, NewObject] IDBRequest getKey(any query);
|
[FIXME, NewObject] IDBRequest getKey(any query);
|
||||||
[FIXME, NewObject] IDBRequest getAll(optional any query, optional [EnforceRange] unsigned long count);
|
[FIXME, NewObject] IDBRequest getAll(optional any query, optional [EnforceRange] unsigned long count);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue