mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 10:37:17 +02: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:
Notes:
sideshowbarker
2024-07-17 07:28:15 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6f433c8656 Pull-request: https://github.com/SerenityOS/serenity/pull/14816 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg ✅
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user