mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb/IDB: Implement IDBObjectStore::delete
This commit is contained in:
parent
1fe6060ff9
commit
aa35ced34f
Notes:
github-actions[bot]
2025-05-08 13:14:32 +00:00
Author: https://github.com/stelar7
Commit: aa35ced34f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4650
Reviewed-by: https://github.com/AtkinsSJ ✅
5 changed files with 40 additions and 3 deletions
|
@ -439,4 +439,39 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::open_cursor(JS::Value q
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-delete
|
||||||
|
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::delete_(JS::Value query)
|
||||||
|
{
|
||||||
|
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 deleting 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 deleting object store"_string);
|
||||||
|
|
||||||
|
// 6. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
|
||||||
|
auto range = TRY(convert_a_value_to_a_key_range(realm, query, true));
|
||||||
|
|
||||||
|
// 7. Let operation be an algorithm to run delete records from an object store with store and range.
|
||||||
|
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [store, range] -> WebIDL::ExceptionOr<JS::Value> {
|
||||||
|
return delete_records_from_an_object_store(store, range);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 8. 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 delete with uuid {}", result->uuid());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> count(Optional<JS::Value>);
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> count(Optional<JS::Value>);
|
||||||
[[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);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
||||||
|
|
|
@ -12,7 +12,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);
|
||||||
[FIXME, NewObject] IDBRequest delete(any query);
|
[NewObject] IDBRequest delete(any query);
|
||||||
[FIXME, NewObject] IDBRequest clear();
|
[FIXME, 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);
|
||||||
|
|
|
@ -1312,7 +1312,7 @@ void inject_a_key_into_a_value_using_a_key_path(JS::Realm& realm, JS::Value valu
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/IndexedDB/#delete-records-from-an-object-store
|
// https://w3c.github.io/IndexedDB/#delete-records-from-an-object-store
|
||||||
void delete_records_from_an_object_store(GC::Ref<ObjectStore> store, GC::Ref<IDBKeyRange> range)
|
JS::Value delete_records_from_an_object_store(GC::Ref<ObjectStore> store, GC::Ref<IDBKeyRange> range)
|
||||||
{
|
{
|
||||||
// 1. Remove all records, if any, from store’s list of records with key in range.
|
// 1. Remove all records, if any, from store’s list of records with key in range.
|
||||||
store->remove_records_in_range(range);
|
store->remove_records_in_range(range);
|
||||||
|
@ -1320,6 +1320,7 @@ void delete_records_from_an_object_store(GC::Ref<ObjectStore> store, GC::Ref<IDB
|
||||||
// FIXME: 2. For each index which references store, remove every record from index’s list of records whose value is in range, if any such records exist.
|
// FIXME: 2. For each index which references store, remove every record from index’s list of records whose value is in range, if any such records exist.
|
||||||
|
|
||||||
// 3. Return undefined.
|
// 3. Return undefined.
|
||||||
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/IndexedDB/#store-a-record-into-an-object-store
|
// https://w3c.github.io/IndexedDB/#store-a-record-into-an-object-store
|
||||||
|
|
|
@ -39,7 +39,7 @@ GC::Ref<IDBRequest> asynchronously_execute_a_request(JS::Realm&, IDBRequestSourc
|
||||||
ErrorOr<u64> generate_a_key(GC::Ref<ObjectStore>);
|
ErrorOr<u64> generate_a_key(GC::Ref<ObjectStore>);
|
||||||
void possibly_update_the_key_generator(GC::Ref<ObjectStore>, GC::Ref<Key>);
|
void possibly_update_the_key_generator(GC::Ref<ObjectStore>, GC::Ref<Key>);
|
||||||
void inject_a_key_into_a_value_using_a_key_path(JS::Realm&, JS::Value, GC::Ref<Key>, KeyPath const&);
|
void inject_a_key_into_a_value_using_a_key_path(JS::Realm&, JS::Value, GC::Ref<Key>, KeyPath const&);
|
||||||
void delete_records_from_an_object_store(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
JS::Value delete_records_from_an_object_store(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
||||||
WebIDL::ExceptionOr<GC::Ptr<Key>> store_a_record_into_an_object_store(JS::Realm&, GC::Ref<ObjectStore>, JS::Value, GC::Ptr<Key>, bool);
|
WebIDL::ExceptionOr<GC::Ptr<Key>> store_a_record_into_an_object_store(JS::Realm&, GC::Ref<ObjectStore>, JS::Value, GC::Ptr<Key>, bool);
|
||||||
WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Realm&, Optional<JS::Value>, bool = false);
|
WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Realm&, Optional<JS::Value>, bool = false);
|
||||||
JS::Value count_the_records_in_a_range(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
JS::Value count_the_records_in_a_range(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue