diff options
author | Linus Groh <mail@linusgroh.de> | 2021-04-03 15:17:29 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-03 16:34:34 +0200 |
commit | 288b90a297e63ed9f181f36e28dd5ff8a17ef456 (patch) | |
tree | 398c488dc0a6a4a3aec3353578480789ec11e886 /Userland/Libraries | |
parent | e02270c5cc1692761a60d7928e6d2adf740b27aa (diff) | |
download | serenity-288b90a297e63ed9f181f36e28dd5ff8a17ef456.zip |
LibWeb: Implement XMLHttpRequest.status
This lets jQuery's AJAX functionality progress further :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl | 1 |
3 files changed, 8 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 72518bdb15..4a967672ce 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -229,7 +229,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::send() // we need to make ResourceLoader give us more detailed updates than just "done" and "error". ResourceLoader::the().load( request, - [weak_this = make_weak_ptr()](auto data, auto&, auto) { + [weak_this = make_weak_ptr()](auto data, auto&, auto status_code) { if (!weak_this) return; auto& xhr = const_cast<XMLHttpRequest&>(*weak_this); @@ -244,16 +244,18 @@ DOM::ExceptionOr<void> XMLHttpRequest::send() } xhr.m_ready_state = ReadyState::Done; + xhr.m_status = status_code.value_or(0); xhr.m_send = false; xhr.dispatch_event(DOM::Event::create(EventNames::readystatechange)); xhr.fire_progress_event(EventNames::load, transmitted, length); xhr.fire_progress_event(EventNames::loadend, transmitted, length); }, - [weak_this = make_weak_ptr()](auto& error, auto) { + [weak_this = make_weak_ptr()](auto& error, auto status_code) { if (!weak_this) return; dbgln("XHR failed to load: {}", error); const_cast<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done); + const_cast<XMLHttpRequest&>(*weak_this).set_status(status_code.value_or(0)); const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create(HTML::EventNames::error)); }); } else { diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index f90a5bf532..1bdcb93925 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -68,6 +68,7 @@ public: using RefCounted::unref; ReadyState ready_state() const { return m_ready_state; }; + unsigned status() const { return m_status; }; String response_text() const; DOM::ExceptionOr<void> open(const String& method, const String& url); @@ -82,6 +83,7 @@ private: virtual JS::Object* create_wrapper(JS::GlobalObject&) override; void set_ready_state(ReadyState); + void set_status(unsigned status) { m_status = status; } void fire_progress_event(const String&, u64, u64); explicit XMLHttpRequest(DOM::Window&); @@ -89,6 +91,7 @@ private: NonnullRefPtr<DOM::Window> m_window; ReadyState m_ready_state { ReadyState::Unsent }; + unsigned m_status { 0 }; bool m_send { false }; String m_method; diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl index f6e25809b5..35a63d0532 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl @@ -9,6 +9,7 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget { const unsigned short DONE = 4; readonly attribute unsigned short readyState; + readonly attribute unsigned short status; readonly attribute DOMString responseText; undefined open(DOMString method, DOMString url); |