From 5d486528906ee1d0b56a084d506baf788f6a186a Mon Sep 17 00:00:00 2001 From: stelar7 Date: Fri, 11 Apr 2025 11:42:19 +0200 Subject: [PATCH] LibWeb/IDB: Implement IDBObjectStore::put --- Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp | 7 +++++++ Libraries/LibWeb/IndexedDB/IDBObjectStore.h | 1 + Libraries/LibWeb/IndexedDB/IDBObjectStore.idl | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp index bb61e159eb8..2f85a046363 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp @@ -324,4 +324,11 @@ WebIDL::ExceptionOr> IDBObjectStore::add(JS::Value value, Op return add_or_put(*this, value, key, true); } +// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-put +WebIDL::ExceptionOr> IDBObjectStore::put(JS::Value value, Optional const& key) +{ + // The put(value, key) method steps are to return the result of running add or put with this, value, key and the no-overwrite flag false. + return add_or_put(*this, value, key, false); +} + } diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h index fd82690131a..01f949f6f52 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h @@ -46,6 +46,7 @@ public: [[nodiscard]] WebIDL::ExceptionOr> add_or_put(GC::Ref, JS::Value, Optional const&, bool); [[nodiscard]] WebIDL::ExceptionOr> add(JS::Value value, Optional const& key); + [[nodiscard]] WebIDL::ExceptionOr> put(JS::Value value, Optional const& key); protected: explicit IDBObjectStore(JS::Realm&, GC::Ref, GC::Ref); diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl b/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl index 1cc08285528..46a43c2ab29 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl @@ -10,7 +10,7 @@ interface IDBObjectStore { [SameObject] readonly attribute IDBTransaction transaction; readonly attribute boolean autoIncrement; - [FIXME, NewObject] IDBRequest put(any value, optional any key); + [NewObject] IDBRequest put(any value, optional any key); [NewObject] IDBRequest add(any value, optional any key); [FIXME, NewObject] IDBRequest delete(any query); [FIXME, NewObject] IDBRequest clear();