mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibWeb/IDB: Add internal ObjectStore type
This commit is contained in:
parent
0979a154fd
commit
3c5578cc87
Notes:
github-actions[bot]
2025-03-27 15:49:50 +00:00
Author: https://github.com/stelar7
Commit: 3c5578cc87
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4077
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/gmta ✅
6 changed files with 86 additions and 2 deletions
|
@ -560,6 +560,7 @@ set(SOURCES
|
||||||
IndexedDB/Internal/Algorithms.cpp
|
IndexedDB/Internal/Algorithms.cpp
|
||||||
IndexedDB/Internal/Database.cpp
|
IndexedDB/Internal/Database.cpp
|
||||||
IndexedDB/Internal/Key.cpp
|
IndexedDB/Internal/Key.cpp
|
||||||
|
IndexedDB/Internal/ObjectStore.cpp
|
||||||
IndexedDB/Internal/RequestList.cpp
|
IndexedDB/Internal/RequestList.cpp
|
||||||
Internals/InternalAnimationTimeline.cpp
|
Internals/InternalAnimationTimeline.cpp
|
||||||
Internals/Internals.cpp
|
Internals/Internals.cpp
|
||||||
|
|
|
@ -620,6 +620,7 @@ class IDBOpenDBRequest;
|
||||||
class IDBRequest;
|
class IDBRequest;
|
||||||
class IDBTransaction;
|
class IDBTransaction;
|
||||||
class IDBVersionChangeEvent;
|
class IDBVersionChangeEvent;
|
||||||
|
class ObjectStore;
|
||||||
class RequestList;
|
class RequestList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ void Database::visit_edges(Visitor& visitor)
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
visitor.visit(m_associated_connections);
|
visitor.visit(m_associated_connections);
|
||||||
visitor.visit(m_upgrade_transaction);
|
visitor.visit(m_upgrade_transaction);
|
||||||
|
visitor.visit(m_object_stores);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<GC::Root<Database>> Database::for_key(StorageAPI::StorageKey const& key)
|
Vector<GC::Root<Database>> Database::for_key(StorageAPI::StorageKey const& key)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <LibWeb/DOM/EventTarget.h>
|
#include <LibWeb/DOM/EventTarget.h>
|
||||||
#include <LibWeb/IndexedDB/IDBDatabase.h>
|
#include <LibWeb/IndexedDB/IDBDatabase.h>
|
||||||
#include <LibWeb/IndexedDB/IDBRequest.h>
|
#include <LibWeb/IndexedDB/IDBRequest.h>
|
||||||
|
#include <LibWeb/IndexedDB/Internal/ObjectStore.h>
|
||||||
#include <LibWeb/StorageAPI/StorageKey.h>
|
#include <LibWeb/StorageAPI/StorageKey.h>
|
||||||
|
|
||||||
namespace Web::IndexedDB {
|
namespace Web::IndexedDB {
|
||||||
|
@ -61,8 +62,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
Vector<GC::Ref<IDBDatabase>> m_associated_connections;
|
Vector<GC::Ref<IDBDatabase>> m_associated_connections;
|
||||||
|
|
||||||
// FIXME: A database has zero or more object stores which hold the data stored in the database.
|
|
||||||
|
|
||||||
// A database has a name which identifies it within a specific storage key.
|
// A database has a name which identifies it within a specific storage key.
|
||||||
String m_name;
|
String m_name;
|
||||||
|
|
||||||
|
@ -71,6 +70,9 @@ private:
|
||||||
|
|
||||||
// A database has at most one associated upgrade transaction, which is either null or an upgrade transaction, and is initially null.
|
// A database has at most one associated upgrade transaction, which is either null or an upgrade transaction, and is initially null.
|
||||||
GC::Ptr<IDBTransaction> m_upgrade_transaction;
|
GC::Ptr<IDBTransaction> m_upgrade_transaction;
|
||||||
|
|
||||||
|
// A database has zero or more object stores which hold the data stored in the database.
|
||||||
|
Vector<GC::Ref<ObjectStore>> m_object_stores;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
20
Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp
Normal file
20
Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, stelar7 <dudedbz@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/IndexedDB/Internal/ObjectStore.h>
|
||||||
|
|
||||||
|
namespace Web::IndexedDB {
|
||||||
|
|
||||||
|
GC_DEFINE_ALLOCATOR(ObjectStore);
|
||||||
|
|
||||||
|
ObjectStore::~ObjectStore() = default;
|
||||||
|
|
||||||
|
GC::Ref<ObjectStore> ObjectStore::create(JS::Realm& realm, String name, bool auto_increment, Optional<KeyPath> const& key_path)
|
||||||
|
{
|
||||||
|
return realm.create<ObjectStore>(name, auto_increment, key_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
Libraries/LibWeb/IndexedDB/Internal/ObjectStore.h
Normal file
59
Libraries/LibWeb/IndexedDB/Internal/ObjectStore.h
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, stelar7 <dudedbz@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Optional.h>
|
||||||
|
#include <AK/String.h>
|
||||||
|
#include <AK/Variant.h>
|
||||||
|
#include <AK/Vector.h>
|
||||||
|
#include <LibGC/Ptr.h>
|
||||||
|
#include <LibJS/Heap/Cell.h>
|
||||||
|
#include <LibJS/Runtime/Realm.h>
|
||||||
|
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
|
||||||
|
#include <LibWeb/IndexedDB/Internal/KeyGenerator.h>
|
||||||
|
|
||||||
|
namespace Web::IndexedDB {
|
||||||
|
|
||||||
|
using KeyPath = Variant<String, Vector<String>>;
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#object-store-construct
|
||||||
|
class ObjectStore : public JS::Cell {
|
||||||
|
GC_CELL(ObjectStore, JS::Cell);
|
||||||
|
GC_DECLARE_ALLOCATOR(ObjectStore);
|
||||||
|
|
||||||
|
public:
|
||||||
|
[[nodiscard]] static GC::Ref<ObjectStore> create(JS::Realm&, String, bool, Optional<KeyPath> const&);
|
||||||
|
virtual ~ObjectStore();
|
||||||
|
|
||||||
|
String name() const { return m_name; }
|
||||||
|
Optional<KeyPath> key_path() const { return m_key_path; }
|
||||||
|
bool uses_inline_keys() const { return m_key_path.has_value(); }
|
||||||
|
bool uses_out_of_line_keys() const { return !m_key_path.has_value(); }
|
||||||
|
|
||||||
|
// The autoIncrement getter steps are to return true if this’s object store has a key generator, and false otherwise.
|
||||||
|
bool auto_increment() const { return m_key_generator.has_value(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ObjectStore(String name, bool auto_increment, Optional<KeyPath> const& key_path)
|
||||||
|
: m_name(move(name))
|
||||||
|
, m_key_path(key_path)
|
||||||
|
{
|
||||||
|
if (auto_increment)
|
||||||
|
m_key_generator = KeyGenerator {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// An object store has a name, which is a name. At any one time, the name is unique within the database to which it belongs.
|
||||||
|
String m_name;
|
||||||
|
|
||||||
|
// An object store optionally has a key path. If the object store has a key path it is said to use in-line keys. Otherwise it is said to use out-of-line keys.
|
||||||
|
Optional<KeyPath> m_key_path;
|
||||||
|
|
||||||
|
// An object store optionally has a key generator.
|
||||||
|
Optional<KeyGenerator> m_key_generator;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue