1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +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

@ -8,11 +8,11 @@
#include <AK/CharacterTypes.h>
#include <AK/StringBuilder.h>
#include <LibWeb/Bindings/DOMTokenListPrototype.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/DOMTokenList.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/HTML/Window.h>
namespace {
@ -56,13 +56,13 @@ namespace Web::DOM {
DOMTokenList* DOMTokenList::create(Element const& associated_element, FlyString associated_attribute)
{
auto& realm = associated_element.document().preferred_window_object().realm();
auto& realm = associated_element.document().window().realm();
return realm.heap().allocate<DOMTokenList>(realm, associated_element, move(associated_attribute));
}
// https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A2
DOMTokenList::DOMTokenList(Element const& associated_element, FlyString associated_attribute)
: Bindings::LegacyPlatformObject(associated_element.document().preferred_window_object().ensure_web_prototype<Bindings::DOMTokenListPrototype>("DOMTokenList"))
: Bindings::LegacyPlatformObject(associated_element.document().window().ensure_web_prototype<Bindings::DOMTokenListPrototype>("DOMTokenList"))
, m_associated_element(associated_element)
, m_associated_attribute(move(associated_attribute))
{
@ -225,7 +225,7 @@ String DOMTokenList::value() const
// https://dom.spec.whatwg.org/#ref-for-concept-element-attributes-set-value%E2%91%A2
void DOMTokenList::set_value(String value)
{
auto associated_element = m_associated_element.strong_ref();
JS::GCPtr<DOM::Element> associated_element = m_associated_element.ptr();
if (!associated_element)
return;
@ -244,7 +244,7 @@ ExceptionOr<void> DOMTokenList::validate_token(StringView token) const
// https://dom.spec.whatwg.org/#concept-dtl-update
void DOMTokenList::run_update_steps()
{
auto associated_element = m_associated_element.strong_ref();
JS::GCPtr<DOM::Element> associated_element = m_associated_element.ptr();
if (!associated_element)
return;