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

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/AbortSignalWrapper.h>
#include <LibWeb/Bindings/DOMExceptionWrapper.h>
#include <LibWeb/Bindings/Wrapper.h>
#include <LibWeb/DOM/AbortSignal.h>
@ -14,14 +13,14 @@
namespace Web::DOM {
AbortSignal::AbortSignal()
: EventTarget()
JS::NonnullGCPtr<AbortSignal> AbortSignal::create_with_global_object(HTML::Window& window)
{
return *window.heap().allocate<AbortSignal>(window.realm(), window);
}
JS::Object* AbortSignal::create_wrapper(JS::Realm& realm)
AbortSignal::AbortSignal(HTML::Window& window)
: EventTarget(window.realm())
{
return wrap(realm, *this);
}
// https://dom.spec.whatwg.org/#abortsignal-add
@ -38,10 +37,6 @@ void AbortSignal::add_abort_algorithm(Function<void()> abort_algorithm)
// https://dom.spec.whatwg.org/#abortsignal-signal-abort
void AbortSignal::signal_abort(JS::Value reason)
{
VERIFY(wrapper());
auto& vm = wrapper()->vm();
auto& realm = *vm.current_realm();
// 1. If signal is aborted, then return.
if (aborted())
return;
@ -50,7 +45,7 @@ void AbortSignal::signal_abort(JS::Value reason)
if (!reason.is_undefined())
m_abort_reason = reason;
else
m_abort_reason = wrap(realm, AbortError::create("Aborted without reason"));
m_abort_reason = wrap(realm(), AbortError::create("Aborted without reason"));
// 3. For each algorithm in signals abort algorithms: run algorithm.
for (auto& algorithm : m_abort_algorithms)
@ -60,7 +55,7 @@ void AbortSignal::signal_abort(JS::Value reason)
m_abort_algorithms.clear();
// 5. Fire an event named abort at signal.
dispatch_event(*Event::create(verify_cast<Bindings::WindowObject>(wrapper()->global_object()), HTML::EventNames::abort));
dispatch_event(*Event::create(global_object(), HTML::EventNames::abort));
}
void AbortSignal::set_onabort(Bindings::CallbackType* event_handler)
@ -85,6 +80,7 @@ JS::ThrowCompletionOr<void> AbortSignal::throw_if_aborted() const
void AbortSignal::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_abort_reason);
}