diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 21409cc74c1..fc7c4b4d690 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -512,6 +512,7 @@ set(SOURCES IndexedDB/Internal/Database.cpp IndexedDB/Internal/Key.cpp IndexedDB/IDBDatabase.cpp + IndexedDB/IDBCursor.cpp IndexedDB/IDBFactory.cpp IndexedDB/IDBOpenDBRequest.cpp IndexedDB/IDBRequest.cpp diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 46383286d9b..ecfbd198ec0 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -574,6 +574,7 @@ class Performance; namespace Web::IndexedDB { class Database; +class IDBCursor; class IDBFactory; class IDBDatabase; class IDBOpenDBRequest; diff --git a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp b/Libraries/LibWeb/IndexedDB/IDBCursor.cpp new file mode 100644 index 00000000000..f00e94714f7 --- /dev/null +++ b/Libraries/LibWeb/IndexedDB/IDBCursor.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(IDBCursor); + +IDBCursor::~IDBCursor() = default; + +IDBCursor::IDBCursor(JS::Realm& realm) + : PlatformObject(realm) +{ +} + +GC::Ref IDBCursor::create(JS::Realm& realm) +{ + return realm.create(realm); +} + +void IDBCursor::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBCursor); +} + +} diff --git a/Libraries/LibWeb/IndexedDB/IDBCursor.h b/Libraries/LibWeb/IndexedDB/IDBCursor.h new file mode 100644 index 00000000000..004880aca34 --- /dev/null +++ b/Libraries/LibWeb/IndexedDB/IDBCursor.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, stelar7 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::IndexedDB { + +// https://w3c.github.io/IndexedDB/#cursor-interface +class IDBCursor : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(IDBCursor, Bindings::PlatformObject); + GC_DECLARE_ALLOCATOR(IDBCursor); + +public: + virtual ~IDBCursor() override; + [[nodiscard]] static GC::Ref create(JS::Realm&); + +protected: + explicit IDBCursor(JS::Realm&); + virtual void initialize(JS::Realm&) override; +}; +} diff --git a/Libraries/LibWeb/IndexedDB/IDBCursor.idl b/Libraries/LibWeb/IndexedDB/IDBCursor.idl new file mode 100644 index 00000000000..d97bc8d87a3 --- /dev/null +++ b/Libraries/LibWeb/IndexedDB/IDBCursor.idl @@ -0,0 +1,22 @@ +#import + +[Exposed=(Window,Worker)] +interface IDBCursor { + [FIXME] readonly attribute (IDBObjectStore or IDBIndex) source; + [FIXME] readonly attribute IDBCursorDirection direction; + [FIXME] readonly attribute any key; + [FIXME] readonly attribute any primaryKey; + [FIXME, SameObject] readonly attribute IDBRequest request; + [FIXME] undefined advance([EnforceRange] unsigned long count); + [FIXME] undefined continue(optional any key); + [FIXME] undefined continuePrimaryKey(any key, any primaryKey); + [FIXME, NewObject] IDBRequest update(any value); + [FIXME, NewObject] IDBRequest delete(); +}; + +enum IDBCursorDirection { + "next", + "nextunique", + "prev", + "prevunique" +}; diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake index 52599970883..84e511ba437 100644 --- a/Libraries/LibWeb/idl_files.cmake +++ b/Libraries/LibWeb/idl_files.cmake @@ -245,6 +245,7 @@ libweb_js_bindings(HTML/WorkerGlobalScope) libweb_js_bindings(HTML/WorkerLocation) libweb_js_bindings(HTML/WorkerNavigator) libweb_js_bindings(HighResolutionTime/Performance) +libweb_js_bindings(IndexedDB/IDBCursor) libweb_js_bindings(IndexedDB/IDBDatabase) libweb_js_bindings(IndexedDB/IDBFactory) libweb_js_bindings(IndexedDB/IDBOpenDBRequest) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 962c60b8e8c..1da14fe972e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -59,6 +59,7 @@ static bool is_platform_object(Type const& type) "FontFace"sv, "FormData"sv, "HTMLCollection"sv, + "IDBCursor"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 489142cd435..a647b5a83e2 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -199,6 +199,7 @@ HTMLVideoElement HashChangeEvent Headers History +IDBCursor IDBDatabase IDBFactory IDBOpenDBRequest