Przeglądaj źródła

LibWeb: Add IDBCursor

stelar7 9 miesięcy temu
rodzic
commit
71772d97dc

+ 1 - 0
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

+ 1 - 0
Libraries/LibWeb/Forward.h

@@ -574,6 +574,7 @@ class Performance;
 
 namespace Web::IndexedDB {
 class Database;
+class IDBCursor;
 class IDBFactory;
 class IDBDatabase;
 class IDBOpenDBRequest;

+ 34 - 0
Libraries/LibWeb/IndexedDB/IDBCursor.cpp

@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Bindings/IDBCursorPrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/HTML/EventNames.h>
+#include <LibWeb/IndexedDB/IDBCursor.h>
+
+namespace Web::IndexedDB {
+
+GC_DEFINE_ALLOCATOR(IDBCursor);
+
+IDBCursor::~IDBCursor() = default;
+
+IDBCursor::IDBCursor(JS::Realm& realm)
+    : PlatformObject(realm)
+{
+}
+
+GC::Ref<IDBCursor> IDBCursor::create(JS::Realm& realm)
+{
+    return realm.create<IDBCursor>(realm);
+}
+
+void IDBCursor::initialize(JS::Realm& realm)
+{
+    Base::initialize(realm);
+    WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBCursor);
+}
+
+}

+ 27 - 0
Libraries/LibWeb/IndexedDB/IDBCursor.h

@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibGC/Heap.h>
+#include <LibWeb/Bindings/PlatformObject.h>
+
+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<IDBCursor> create(JS::Realm&);
+
+protected:
+    explicit IDBCursor(JS::Realm&);
+    virtual void initialize(JS::Realm&) override;
+};
+}

+ 22 - 0
Libraries/LibWeb/IndexedDB/IDBCursor.idl

@@ -0,0 +1,22 @@
+#import <IndexedDB/IDBRequest.idl>
+
+[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"
+};

+ 1 - 0
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)

+ 1 - 0
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,

+ 1 - 0
Tests/LibWeb/Text/expected/all-window-properties.txt

@@ -199,6 +199,7 @@ HTMLVideoElement
 HashChangeEvent
 Headers
 History
+IDBCursor
 IDBDatabase
 IDBFactory
 IDBOpenDBRequest