1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:47:34 +00:00

LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated

This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
This commit is contained in:
Andreas Kling 2022-08-28 13:42:07 +02:00
parent bb547ce1c4
commit 6f433c8656
445 changed files with 4797 additions and 4268 deletions

View file

@ -11,12 +11,12 @@
#include <AK/RefCounted.h>
#include <AK/URL.h>
#include <AK/Weakable.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/MimeSniff/MimeType.h>
#include <LibWeb/URL/URLSearchParams.h>
#include <LibWeb/XHR/XMLHttpRequestEventTarget.h>
@ -26,10 +26,9 @@ namespace Web::XHR {
// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
using XMLHttpRequestBodyInit = Variant<NonnullRefPtr<FileAPI::Blob>, JS::Handle<JS::Object>, NonnullRefPtr<URL::URLSearchParams>, String>;
class XMLHttpRequest final
: public RefCounted<XMLHttpRequest>
, public Weakable<XMLHttpRequest>
, public XMLHttpRequestEventTarget {
class XMLHttpRequest final : public XMLHttpRequestEventTarget {
WEB_PLATFORM_OBJECT(XMLHttpRequest, XMLHttpRequestEventTarget);
public:
enum class ReadyState : u16 {
Unsent = 0,
@ -39,22 +38,10 @@ public:
Done = 4,
};
using WrapperType = Bindings::XMLHttpRequestWrapper;
static NonnullRefPtr<XMLHttpRequest> create(HTML::Window& window)
{
return adopt_ref(*new XMLHttpRequest(window));
}
static NonnullRefPtr<XMLHttpRequest> create_with_global_object(Bindings::WindowObject& window)
{
return XMLHttpRequest::create(window.impl());
}
static JS::NonnullGCPtr<XMLHttpRequest> create_with_global_object(HTML::Window&);
virtual ~XMLHttpRequest() override;
using RefCounted::ref;
using RefCounted::unref;
ReadyState ready_state() const { return m_ready_state; };
Fetch::Infrastructure::Status status() const { return m_status; };
DOM::ExceptionOr<String> response_text() const;
@ -80,9 +67,7 @@ public:
u32 timeout() const;
private:
virtual void ref_event_target() override { ref(); }
virtual void unref_event_target() override { unref(); }
virtual JS::Object* create_wrapper(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
void set_ready_state(ReadyState);
void set_status(Fetch::Infrastructure::Status status) { m_status = status; }
@ -96,7 +81,7 @@ private:
explicit XMLHttpRequest(HTML::Window&);
NonnullRefPtr<HTML::Window> m_window;
JS::NonnullGCPtr<HTML::Window> m_window;
ReadyState m_ready_state { ReadyState::Unsent };
Fetch::Infrastructure::Status m_status { 0 };
@ -128,3 +113,5 @@ private:
};
}
WRAPPER_HACK(XMLHttpRequest, Web::XHR)