mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the namespace change, we now have the following names: * JS::NonnullGCPtr -> GC::Ref * JS::GCPtr -> GC::Ptr * JS::HeapFunction -> GC::Function * JS::CellImpl -> GC::Cell * JS::Handle -> GC::Root
This commit is contained in:
parent
ce23efc5f6
commit
f87041bf3a
Notes:
github-actions[bot]
2024-11-15 13:50:17 +00:00
Author: https://github.com/shannonbooth
Commit: f87041bf3a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2345
1722 changed files with 9939 additions and 9906 deletions
|
@ -17,7 +17,7 @@
|
|||
namespace Web::IndexedDB {
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#open-a-database-connection
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<IDBDatabase>> open_a_database_connection(JS::Realm& realm, StorageAPI::StorageKey storage_key, String name, Optional<u64> maybe_version, JS::NonnullGCPtr<IDBRequest> request)
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm& realm, StorageAPI::StorageKey storage_key, String name, Optional<u64> maybe_version, GC::Ref<IDBRequest> request)
|
||||
{
|
||||
// 1. Let queue be the connection queue for storageKey and name.
|
||||
auto& queue = ConnectionQueueHandler::for_key_and_name(storage_key, name);
|
||||
|
@ -26,13 +26,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<IDBDatabase>> open_a_database_connection(JS
|
|||
queue.append(request);
|
||||
|
||||
// 3. Wait until all previous requests in queue have been processed.
|
||||
HTML::main_thread_event_loop().spin_until(JS::create_heap_function(realm.vm().heap(), [queue, request]() {
|
||||
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [queue, request]() {
|
||||
return queue.all_previous_requests_processed(request);
|
||||
}));
|
||||
|
||||
// 4. Let db be the database named name in storageKey, or null otherwise.
|
||||
auto maybe_db = Database::for_key_and_name(storage_key, name);
|
||||
JS::GCPtr<Database> db;
|
||||
GC::Ptr<Database> db;
|
||||
|
||||
// 5. If version is undefined, let version be 1 if db is null, or db’s version otherwise.
|
||||
auto version = maybe_version.value_or(maybe_db.has_value() ? maybe_db.value()->version() : 1);
|
||||
|
@ -69,7 +69,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<IDBDatabase>> open_a_database_connection(JS
|
|||
// queue a task to fire a version change event named versionchange at entry with db’s version and version.
|
||||
for (auto& entry : open_connections) {
|
||||
if (!entry->close_pending()) {
|
||||
HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, JS::create_heap_function(realm.vm().heap(), [&realm, entry, db, version]() {
|
||||
HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, GC::create_function(realm.vm().heap(), [&realm, entry, db, version]() {
|
||||
fire_a_version_change_event(realm, HTML::EventNames::versionchange, *entry, db->version(), version);
|
||||
}));
|
||||
}
|
||||
|
@ -81,14 +81,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<IDBDatabase>> open_a_database_connection(JS
|
|||
// queue a task to fire a version change event named blocked at request with db’s version and version.
|
||||
for (auto& entry : open_connections) {
|
||||
if (entry->state() != IDBDatabase::ConnectionState::Closed) {
|
||||
HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, JS::create_heap_function(realm.vm().heap(), [&realm, entry, db, version]() {
|
||||
HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, GC::create_function(realm.vm().heap(), [&realm, entry, db, version]() {
|
||||
fire_a_version_change_event(realm, HTML::EventNames::blocked, *entry, db->version(), version);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Wait until all connections in openConnections are closed.
|
||||
HTML::main_thread_event_loop().spin_until(JS::create_heap_function(realm.vm().heap(), [open_connections]() {
|
||||
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [open_connections]() {
|
||||
for (auto const& entry : open_connections) {
|
||||
if (entry->state() != IDBDatabase::ConnectionState::Closed) {
|
||||
return false;
|
||||
|
@ -115,7 +115,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<IDBDatabase>> open_a_database_connection(JS
|
|||
return connection;
|
||||
}
|
||||
|
||||
bool fire_a_version_change_event(JS::Realm& realm, FlyString const& event_name, JS::NonnullGCPtr<DOM::EventTarget> target, u64 old_version, Optional<u64> new_version)
|
||||
bool fire_a_version_change_event(JS::Realm& realm, FlyString const& event_name, GC::Ref<DOM::EventTarget> target, u64 old_version, Optional<u64> new_version)
|
||||
{
|
||||
IDBVersionChangeEventInit event_init = {};
|
||||
// 4. Set event’s oldVersion attribute to oldVersion.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<IDBDatabase>> open_a_database_connection(JS::Realm&, StorageAPI::StorageKey, String, Optional<u64>, JS::NonnullGCPtr<IDBRequest>);
|
||||
bool fire_a_version_change_event(JS::Realm&, FlyString const&, JS::NonnullGCPtr<DOM::EventTarget>, u64, Optional<u64>);
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&, StorageAPI::StorageKey, String, Optional<u64>, GC::Ref<IDBRequest>);
|
||||
bool fire_a_version_change_event(JS::Realm&, FlyString const&, GC::Ref<DOM::EventTarget>, u64, Optional<u64>);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,16 +7,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibGC/Root.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/IndexedDB/IDBRequest.h>
|
||||
#include <LibWeb/StorageAPI/StorageKey.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
class ConnectionQueue : public AK::Vector<JS::Handle<IDBRequest>> {
|
||||
class ConnectionQueue : public AK::Vector<GC::Root<IDBRequest>> {
|
||||
public:
|
||||
bool all_previous_requests_processed(JS::NonnullGCPtr<IDBRequest> const& request) const
|
||||
bool all_previous_requests_processed(GC::Ref<IDBRequest> const& request) const
|
||||
{
|
||||
for (auto const& entry : *this) {
|
||||
if (entry == request)
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
using IDBDatabaseMapping = HashMap<StorageAPI::StorageKey, HashMap<String, JS::Handle<Database>>>;
|
||||
using IDBDatabaseMapping = HashMap<StorageAPI::StorageKey, HashMap<String, GC::Root<Database>>>;
|
||||
static IDBDatabaseMapping m_databases;
|
||||
|
||||
JS_DEFINE_ALLOCATOR(Database);
|
||||
GC_DEFINE_ALLOCATOR(Database);
|
||||
|
||||
Database::~Database() = default;
|
||||
|
||||
JS::NonnullGCPtr<Database> Database::create(JS::Realm& realm, String const& name)
|
||||
GC::Ref<Database> Database::create(JS::Realm& realm, String const& name)
|
||||
{
|
||||
return realm.create<Database>(realm, name);
|
||||
}
|
||||
|
@ -37,18 +37,18 @@ ConnectionQueue& ConnectionQueueHandler::for_key_and_name(StorageAPI::StorageKey
|
|||
});
|
||||
}
|
||||
|
||||
Optional<JS::Handle<Database>> Database::for_key_and_name(StorageAPI::StorageKey& key, String& name)
|
||||
Optional<GC::Root<Database>> Database::for_key_and_name(StorageAPI::StorageKey& key, String& name)
|
||||
{
|
||||
return m_databases.ensure(key, [] {
|
||||
return HashMap<String, JS::Handle<Database>>();
|
||||
return HashMap<String, GC::Root<Database>>();
|
||||
})
|
||||
.get(name);
|
||||
}
|
||||
|
||||
ErrorOr<JS::Handle<Database>> Database::create_for_key_and_name(JS::Realm& realm, StorageAPI::StorageKey& key, String& name)
|
||||
ErrorOr<GC::Root<Database>> Database::create_for_key_and_name(JS::Realm& realm, StorageAPI::StorageKey& key, String& name)
|
||||
{
|
||||
auto database_mapping = TRY(m_databases.try_ensure(key, [] {
|
||||
return HashMap<String, JS::Handle<Database>>();
|
||||
return HashMap<String, GC::Root<Database>>();
|
||||
}));
|
||||
|
||||
return database_mapping.try_ensure(name, [&] {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/IndexedDB/IDBDatabase.h>
|
||||
#include <LibWeb/IndexedDB/IDBRequest.h>
|
||||
|
@ -18,18 +18,18 @@ namespace Web::IndexedDB {
|
|||
// https://www.w3.org/TR/IndexedDB/#database-construct
|
||||
class Database : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(Database, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(Database);
|
||||
GC_DECLARE_ALLOCATOR(Database);
|
||||
|
||||
public:
|
||||
void set_version(u64 version) { m_version = version; }
|
||||
u64 version() const { return m_version; }
|
||||
String name() const { return m_name; }
|
||||
|
||||
void associate(JS::NonnullGCPtr<IDBDatabase> connection) { m_associated_connections.append(connection); }
|
||||
ReadonlySpan<JS::NonnullGCPtr<IDBDatabase>> associated_connections() { return m_associated_connections; }
|
||||
Vector<JS::Handle<IDBDatabase>> associated_connections_except(IDBDatabase& connection)
|
||||
void associate(GC::Ref<IDBDatabase> connection) { m_associated_connections.append(connection); }
|
||||
ReadonlySpan<GC::Ref<IDBDatabase>> associated_connections() { return m_associated_connections; }
|
||||
Vector<GC::Root<IDBDatabase>> associated_connections_except(IDBDatabase& connection)
|
||||
{
|
||||
Vector<JS::Handle<IDBDatabase>> connections;
|
||||
Vector<GC::Root<IDBDatabase>> connections;
|
||||
for (auto& associated_connection : m_associated_connections) {
|
||||
if (associated_connection != &connection)
|
||||
connections.append(associated_connection);
|
||||
|
@ -37,11 +37,11 @@ public:
|
|||
return connections;
|
||||
}
|
||||
|
||||
[[nodiscard]] static Optional<JS::Handle<Database>> for_key_and_name(StorageAPI::StorageKey&, String&);
|
||||
[[nodiscard]] static ErrorOr<JS::Handle<Database>> create_for_key_and_name(JS::Realm&, StorageAPI::StorageKey&, String&);
|
||||
[[nodiscard]] static Optional<GC::Root<Database>> for_key_and_name(StorageAPI::StorageKey&, String&);
|
||||
[[nodiscard]] static ErrorOr<GC::Root<Database>> create_for_key_and_name(JS::Realm&, StorageAPI::StorageKey&, String&);
|
||||
[[nodiscard]] static ErrorOr<void> delete_for_key_and_name(StorageAPI::StorageKey&, String&);
|
||||
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Database> create(JS::Realm&, String const&);
|
||||
[[nodiscard]] static GC::Ref<Database> create(JS::Realm&, String const&);
|
||||
virtual ~Database();
|
||||
|
||||
protected:
|
||||
|
@ -56,7 +56,7 @@ protected:
|
|||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
private:
|
||||
Vector<JS::NonnullGCPtr<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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue