diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 5428df526fe..4081f101e4b 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -516,6 +516,7 @@ set(SOURCES IndexedDB/IDBFactory.cpp IndexedDB/IDBOpenDBRequest.cpp IndexedDB/IDBIndex.cpp + IndexedDB/IDBObjectStore.cpp IndexedDB/IDBRequest.cpp IndexedDB/IDBVersionChangeEvent.cpp Internals/Inspector.cpp diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 440690bc68f..73d80632bc0 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -578,6 +578,7 @@ class IDBCursor; class IDBDatabase; class IDBFactory; class IDBIndex; +class IDBObjectStore; class IDBOpenDBRequest; class IDBRequest; class IDBVersionChangeEvent; diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp new file mode 100644 index 00000000000..c93373cec2b --- /dev/null +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, stelar7 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::IndexedDB { + +GC_DEFINE_ALLOCATOR(IDBObjectStore); + +IDBObjectStore::~IDBObjectStore() = default; + +IDBObjectStore::IDBObjectStore(JS::Realm& realm) + : PlatformObject(realm) +{ +} + +GC::Ref IDBObjectStore::create(JS::Realm& realm) +{ + return realm.create(realm); +} + +void IDBObjectStore::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBObjectStore); +} + +} diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h new file mode 100644 index 00000000000..08cd335c557 --- /dev/null +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024, stelar7 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::IndexedDB { + +// https://w3c.github.io/IndexedDB/#object-store-interface +class IDBObjectStore : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(IDBObjectStore, Bindings::PlatformObject); + GC_DECLARE_ALLOCATOR(IDBObjectStore); + +public: + virtual ~IDBObjectStore() override; + [[nodiscard]] static GC::Ref create(JS::Realm&); + +protected: + explicit IDBObjectStore(JS::Realm&); + virtual void initialize(JS::Realm&) override; +}; + +} diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl b/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl new file mode 100644 index 00000000000..de929eb3e24 --- /dev/null +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl @@ -0,0 +1,32 @@ +#import +#import +#import + +[Exposed=(Window,Worker)] +interface IDBObjectStore { + [FIXME] attribute DOMString name; + [FIXME] readonly attribute any keyPath; + [FIXME] readonly attribute DOMStringList indexNames; + [FIXME, SameObject] readonly attribute IDBTransaction transaction; + [FIXME] readonly attribute boolean autoIncrement; + + [FIXME, NewObject] IDBRequest put(any value, optional any key); + [FIXME, NewObject] IDBRequest add(any value, optional any key); + [FIXME, NewObject] IDBRequest delete(any query); + [FIXME, NewObject] IDBRequest clear(); + [FIXME, NewObject] IDBRequest get(any query); + [FIXME, NewObject] IDBRequest getKey(any query); + [FIXME, NewObject] IDBRequest getAll(optional any query, optional [EnforceRange] unsigned long count); + [FIXME, NewObject] IDBRequest getAllKeys(optional any query, optional [EnforceRange] unsigned long count); + [FIXME, NewObject] IDBRequest count(optional any query); + [FIXME, NewObject] IDBRequest openCursor(optional any query, optional IDBCursorDirection direction = "next"); + [FIXME, NewObject] IDBRequest openKeyCursor(optional any query, optional IDBCursorDirection direction = "next"); + [FIXME] IDBIndex index(DOMString name); + [FIXME, NewObject] IDBIndex createIndex(DOMString name, (DOMString or sequence) keyPath, optional IDBIndexParameters options = {}); + [FIXME] undefined deleteIndex(DOMString name); +}; + +dictionary IDBIndexParameters { + boolean unique = false; + boolean multiEntry = false; +}; diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake index e7f44fecffc..323330734f4 100644 --- a/Libraries/LibWeb/idl_files.cmake +++ b/Libraries/LibWeb/idl_files.cmake @@ -249,6 +249,7 @@ libweb_js_bindings(IndexedDB/IDBCursor) libweb_js_bindings(IndexedDB/IDBDatabase) libweb_js_bindings(IndexedDB/IDBFactory) libweb_js_bindings(IndexedDB/IDBIndex) +libweb_js_bindings(IndexedDB/IDBObjectStore) libweb_js_bindings(IndexedDB/IDBOpenDBRequest) libweb_js_bindings(IndexedDB/IDBRequest) libweb_js_bindings(IndexedDB/IDBVersionChangeEvent) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 803e7cd8ac7..6f025961093 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -61,6 +61,7 @@ static bool is_platform_object(Type const& type) "HTMLCollection"sv, "IDBCursor"sv, "IDBIndex"sv, + "IDBObjectStore"sv, "ImageBitmap"sv, "ImageData"sv, "Instance"sv, diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index 26ff077bf42..ddde15c2cfa 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -203,6 +203,7 @@ IDBCursor IDBDatabase IDBFactory IDBIndex +IDBObjectStore IDBOpenDBRequest IDBRequest IDBVersionChangeEvent