LibWeb: Implement IDBDatabase::close()

This commit is contained in:
stelar7 2024-11-07 20:33:25 +01:00 committed by Jelle Raaijmakers
commit bb31b682a5
Notes: github-actions[bot] 2024-11-26 13:52:06 +00:00
4 changed files with 27 additions and 1 deletions

View file

@ -13,6 +13,7 @@
#include <LibJS/Runtime/VM.h>
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/IndexedDB/IDBDatabase.h>
#include <LibWeb/IndexedDB/IDBRequest.h>
#include <LibWeb/IndexedDB/IDBVersionChangeEvent.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");
}
// https://w3c.github.io/IndexedDB/#close-a-database-connection
void close_a_database_connection(IDBDatabase& connection, bool forced)
{
// 1. Set connections 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));
}
}