1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibWeb: Do not use JS::Handle for "scripts to execute" in DOM::Document

Using JS::Handle in members of GC-allocated object almost always leaks.
Instead we should visit these members in visit_edges().
This commit is contained in:
Aliaksandr Kalenik 2023-09-27 17:27:47 +02:00 committed by Andreas Kling
parent cad2d2c85b
commit dc19de58d0
2 changed files with 30 additions and 18 deletions

View file

@ -1512,32 +1512,44 @@ JS::NonnullGCPtr<HTML::HTMLScriptElement> Document::take_pending_parsing_blockin
void Document::add_script_to_execute_when_parsing_has_finished(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement& script)
{
m_scripts_to_execute_when_parsing_has_finished.append(JS::make_handle(script));
m_scripts_to_execute_when_parsing_has_finished.append(script);
}
Vector<JS::Handle<HTML::HTMLScriptElement>> Document::take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>)
{
return move(m_scripts_to_execute_when_parsing_has_finished);
Vector<JS::Handle<HTML::HTMLScriptElement>> handles;
for (auto script : m_scripts_to_execute_when_parsing_has_finished)
handles.append(JS::make_handle(script));
m_scripts_to_execute_when_parsing_has_finished.clear();
return handles;
}
void Document::add_script_to_execute_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement& script)
{
m_scripts_to_execute_as_soon_as_possible.append(JS::make_handle(script));
m_scripts_to_execute_as_soon_as_possible.append(script);
}
Vector<JS::Handle<HTML::HTMLScriptElement>> Document::take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>)
{
return move(m_scripts_to_execute_as_soon_as_possible);
Vector<JS::Handle<HTML::HTMLScriptElement>> handles;
for (auto script : m_scripts_to_execute_as_soon_as_possible)
handles.append(JS::make_handle(script));
m_scripts_to_execute_as_soon_as_possible.clear();
return handles;
}
void Document::add_script_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement& script)
{
m_scripts_to_execute_in_order_as_soon_as_possible.append(JS::make_handle(script));
m_scripts_to_execute_in_order_as_soon_as_possible.append(script);
}
Vector<JS::Handle<HTML::HTMLScriptElement>> Document::take_scripts_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLParser>)
{
return move(m_scripts_to_execute_in_order_as_soon_as_possible);
Vector<JS::Handle<HTML::HTMLScriptElement>> handles;
for (auto script : m_scripts_to_execute_in_order_as_soon_as_possible)
handles.append(JS::make_handle(script));
m_scripts_to_execute_in_order_as_soon_as_possible.clear();
return handles;
}
// https://dom.spec.whatwg.org/#dom-document-importnode
@ -1942,8 +1954,8 @@ void Document::completely_finish_loading()
auto observers_to_notify = m_document_observers.values();
for (auto& document_observer : observers_to_notify) {
if (document_observer->document_completely_loaded)
document_observer->document_completely_loaded();
if (document_observer->document_completely_loaded())
document_observer->document_completely_loaded()->function()();
}
}
@ -2897,8 +2909,8 @@ void Document::did_stop_being_active_document_in_browsing_context(Badge<HTML::Br
auto observers_to_notify = m_document_observers.values();
for (auto& document_observer : observers_to_notify) {
if (document_observer->document_became_inactive)
document_observer->document_became_inactive();
if (document_observer->document_became_inactive())
document_observer->document_became_inactive()->function()();
}
}
@ -2908,8 +2920,8 @@ void Document::did_stop_being_active_document_in_navigable()
auto observers_to_notify = m_document_observers.values();
for (auto& document_observer : observers_to_notify) {
if (document_observer->document_became_inactive)
document_observer->document_became_inactive();
if (document_observer->document_became_inactive())
document_observer->document_became_inactive()->function()();
}
}