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
Notes: sideshowbarker 2024-07-17 09:39:38 +09:00
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()();
}
}

View File

@ -253,15 +253,15 @@ public:
void add_script_to_execute_when_parsing_has_finished(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>);
Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_when_parsing_has_finished() { return m_scripts_to_execute_when_parsing_has_finished; }
Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>>& scripts_to_execute_when_parsing_has_finished() { return m_scripts_to_execute_when_parsing_has_finished; }
void add_script_to_execute_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>);
Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_as_soon_as_possible() { return m_scripts_to_execute_as_soon_as_possible; }
Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>>& scripts_to_execute_as_soon_as_possible() { return m_scripts_to_execute_as_soon_as_possible; }
void add_script_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLParser>);
Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_in_order_as_soon_as_possible() { return m_scripts_to_execute_in_order_as_soon_as_possible; }
Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>>& scripts_to_execute_in_order_as_soon_as_possible() { return m_scripts_to_execute_in_order_as_soon_as_possible; }
QuirksMode mode() const { return m_quirks_mode; }
bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
@ -583,13 +583,13 @@ private:
JS::GCPtr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script;
Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_when_parsing_has_finished;
Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>> m_scripts_to_execute_when_parsing_has_finished;
// https://html.spec.whatwg.org/multipage/scripting.html#list-of-scripts-that-will-execute-in-order-as-soon-as-possible
Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_in_order_as_soon_as_possible;
Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>> m_scripts_to_execute_in_order_as_soon_as_possible;
// https://html.spec.whatwg.org/multipage/scripting.html#set-of-scripts-that-will-execute-as-soon-as-possible
Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_as_soon_as_possible;
Vector<JS::NonnullGCPtr<HTML::HTMLScriptElement>> m_scripts_to_execute_as_soon_as_possible;
QuirksMode m_quirks_mode { QuirksMode::No };