mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-30 13:19:02 +00:00
LibWeb/IDB: Check the request error instead of the transaction
This commit is contained in:
parent
a7bcb1b0c5
commit
474b748275
Notes:
github-actions[bot]
2025-08-14 08:33:32 +00:00
Author: https://github.com/stelar7
Commit: 474b748275
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5827
Reviewed-by: https://github.com/AtkinsSJ ✅
4 changed files with 15 additions and 14 deletions
|
@ -39,9 +39,11 @@ GC::Ref<IDBRequest> IDBRequest::create(JS::Realm& realm, IDBRequestSource source
|
||||||
void IDBRequest::visit_edges(Visitor& visitor)
|
void IDBRequest::visit_edges(Visitor& visitor)
|
||||||
{
|
{
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
visitor.visit(m_error);
|
|
||||||
visitor.visit(m_result);
|
visitor.visit(m_result);
|
||||||
visitor.visit(m_transaction);
|
visitor.visit(m_transaction);
|
||||||
|
|
||||||
|
if (m_error.has_value())
|
||||||
|
visitor.visit(*m_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/IndexedDB/#dom-idbrequest-onsuccess
|
// https://w3c.github.io/IndexedDB/#dom-idbrequest-onsuccess
|
||||||
|
@ -83,7 +85,7 @@ WebIDL::CallbackType* IDBRequest::onerror()
|
||||||
return WebIDL::InvalidStateError::create(realm(), "The request is not done"_utf16);
|
return WebIDL::InvalidStateError::create(realm(), "The request is not done"_utf16);
|
||||||
|
|
||||||
// 2. Otherwise, return this's error, or null if no error occurred.
|
// 2. Otherwise, return this's error, or null if no error occurred.
|
||||||
return m_error;
|
return m_error.value_or(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/IndexedDB/#dom-idbrequest-result
|
// https://w3c.github.io/IndexedDB/#dom-idbrequest-result
|
||||||
|
@ -94,7 +96,7 @@ WebIDL::CallbackType* IDBRequest::onerror()
|
||||||
return WebIDL::InvalidStateError::create(realm(), "The request is not done"_utf16);
|
return WebIDL::InvalidStateError::create(realm(), "The request is not done"_utf16);
|
||||||
|
|
||||||
// 2. Otherwise, return this's result, or undefined if the request resulted in an error.
|
// 2. Otherwise, return this's result, or undefined if the request resulted in an error.
|
||||||
if (m_error)
|
if (m_error.has_value())
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
|
|
||||||
return m_result;
|
return m_result;
|
||||||
|
|
|
@ -38,11 +38,13 @@ public:
|
||||||
|
|
||||||
void set_done(bool done) { m_done = done; }
|
void set_done(bool done) { m_done = done; }
|
||||||
void set_result(JS::Value result) { m_result = result; }
|
void set_result(JS::Value result) { m_result = result; }
|
||||||
void set_error(GC::Ptr<WebIDL::DOMException> error) { m_error = error; }
|
void set_error(Optional<GC::Ptr<WebIDL::DOMException>> error) { m_error = error; }
|
||||||
void set_processed(bool processed) { m_processed = processed; }
|
void set_processed(bool processed) { m_processed = processed; }
|
||||||
void set_source(IDBRequestSource source) { m_source = source; }
|
void set_source(IDBRequestSource source) { m_source = source; }
|
||||||
void set_transaction(GC::Ptr<IDBTransaction> transaction) { m_transaction = transaction; }
|
void set_transaction(GC::Ptr<IDBTransaction> transaction) { m_transaction = transaction; }
|
||||||
|
|
||||||
|
bool has_error() const { return m_error.has_value(); }
|
||||||
|
|
||||||
void set_onsuccess(WebIDL::CallbackType*);
|
void set_onsuccess(WebIDL::CallbackType*);
|
||||||
WebIDL::CallbackType* onsuccess();
|
WebIDL::CallbackType* onsuccess();
|
||||||
void set_onerror(WebIDL::CallbackType*);
|
void set_onerror(WebIDL::CallbackType*);
|
||||||
|
@ -63,7 +65,7 @@ private:
|
||||||
|
|
||||||
// A request has a result and an error
|
// A request has a result and an error
|
||||||
JS::Value m_result;
|
JS::Value m_result;
|
||||||
GC::Ptr<WebIDL::DOMException> m_error;
|
Optional<GC::Ptr<WebIDL::DOMException>> m_error;
|
||||||
|
|
||||||
// A request has a source object.
|
// A request has a source object.
|
||||||
IDBRequestSource m_source;
|
IDBRequestSource m_source;
|
||||||
|
|
|
@ -164,16 +164,15 @@ WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 6. Run upgrade a database using connection, version and request.
|
// 6. Run upgrade a database using connection, version and request.
|
||||||
// AD-HOC: https://github.com/w3c/IndexedDB/issues/433#issuecomment-2512330086
|
upgrade_a_database(realm, connection, version, request);
|
||||||
auto upgrade_transaction = upgrade_a_database(realm, connection, version, request);
|
|
||||||
|
|
||||||
// 7. If connection was closed, return a newly created "AbortError" DOMException and abort these steps.
|
// 7. If connection was closed, return a newly created "AbortError" DOMException and abort these steps.
|
||||||
if (connection->state() == IDBDatabase::ConnectionState::Closed)
|
if (connection->state() == IDBDatabase::ConnectionState::Closed)
|
||||||
return WebIDL::AbortError::create(realm, "Connection was closed"_utf16);
|
return WebIDL::AbortError::create(realm, "Connection was closed"_utf16);
|
||||||
|
|
||||||
// 8. If the upgrade transaction was aborted, run the steps to close a database connection with connection,
|
// 8. If request's error is set, run the steps to close a database connection with connection,
|
||||||
// return a newly created "AbortError" DOMException and abort these steps.
|
// return a newly created "AbortError" DOMException and abort these steps.
|
||||||
if (upgrade_transaction->aborted()) {
|
if (request->has_error()) {
|
||||||
close_a_database_connection(*connection);
|
close_a_database_connection(*connection);
|
||||||
return WebIDL::AbortError::create(realm, "Upgrade transaction was aborted"_utf16);
|
return WebIDL::AbortError::create(realm, "Upgrade transaction was aborted"_utf16);
|
||||||
}
|
}
|
||||||
|
@ -360,7 +359,7 @@ void close_a_database_connection(GC::Ref<IDBDatabase> connection, bool forced)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/IndexedDB/#upgrade-a-database
|
// https://w3c.github.io/IndexedDB/#upgrade-a-database
|
||||||
GC::Ref<IDBTransaction> upgrade_a_database(JS::Realm& realm, GC::Ref<IDBDatabase> connection, u64 version, GC::Ref<IDBRequest> request)
|
void upgrade_a_database(JS::Realm& realm, GC::Ref<IDBDatabase> connection, u64 version, GC::Ref<IDBRequest> request)
|
||||||
{
|
{
|
||||||
// 1. Let db be connection’s database.
|
// 1. Let db be connection’s database.
|
||||||
auto db = connection->associated_database();
|
auto db = connection->associated_database();
|
||||||
|
@ -431,8 +430,6 @@ GC::Ref<IDBTransaction> upgrade_a_database(JS::Realm& realm, GC::Ref<IDBDatabase
|
||||||
dbgln_if(IDB_DEBUG, "upgrade_a_database: waiting for step 11");
|
dbgln_if(IDB_DEBUG, "upgrade_a_database: waiting for step 11");
|
||||||
return transaction->is_finished();
|
return transaction->is_finished();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return transaction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/IndexedDB/#deleting-a-database
|
// https://w3c.github.io/IndexedDB/#deleting-a-database
|
||||||
|
@ -1209,7 +1206,7 @@ GC::Ref<IDBRequest> asynchronously_execute_a_request(JS::Realm& realm, IDBReques
|
||||||
request->set_result(result.release_value());
|
request->set_result(result.release_value());
|
||||||
|
|
||||||
// 2. Set request’s error to undefined.
|
// 2. Set request’s error to undefined.
|
||||||
request->set_error(nullptr);
|
request->set_error(Optional<GC::Ptr<WebIDL::DOMException>> {});
|
||||||
|
|
||||||
// 3. Fire a success event at request.
|
// 3. Fire a success event at request.
|
||||||
fire_a_success_event(realm, request);
|
fire_a_success_event(realm, request);
|
||||||
|
|
|
@ -24,7 +24,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&,
|
||||||
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>);
|
||||||
WebIDL::ExceptionOr<GC::Ref<Key>> convert_a_value_to_a_key(JS::Realm&, JS::Value, Vector<JS::Value> = {});
|
WebIDL::ExceptionOr<GC::Ref<Key>> convert_a_value_to_a_key(JS::Realm&, JS::Value, Vector<JS::Value> = {});
|
||||||
void close_a_database_connection(GC::Ref<IDBDatabase>, bool forced = false);
|
void close_a_database_connection(GC::Ref<IDBDatabase>, bool forced = false);
|
||||||
GC::Ref<IDBTransaction> upgrade_a_database(JS::Realm&, GC::Ref<IDBDatabase>, u64, GC::Ref<IDBRequest>);
|
void upgrade_a_database(JS::Realm&, GC::Ref<IDBDatabase>, u64, GC::Ref<IDBRequest>);
|
||||||
WebIDL::ExceptionOr<u64> delete_a_database(JS::Realm&, StorageAPI::StorageKey, String, GC::Ref<IDBRequest>);
|
WebIDL::ExceptionOr<u64> delete_a_database(JS::Realm&, StorageAPI::StorageKey, String, GC::Ref<IDBRequest>);
|
||||||
void abort_a_transaction(GC::Ref<IDBTransaction>, GC::Ptr<WebIDL::DOMException>);
|
void abort_a_transaction(GC::Ref<IDBTransaction>, GC::Ptr<WebIDL::DOMException>);
|
||||||
JS::Value convert_a_key_to_a_value(JS::Realm&, GC::Ref<Key>);
|
JS::Value convert_a_key_to_a_value(JS::Realm&, GC::Ref<Key>);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue