LibWeb: Properly implement IDBRequest::result()

This commit is contained in:
stelar7 2024-11-07 20:24:13 +01:00 committed by Jelle Raaijmakers
parent 204d776cdb
commit 49ad27816b
Notes: github-actions[bot] 2024-11-26 13:52:18 +00:00
2 changed files with 12 additions and 1 deletions

View file

@ -76,4 +76,15 @@ WebIDL::CallbackType* IDBRequest::onerror()
return m_error;
}
// https://w3c.github.io/IndexedDB/#dom-idbrequest-result
[[nodiscard]] WebIDL::ExceptionOr<JS::Value> IDBRequest::result() const
{
// 1. If this's done flag is false, then throw an "InvalidStateError" DOMException.
if (!m_done)
return WebIDL::InvalidStateError::create(realm(), "The request is not done"_string);
// 2. Otherwise, return this's result, or undefined if the request resulted in an error.
return m_result;
}
}

View file

@ -22,13 +22,13 @@ class IDBRequest : public DOM::EventTarget {
public:
virtual ~IDBRequest() override;
[[nodiscard]] JS::Value result() const { return m_result; }
[[nodiscard]] bool done() const { return m_done; }
[[nodiscard]] bool processed() const { return m_processed; }
[[nodiscard]] IDBRequestSource source() const { return m_source; }
[[nodiscard]] Bindings::IDBRequestReadyState ready_state() const;
[[nodiscard]] WebIDL::ExceptionOr<GC::Ptr<WebIDL::DOMException>> error() const;
[[nodiscard]] WebIDL::ExceptionOr<JS::Value> result() const;
void set_done(bool done) { m_done = done; }
void set_result(JS::Value result) { m_result = result; }