1
0
Fork 0
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:
stelar7 2025-04-11 11:10:05 +02:00 committed by Andrew Kaster
parent 5c814e1a62
commit abb11a26a8
Notes: github-actions[bot] 2025-04-23 18:37:55 +00:00
2 changed files with 39 additions and 0 deletions

View file

@ -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 events type attribute to "success".
// 3. Set events bubbles and cancelable attributes to false.
auto event = DOM::Event::create(realm, HTML::EventNames::success, { .bubbles = false, .cancelable = false });
// 4. Let transaction be requests transaction.
auto transaction = request->transaction();
// 5. Let legacyOutputDidListenersThrowFlag be initially false.
bool legacy_output_did_listeners_throw_flag = false;
// 6. If transactions state is inactive, then set transactions 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 transactions state is active, then:
if (transaction->state() == IDBTransaction::TransactionState::Active) {
// 1. Set transactions 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 transactions request list is empty, then run commit a transaction with transaction.
if (transaction->request_list().is_empty())
commit_a_transaction(realm, *transaction);
}
}
}

View file

@ -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>);
}