mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +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:
parent
bb547ce1c4
commit
6f433c8656
445 changed files with 4797 additions and 4268 deletions
|
@ -141,12 +141,12 @@ void EventLoop::process()
|
|||
// - Any Document B whose browsing context's container document is A must be listed after A in the list.
|
||||
// - If there are two documents A and B whose browsing contexts are both child browsing contexts whose container documents are another Document C, then the order of A and B in the list must match the shadow-including tree order of their respective browsing context containers in C's node tree.
|
||||
// FIXME: NOTE: The sort order specified above is missing here!
|
||||
NonnullRefPtrVector<DOM::Document> docs = documents_in_this_event_loop();
|
||||
Vector<JS::Handle<DOM::Document>> docs = documents_in_this_event_loop();
|
||||
|
||||
auto for_each_fully_active_document_in_docs = [&](auto&& callback) {
|
||||
for (auto& document : docs) {
|
||||
if (document.is_fully_active())
|
||||
callback(document);
|
||||
if (document->is_fully_active())
|
||||
callback(*document);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -215,7 +215,7 @@ void EventLoop::process()
|
|||
// 3. For each win of the same-loop windows for this event loop,
|
||||
// perform the start an idle period algorithm for win with computeDeadline. [REQUESTIDLECALLBACK]
|
||||
for (auto& win : same_loop_windows())
|
||||
win.start_an_idle_period();
|
||||
win->start_an_idle_period();
|
||||
}
|
||||
|
||||
// FIXME: 14. If this is a worker event loop, then:
|
||||
|
@ -248,8 +248,8 @@ void queue_global_task(HTML::Task::Source source, JS::Object& global_object, Fun
|
|||
|
||||
// 2. Let document be global's associated Document, if global is a Window object; otherwise null.
|
||||
DOM::Document* document { nullptr };
|
||||
if (is<Bindings::WindowObject>(global_object)) {
|
||||
auto& window_object = verify_cast<Bindings::WindowObject>(global_object);
|
||||
if (is<HTML::Window>(global_object)) {
|
||||
auto& window_object = verify_cast<HTML::Window>(global_object);
|
||||
document = &window_object.impl().associated_document();
|
||||
}
|
||||
|
||||
|
@ -320,12 +320,12 @@ void EventLoop::perform_a_microtask_checkpoint()
|
|||
m_performing_a_microtask_checkpoint = false;
|
||||
}
|
||||
|
||||
NonnullRefPtrVector<DOM::Document> EventLoop::documents_in_this_event_loop() const
|
||||
Vector<JS::Handle<DOM::Document>> EventLoop::documents_in_this_event_loop() const
|
||||
{
|
||||
NonnullRefPtrVector<DOM::Document> documents;
|
||||
Vector<JS::Handle<DOM::Document>> documents;
|
||||
for (auto& document : m_documents) {
|
||||
VERIFY(document);
|
||||
documents.append(*document);
|
||||
documents.append(JS::make_handle(*document.ptr()));
|
||||
}
|
||||
return documents;
|
||||
}
|
||||
|
@ -368,11 +368,11 @@ void EventLoop::unregister_environment_settings_object(Badge<EnvironmentSettings
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#same-loop-windows
|
||||
NonnullRefPtrVector<Window> EventLoop::same_loop_windows() const
|
||||
Vector<JS::Handle<HTML::Window>> EventLoop::same_loop_windows() const
|
||||
{
|
||||
NonnullRefPtrVector<Window> windows;
|
||||
Vector<JS::Handle<HTML::Window>> windows;
|
||||
for (auto& document : documents_in_this_event_loop())
|
||||
windows.append(document.window());
|
||||
windows.append(JS::make_handle(document->window()));
|
||||
return windows;
|
||||
}
|
||||
|
||||
|
@ -394,7 +394,7 @@ double EventLoop::compute_deadline() const
|
|||
// 1. If windowInSameLoop's map of animation frame callbacks is not empty,
|
||||
// or if the user agent believes that the windowInSameLoop might have pending rendering updates,
|
||||
// set hasPendingRenders to true.
|
||||
if (window.has_animation_frame_callbacks())
|
||||
if (window->has_animation_frame_callbacks())
|
||||
has_pending_renders = true;
|
||||
// FIXME: 2. Let timerCallbackEstimates be the result of getting the values of windowInSameLoop's map of active timers.
|
||||
// FIXME: 3. For each timeoutDeadline of timerCallbackEstimates, if timeoutDeadline is less than deadline, set deadline to timeoutDeadline.
|
||||
|
|
|
@ -53,9 +53,9 @@ public:
|
|||
void register_document(Badge<DOM::Document>, DOM::Document&);
|
||||
void unregister_document(Badge<DOM::Document>, DOM::Document&);
|
||||
|
||||
NonnullRefPtrVector<DOM::Document> documents_in_this_event_loop() const;
|
||||
Vector<JS::Handle<DOM::Document>> documents_in_this_event_loop() const;
|
||||
|
||||
NonnullRefPtrVector<Window> same_loop_windows() const;
|
||||
Vector<JS::Handle<HTML::Window>> same_loop_windows() const;
|
||||
|
||||
void push_onto_backup_incumbent_settings_object_stack(Badge<EnvironmentSettingsObject>, EnvironmentSettingsObject& environment_settings_object);
|
||||
void pop_backup_incumbent_settings_object_stack(Badge<EnvironmentSettingsObject>);
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Web::HTML {
|
|||
Task::Task(Source source, DOM::Document* document, Function<void()> steps)
|
||||
: m_source(source)
|
||||
, m_steps(move(steps))
|
||||
, m_document(document)
|
||||
, m_document(JS::make_handle(document))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,17 @@ void Task::execute()
|
|||
bool Task::is_runnable() const
|
||||
{
|
||||
// A task is runnable if its document is either null or fully active.
|
||||
return !m_document || m_document->is_fully_active();
|
||||
return !m_document.ptr() || m_document->is_fully_active();
|
||||
}
|
||||
|
||||
DOM::Document* Task::document()
|
||||
{
|
||||
return m_document.ptr();
|
||||
}
|
||||
|
||||
DOM::Document const* Task::document() const
|
||||
{
|
||||
return m_document.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Function.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -38,8 +39,8 @@ public:
|
|||
Source source() const { return m_source; }
|
||||
void execute();
|
||||
|
||||
DOM::Document* document() { return m_document; }
|
||||
DOM::Document const* document() const { return m_document; }
|
||||
DOM::Document* document();
|
||||
DOM::Document const* document() const;
|
||||
|
||||
bool is_runnable() const;
|
||||
|
||||
|
@ -48,7 +49,7 @@ private:
|
|||
|
||||
Source m_source { Source::Unspecified };
|
||||
Function<void()> m_steps;
|
||||
RefPtr<DOM::Document> m_document;
|
||||
JS::Handle<DOM::Document> m_document;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue