Browse Source

LibWeb: Add stub interface for IDBRequest

Shannon Booth 1 year ago
parent
commit
bfa330914d

+ 1 - 0
Userland/Libraries/LibWeb/CMakeLists.txt

@@ -448,6 +448,7 @@ set(SOURCES
     Infra/JSON.cpp
     Infra/Strings.cpp
     IndexedDB/IDBFactory.cpp
+    IndexedDB/IDBRequest.cpp
     Internals/Inspector.cpp
     Internals/InternalAnimationTimeline.cpp
     Internals/Internals.cpp

+ 1 - 0
Userland/Libraries/LibWeb/Forward.h

@@ -500,6 +500,7 @@ class Performance;
 
 namespace Web::IndexedDB {
 class IDBFactory;
+class IDBRequest;
 }
 
 namespace Web::Internals {

+ 28 - 0
Userland/Libraries/LibWeb/IndexedDB/IDBRequest.cpp

@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Bindings/IDBRequestPrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/IndexedDB/IDBRequest.h>
+
+namespace Web::IndexedDB {
+
+JS_DEFINE_ALLOCATOR(IDBRequest);
+
+IDBRequest::~IDBRequest() = default;
+
+IDBRequest::IDBRequest(JS::Realm& realm)
+    : EventTarget(realm)
+{
+}
+
+void IDBRequest::initialize(JS::Realm& realm)
+{
+    Base::initialize(realm);
+    WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBRequest);
+}
+
+}

+ 26 - 0
Userland/Libraries/LibWeb/IndexedDB/IDBRequest.h

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/DOM/EventTarget.h>
+
+namespace Web::IndexedDB {
+
+class IDBRequest : public DOM::EventTarget {
+    WEB_PLATFORM_OBJECT(IDBRequest, EventTarget);
+    JS_DECLARE_ALLOCATOR(IDBRequest);
+
+public:
+    virtual ~IDBRequest() override;
+
+protected:
+    explicit IDBRequest(JS::Realm&);
+
+    virtual void initialize(JS::Realm&) override;
+};
+
+}

+ 20 - 0
Userland/Libraries/LibWeb/IndexedDB/IDBRequest.idl

@@ -0,0 +1,20 @@
+#import <DOM/EventTarget.idl>
+
+// https://w3c.github.io/IndexedDB/#idbrequest
+[Exposed=(Window,Worker)]
+interface IDBRequest : EventTarget {
+    // FIXME: readonly attribute any result;
+    // FIXME: readonly attribute DOMException? error;
+    // FIXME: readonly attribute (IDBObjectStore or IDBIndex or IDBCursor)? source;
+    // FIXME: readonly attribute IDBTransaction? transaction;
+    // FIXME: readonly attribute IDBRequestReadyState readyState;
+
+    // Event handlers:
+    // FIXME: attribute EventHandler onsuccess;
+    // FIXME: attribute EventHandler onerror;
+};
+
+enum IDBRequestReadyState {
+    "pending",
+    "done"
+};

+ 1 - 0
Userland/Libraries/LibWeb/idl_files.cmake

@@ -217,6 +217,7 @@ libweb_js_bindings(HTML/WorkerLocation)
 libweb_js_bindings(HTML/WorkerNavigator)
 libweb_js_bindings(HighResolutionTime/Performance)
 libweb_js_bindings(IndexedDB/IDBFactory)
+libweb_js_bindings(IndexedDB/IDBRequest)
 libweb_js_bindings(Internals/Inspector)
 libweb_js_bindings(Internals/InternalAnimationTimeline)
 libweb_js_bindings(Internals/Internals)