diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-22 19:47:26 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-23 11:03:17 +0200 |
commit | 602a36970fb265b6297a68a92a0d35c8eaede63c (patch) | |
tree | bdbc4adae7da361952f991facc58e6add4ee991d /Libraries/LibWeb/Bindings | |
parent | 3c9693c6c7b6421c1e222fe9a7351e3a19ead5aa (diff) | |
download | serenity-602a36970fb265b6297a68a92a0d35c8eaede63c.zip |
LibWeb: Add XMLHttpRequest.readyState and constants
Diffstat (limited to 'Libraries/LibWeb/Bindings')
-rw-r--r-- | Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp | 15 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h | 1 |
3 files changed, 22 insertions, 0 deletions
diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp b/Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp index 092df6206f..7fea4c1cc1 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp @@ -39,6 +39,12 @@ XMLHttpRequestConstructor::XMLHttpRequestConstructor() : NativeFunction(*interpreter().global_object().function_prototype()) { put("length", JS::Value(1)); + + put("UNSENT", JS::Value((i32)XMLHttpRequest::ReadyState::Unsent)); + put("OPENED", JS::Value((i32)XMLHttpRequest::ReadyState::Opened)); + put("HEADERS_RECEIVED", JS::Value((i32)XMLHttpRequest::ReadyState::HeadersReceived)); + put("LOADING", JS::Value((i32)XMLHttpRequest::ReadyState::Loading)); + put("DONE", JS::Value((i32)XMLHttpRequest::ReadyState::Done)); } XMLHttpRequestConstructor::~XMLHttpRequestConstructor() diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp index 0a72097790..d749663c20 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.cpp @@ -40,7 +40,14 @@ XMLHttpRequestPrototype::XMLHttpRequestPrototype() { put_native_function("open", open, 2); put_native_function("send", send, 0); + put_native_property("readyState", ready_state_getter, nullptr); put_native_property("responseText", response_text_getter, nullptr); + + put("UNSENT", JS::Value((i32)XMLHttpRequest::ReadyState::Unsent)); + put("OPENED", JS::Value((i32)XMLHttpRequest::ReadyState::Opened)); + put("HEADERS_RECEIVED", JS::Value((i32)XMLHttpRequest::ReadyState::HeadersReceived)); + put("LOADING", JS::Value((i32)XMLHttpRequest::ReadyState::Loading)); + put("DONE", JS::Value((i32)XMLHttpRequest::ReadyState::Done)); } XMLHttpRequestPrototype::~XMLHttpRequestPrototype() @@ -77,6 +84,14 @@ JS::Value XMLHttpRequestPrototype::send(JS::Interpreter& interpreter) return JS::js_undefined(); } +JS::Value XMLHttpRequestPrototype::ready_state_getter(JS::Interpreter& interpreter) +{ + auto* impl = impl_from(interpreter); + if (!impl) + return {}; + return JS::Value((i32)impl->ready_state()); +} + JS::Value XMLHttpRequestPrototype::response_text_getter(JS::Interpreter& interpreter) { auto* impl = impl_from(interpreter); diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h index 3f76025054..3fa5d48869 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestPrototype.h @@ -42,6 +42,7 @@ private: static JS::Value open(JS::Interpreter&); static JS::Value send(JS::Interpreter&); + static JS::Value ready_state_getter(JS::Interpreter&); static JS::Value response_text_getter(JS::Interpreter&); }; |