1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

LibWeb: Add XMLHttpRequest object :^)

This patch adds very basic XMLHttpRequest support to LibWeb. Here's an
example that currently works:

    var callback = function() { alert(this.responseText); }
    var xhr = new XMLHttpRequest();
    xhr.addEventListener("load", callback);
    xhr.open("GET", "http://serenityos.org/~kling/test/example.txt");
    xhr.send();

There are many limitations and bugs, but it's pretty dang awesome that
we have XHR. :^)
This commit is contained in:
Andreas Kling 2020-04-08 21:11:51 +02:00
parent b3c62d0bc8
commit 4ffac713b9
13 changed files with 546 additions and 3 deletions

View file

@ -32,6 +32,8 @@
#include <LibWeb/Bindings/DocumentWrapper.h>
#include <LibWeb/Bindings/NavigatorObject.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/Bindings/XMLHttpRequestConstructor.h>
#include <LibWeb/Bindings/XMLHttpRequestPrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Window.h>
@ -50,12 +52,24 @@ WindowObject::WindowObject(Window& impl)
put_native_function("cancelAnimationFrame", cancel_animation_frame, 1);
put("navigator", heap().allocate<NavigatorObject>());
m_xhr_prototype = heap().allocate<XMLHttpRequestPrototype>();
m_xhr_constructor = heap().allocate<XMLHttpRequestConstructor>();
m_xhr_constructor->put("prototype", m_xhr_prototype);
put("XMLHttpRequest", m_xhr_constructor);
}
WindowObject::~WindowObject()
{
}
void WindowObject::visit_children(Visitor& visitor)
{
GlobalObject::visit_children(visitor);
visitor.visit(m_xhr_constructor);
visitor.visit(m_xhr_prototype);
}
static Window* impl_from(JS::Interpreter& interpreter)
{
auto* this_object = interpreter.this_value().to_object(interpreter.heap());