Skip to content

Truly independent web browser

LibWeb: Throw from IDBRequest.error while the request is pending

Andreas Klingbdd75a85da76
diff --git a/Libraries/LibWeb/IndexedDB/IDBRequest.cpp b/Libraries/LibWeb/IndexedDB/IDBRequest.cpp
index 4f2bd02129e..d65fbfabb25 100644
--- a/Libraries/LibWeb/IndexedDB/IDBRequest.cpp
+++ b/Libraries/LibWeb/IndexedDB/IDBRequest.cpp
@@ -103,7 +103,7 @@ WebIDL::CallbackType* IDBRequest::onerror()
}
// https://w3c.github.io/IndexedDB/#dom-idbrequest-error
-[[nodiscard]] GC::Ptr<WebIDL::DOMException> IDBRequest::error() const
+WebIDL::ExceptionOr<GC::Ptr<WebIDL::DOMException>> IDBRequest::error() const
{
// 1. If this's done flag is false, then throw an "InvalidStateError" DOMException.
if (!m_done)
diff --git a/Libraries/LibWeb/IndexedDB/IDBRequest.h b/Libraries/LibWeb/IndexedDB/IDBRequest.h
index 65eee0ff983..61baa89065b 100644
--- a/Libraries/LibWeb/IndexedDB/IDBRequest.h
+++ b/Libraries/LibWeb/IndexedDB/IDBRequest.h
@@ -41,7 +41,7 @@ public:
[[nodiscard]] HTML::WindowOrWorkerGlobalScopeMixin& relevant_global_scope() const;
[[nodiscard]] JS::Object& relevant_global_object() const;
- [[nodiscard]] GC::Ptr<WebIDL::DOMException> error() const;
+ [[nodiscard]] WebIDL::ExceptionOr<GC::Ptr<WebIDL::DOMException>> error() const;
[[nodiscard]] WebIDL::ExceptionOr<JS::Value> result() const;
[[nodiscard]] Bindings::IDBRequestReadyState ready_state() const;
diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp
index 846fec39edd..2445e25753c 100644
--- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp
+++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp
@@ -1275,7 +1275,7 @@ void fire_an_error_event(JS::Realm& realm, GC::Ref<IDBRequest> request)
// 3. If event’s canceled flag is false, then run abort a transaction using transaction and request's error, and terminate these steps.
if (!event->cancelled()) {
- abort_a_transaction(*transaction, request->error());
+ abort_a_transaction(*transaction, MUST(request->error()));
return;
}
diff --git a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.sharedworker.txt b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.sharedworker.txt
index 52bbe80682f..0b4b6648e18 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.sharedworker.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.sharedworker.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail IDBRequest.error throws if ready state is pending
\ No newline at end of file
+1 Pass
+Pass IDBRequest.error throws if ready state is pending
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.txt b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.txt
index 52bbe80682f..0b4b6648e18 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail IDBRequest.error throws if ready state is pending
\ No newline at end of file
+1 Pass
+Pass IDBRequest.error throws if ready state is pending
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.worker.txt
index 52bbe80682f..0b4b6648e18 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.worker.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idbrequest_error.any.worker.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail IDBRequest.error throws if ready state is pending
\ No newline at end of file
+1 Pass
+Pass IDBRequest.error throws if ready state is pending
\ No newline at end of file