Pārlūkot izejas kodu

LibWeb: Add IDBKeyRange

stelar7 8 mēneši atpakaļ
vecāks
revīzija
48fae7b64f

+ 1 - 0
Libraries/LibWeb/CMakeLists.txt

@@ -516,6 +516,7 @@ set(SOURCES
     IndexedDB/IDBFactory.cpp
     IndexedDB/IDBOpenDBRequest.cpp
     IndexedDB/IDBIndex.cpp
+    IndexedDB/IDBKeyRange.cpp
     IndexedDB/IDBObjectStore.cpp
     IndexedDB/IDBRequest.cpp
     IndexedDB/IDBTransaction.cpp

+ 1 - 0
Libraries/LibWeb/Forward.h

@@ -578,6 +578,7 @@ class IDBCursor;
 class IDBDatabase;
 class IDBFactory;
 class IDBIndex;
+class IDBKeyRange;
 class IDBObjectStore;
 class IDBOpenDBRequest;
 class IDBRequest;

+ 33 - 0
Libraries/LibWeb/IndexedDB/IDBKeyRange.cpp

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

+ 28 - 0
Libraries/LibWeb/IndexedDB/IDBKeyRange.h

@@ -0,0 +1,28 @@
+/*
+ * 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/#keyrange
+class IDBKeyRange : public Bindings::PlatformObject {
+    WEB_PLATFORM_OBJECT(IDBKeyRange, Bindings::PlatformObject);
+    GC_DECLARE_ALLOCATOR(IDBKeyRange);
+
+public:
+    virtual ~IDBKeyRange() override;
+    [[nodiscard]] static GC::Ref<IDBKeyRange> create(JS::Realm&);
+
+protected:
+    explicit IDBKeyRange(JS::Realm&);
+    virtual void initialize(JS::Realm&) override;
+};
+
+}

+ 14 - 0
Libraries/LibWeb/IndexedDB/IDBKeyRange.idl

@@ -0,0 +1,14 @@
+[Exposed=(Window,Worker)]
+interface IDBKeyRange {
+    [FIXME] readonly attribute any lower;
+    [FIXME] readonly attribute any upper;
+    [FIXME] readonly attribute boolean lowerOpen;
+    [FIXME] readonly attribute boolean upperOpen;
+
+    [FIXME, NewObject] static IDBKeyRange only(any value);
+    [FIXME, NewObject] static IDBKeyRange lowerBound(any lower, optional boolean open = false);
+    [FIXME, NewObject] static IDBKeyRange upperBound(any upper, optional boolean open = false);
+    [FIXME, NewObject] static IDBKeyRange bound(any lower, any upper, optional boolean lowerOpen = false, optional boolean upperOpen = false);
+
+    [FIXME] boolean includes(any key);
+};

+ 1 - 0
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/IDBKeyRange)
 libweb_js_bindings(IndexedDB/IDBObjectStore)
 libweb_js_bindings(IndexedDB/IDBOpenDBRequest)
 libweb_js_bindings(IndexedDB/IDBRequest)

+ 1 - 0
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,
+        "IDBKeyRange"sv,
         "IDBObjectStore"sv,
         "IDBTransaction"sv,
         "ImageBitmap"sv,

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

@@ -203,6 +203,7 @@ IDBCursor
 IDBDatabase
 IDBFactory
 IDBIndex
+IDBKeyRange
 IDBObjectStore
 IDBOpenDBRequest
 IDBRequest