1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibWeb: Add XMLHttpRequest.readyState and constants

This commit is contained in:
Linus Groh 2020-04-22 19:47:26 +01:00 committed by Andreas Kling
parent 3c9693c6c7
commit 602a36970f
5 changed files with 46 additions and 0 deletions

View file

@ -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()

View file

@ -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);

View file

@ -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&);
};