mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-26 04:07:51 +00:00
LibWeb/IDB: Implement IDBTransaction attributes
This also uncovered a bug, where the transactions type was never set :^)
This commit is contained in:
parent
718c805e95
commit
5298ecfc94
Notes:
github-actions[bot]
2025-04-09 17:50:19 +00:00
Author: https://github.com/stelar7
Commit: 5298ecfc94
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4178
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/AtkinsSJ
7 changed files with 63 additions and 15 deletions
|
@ -1,17 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
|
||||
* Copyright (c) 2024-2025, stelar7 <dudedbz@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibWeb/Bindings/IDBDatabasePrototype.h>
|
||||
#include <LibWeb/Bindings/IDBTransactionPrototype.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||
#include <LibWeb/IndexedDB/IDBDatabase.h>
|
||||
#include <LibWeb/IndexedDB/IDBRequest.h>
|
||||
#include <LibWeb/IndexedDB/Internal/ObjectStore.h>
|
||||
#include <LibWeb/IndexedDB/Internal/RequestList.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
|
@ -30,7 +35,7 @@ class IDBTransaction : public DOM::EventTarget {
|
|||
public:
|
||||
virtual ~IDBTransaction() override;
|
||||
|
||||
[[nodiscard]] static GC::Ref<IDBTransaction> create(JS::Realm&, GC::Ref<IDBDatabase>);
|
||||
[[nodiscard]] static GC::Ref<IDBTransaction> create(JS::Realm&, GC::Ref<IDBDatabase>, Bindings::IDBTransactionMode, Bindings::IDBTransactionDurability, Vector<GC::Ref<ObjectStore>>);
|
||||
[[nodiscard]] Bindings::IDBTransactionMode mode() const { return m_mode; }
|
||||
[[nodiscard]] TransactionState state() const { return m_state; }
|
||||
[[nodiscard]] GC::Ptr<WebIDL::DOMException> error() const { return m_error; }
|
||||
|
@ -38,6 +43,8 @@ public:
|
|||
[[nodiscard]] Bindings::IDBTransactionDurability durability() const { return m_durability; }
|
||||
[[nodiscard]] GC::Ptr<IDBRequest> associated_request() const { return m_associated_request; }
|
||||
[[nodiscard]] bool aborted() const { return m_aborted; }
|
||||
[[nodiscard]] GC::Ref<HTML::DOMStringList> object_store_names();
|
||||
[[nodiscard]] ReadonlySpan<GC::Ref<ObjectStore>> scope() const { return m_scope; }
|
||||
|
||||
void set_mode(Bindings::IDBTransactionMode mode) { m_mode = mode; }
|
||||
void set_state(TransactionState state) { m_state = state; }
|
||||
|
@ -59,18 +66,39 @@ public:
|
|||
WebIDL::CallbackType* onerror();
|
||||
|
||||
protected:
|
||||
explicit IDBTransaction(JS::Realm&, GC::Ref<IDBDatabase>);
|
||||
explicit IDBTransaction(JS::Realm&, GC::Ref<IDBDatabase>, Bindings::IDBTransactionMode, Bindings::IDBTransactionDurability, Vector<GC::Ref<ObjectStore>>);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Visitor& visitor) override;
|
||||
|
||||
private:
|
||||
// AD-HOC: The transaction has a connection
|
||||
GC::Ref<IDBDatabase> m_connection;
|
||||
|
||||
// A transaction has a mode that determines which types of interactions can be performed upon that transaction.
|
||||
Bindings::IDBTransactionMode m_mode;
|
||||
|
||||
// A transaction has a durability hint. This is a hint to the user agent of whether to prioritize performance or durability when committing the transaction.
|
||||
Bindings::IDBTransactionDurability m_durability { Bindings::IDBTransactionDurability::Default };
|
||||
|
||||
// A transaction has a state
|
||||
TransactionState m_state;
|
||||
|
||||
// A transaction has a error which is set if the transaction is aborted.
|
||||
GC::Ptr<WebIDL::DOMException> m_error;
|
||||
|
||||
// A transaction has an associated upgrade request
|
||||
GC::Ptr<IDBRequest> m_associated_request;
|
||||
|
||||
// AD-HOC: We need to track abort state separately, since we cannot rely on only the error.
|
||||
bool m_aborted { false };
|
||||
|
||||
// A transaction has a scope which is a set of object stores that the transaction may interact with.
|
||||
Vector<GC::Ref<ObjectStore>> m_scope;
|
||||
|
||||
// A transaction has a request list of pending requests which have been made against the transaction.
|
||||
RequestList m_request_list;
|
||||
|
||||
// A transaction optionally has a cleanup event loop which is an event loop.
|
||||
GC::Ptr<HTML::EventLoop> m_cleanup_event_loop;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue