mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibWeb/IDB: Implement fire_a_success_event
This commit is contained in:
parent
5c814e1a62
commit
abb11a26a8
Notes:
github-actions[bot]
2025-04-23 18:37:55 +00:00
Author: https://github.com/stelar7
Commit: abb11a26a8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4317
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/kennethmyhra ✅
2 changed files with 39 additions and 0 deletions
|
@ -1070,4 +1070,42 @@ void fire_an_error_event(JS::Realm& realm, GC::Ref<IDBRequest> request)
|
|||
}
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#fire-a-success-event
|
||||
void fire_a_success_event(JS::Realm& realm, GC::Ref<IDBRequest> request)
|
||||
{
|
||||
// 1. Let event be the result of creating an event using Event.
|
||||
// 2. Set event’s type attribute to "success".
|
||||
// 3. Set event’s bubbles and cancelable attributes to false.
|
||||
auto event = DOM::Event::create(realm, HTML::EventNames::success, { .bubbles = false, .cancelable = false });
|
||||
|
||||
// 4. Let transaction be request’s transaction.
|
||||
auto transaction = request->transaction();
|
||||
|
||||
// 5. Let legacyOutputDidListenersThrowFlag be initially false.
|
||||
bool legacy_output_did_listeners_throw_flag = false;
|
||||
|
||||
// 6. If transaction’s state is inactive, then set transaction’s state to active.
|
||||
if (transaction->state() == IDBTransaction::TransactionState::Inactive)
|
||||
transaction->set_state(IDBTransaction::TransactionState::Active);
|
||||
|
||||
// 7. Dispatch event at request with legacyOutputDidListenersThrowFlag.
|
||||
DOM::EventDispatcher::dispatch(request, *event, false, legacy_output_did_listeners_throw_flag);
|
||||
|
||||
// 8. If transaction’s state is active, then:
|
||||
if (transaction->state() == IDBTransaction::TransactionState::Active) {
|
||||
// 1. Set transaction’s state to inactive.
|
||||
transaction->set_state(IDBTransaction::TransactionState::Inactive);
|
||||
|
||||
// 2. If legacyOutputDidListenersThrowFlag is true, then run abort a transaction with transaction and a newly created "AbortError" DOMException.
|
||||
if (legacy_output_did_listeners_throw_flag) {
|
||||
abort_a_transaction(*transaction, WebIDL::AbortError::create(realm, "An error occurred"_string));
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. If transaction’s request list is empty, then run commit a transaction with transaction.
|
||||
if (transaction->request_list().is_empty())
|
||||
commit_a_transaction(realm, *transaction);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,5 +34,6 @@ WebIDL::ExceptionOr<ErrorOr<JS::Value>> evaluate_key_path_on_a_value(JS::Realm&,
|
|||
WebIDL::ExceptionOr<ErrorOr<GC::Ref<Key>>> extract_a_key_from_a_value_using_a_key_path(JS::Realm&, JS::Value, KeyPath const&, bool = false);
|
||||
bool check_that_a_key_could_be_injected_into_a_value(JS::Realm&, JS::Value, KeyPath const&);
|
||||
void fire_an_error_event(JS::Realm&, GC::Ref<IDBRequest>);
|
||||
void fire_a_success_event(JS::Realm&, GC::Ref<IDBRequest>);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue