mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb: Implement IDBDatabase::close()
This commit is contained in:
parent
49ad27816b
commit
bb31b682a5
Notes:
github-actions[bot]
2024-11-26 13:52:06 +00:00
Author: https://github.com/stelar7
Commit: bb31b682a5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2236
Reviewed-by: https://github.com/gmta ✅
4 changed files with 27 additions and 1 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <LibWeb/DOM/EventTarget.h>
|
#include <LibWeb/DOM/EventTarget.h>
|
||||||
#include <LibWeb/HTML/DOMStringList.h>
|
#include <LibWeb/HTML/DOMStringList.h>
|
||||||
#include <LibWeb/IndexedDB/IDBRequest.h>
|
#include <LibWeb/IndexedDB/IDBRequest.h>
|
||||||
|
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
|
||||||
#include <LibWeb/IndexedDB/Internal/Database.h>
|
#include <LibWeb/IndexedDB/Internal/Database.h>
|
||||||
#include <LibWeb/StorageAPI/StorageKey.h>
|
#include <LibWeb/StorageAPI/StorageKey.h>
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ public:
|
||||||
|
|
||||||
void set_version(u64 version) { m_version = version; }
|
void set_version(u64 version) { m_version = version; }
|
||||||
void set_close_pending(bool close_pending) { m_close_pending = close_pending; }
|
void set_close_pending(bool close_pending) { m_close_pending = close_pending; }
|
||||||
|
void set_state(ConnectionState state) { m_state = state; }
|
||||||
|
|
||||||
[[nodiscard]] GC::Ref<HTML::DOMStringList> object_store_names() { return m_object_store_names; }
|
[[nodiscard]] GC::Ref<HTML::DOMStringList> object_store_names() { return m_object_store_names; }
|
||||||
[[nodiscard]] String name() const { return m_name; }
|
[[nodiscard]] String name() const { return m_name; }
|
||||||
|
@ -43,6 +45,13 @@ public:
|
||||||
[[nodiscard]] ConnectionState state() const { return m_state; }
|
[[nodiscard]] ConnectionState state() const { return m_state; }
|
||||||
[[nodiscard]] GC::Ref<Database> associated_database() { return m_associated_database; }
|
[[nodiscard]] GC::Ref<Database> associated_database() { return m_associated_database; }
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#dom-idbdatabase-close
|
||||||
|
void close()
|
||||||
|
{
|
||||||
|
// 1. Run close a database connection with this connection.
|
||||||
|
close_a_database_connection(*this);
|
||||||
|
}
|
||||||
|
|
||||||
void set_onabort(WebIDL::CallbackType*);
|
void set_onabort(WebIDL::CallbackType*);
|
||||||
WebIDL::CallbackType* onabort();
|
WebIDL::CallbackType* onabort();
|
||||||
void set_onclose(WebIDL::CallbackType*);
|
void set_onclose(WebIDL::CallbackType*);
|
||||||
|
|
|
@ -8,7 +8,7 @@ interface IDBDatabase : EventTarget {
|
||||||
readonly attribute DOMStringList objectStoreNames;
|
readonly attribute DOMStringList objectStoreNames;
|
||||||
|
|
||||||
[FIXME, NewObject] IDBTransaction transaction((DOMString or sequence<DOMString>) storeNames, optional IDBTransactionMode mode = "readonly", optional IDBTransactionOptions options = {});
|
[FIXME, NewObject] IDBTransaction transaction((DOMString or sequence<DOMString>) storeNames, optional IDBTransactionMode mode = "readonly", optional IDBTransactionOptions options = {});
|
||||||
[FIXME] undefined close();
|
undefined close();
|
||||||
[FIXME, NewObject] IDBObjectStore createObjectStore(DOMString name, optional IDBObjectStoreParameters options = {});
|
[FIXME, NewObject] IDBObjectStore createObjectStore(DOMString name, optional IDBObjectStoreParameters options = {});
|
||||||
[FIXME] undefined deleteObjectStore(DOMString name);
|
[FIXME] undefined deleteObjectStore(DOMString name);
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <LibJS/Runtime/VM.h>
|
#include <LibJS/Runtime/VM.h>
|
||||||
#include <LibWeb/DOM/EventDispatcher.h>
|
#include <LibWeb/DOM/EventDispatcher.h>
|
||||||
#include <LibWeb/HTML/EventNames.h>
|
#include <LibWeb/HTML/EventNames.h>
|
||||||
|
#include <LibWeb/IndexedDB/IDBDatabase.h>
|
||||||
#include <LibWeb/IndexedDB/IDBRequest.h>
|
#include <LibWeb/IndexedDB/IDBRequest.h>
|
||||||
#include <LibWeb/IndexedDB/IDBVersionChangeEvent.h>
|
#include <LibWeb/IndexedDB/IDBVersionChangeEvent.h>
|
||||||
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
|
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
|
||||||
|
@ -266,4 +267,19 @@ ErrorOr<Key> convert_a_value_to_a_key(JS::Realm& realm, JS::Value input, Vector<
|
||||||
return Error::from_string_literal("Unknown key type");
|
return Error::from_string_literal("Unknown key type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#close-a-database-connection
|
||||||
|
void close_a_database_connection(IDBDatabase& connection, bool forced)
|
||||||
|
{
|
||||||
|
// 1. Set connection’s close pending flag to true.
|
||||||
|
connection.set_close_pending(true);
|
||||||
|
|
||||||
|
// FIXME: 2. If the forced flag is true, then for each transaction created using connection run abort a transaction with transaction and newly created "AbortError" DOMException.
|
||||||
|
// FIXME: 3. Wait for all transactions created using connection to complete. Once they are complete, connection is closed.
|
||||||
|
connection.set_state(IDBDatabase::ConnectionState::Closed);
|
||||||
|
|
||||||
|
// 4. If the forced flag is true, then fire an event named close at connection.
|
||||||
|
if (forced)
|
||||||
|
connection.dispatch_event(DOM::Event::create(connection.realm(), HTML::EventNames::close));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,6 @@ namespace Web::IndexedDB {
|
||||||
WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&, StorageAPI::StorageKey, String, Optional<u64>, GC::Ref<IDBRequest>);
|
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>);
|
bool fire_a_version_change_event(JS::Realm&, FlyString const&, GC::Ref<DOM::EventTarget>, u64, Optional<u64>);
|
||||||
ErrorOr<Key> convert_a_value_to_a_key(JS::Realm&, JS::Value, Vector<JS::Value> = {});
|
ErrorOr<Key> convert_a_value_to_a_key(JS::Realm&, JS::Value, Vector<JS::Value> = {});
|
||||||
|
void close_a_database_connection(IDBDatabase&, bool forced = false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue