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

@ -5,16 +5,19 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/HTMLSelectElementPrototype.h>
#include <LibWeb/HTML/HTMLFormElement.h>
#include <LibWeb/HTML/HTMLOptGroupElement.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/HTML/HTMLSelectElement.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
HTMLSelectElement::HTMLSelectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().ensure_web_prototype<Bindings::HTMLSelectElementPrototype>("HTMLSelectElement"));
}
HTMLSelectElement::~HTMLSelectElement() = default;
@ -42,19 +45,19 @@ DOM::ExceptionOr<void> HTMLSelectElement::add(HTMLOptionOrOptGroupElement elemen
}
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-option-list
NonnullRefPtrVector<HTMLOptionElement> HTMLSelectElement::list_of_options() const
Vector<JS::Handle<HTMLOptionElement>> HTMLSelectElement::list_of_options() const
{
// The list of options for a select element consists of all the option element children of the select element,
// and all the option element children of all the optgroup element children of the select element, in tree order.
NonnullRefPtrVector<HTMLOptionElement> list;
Vector<JS::Handle<HTMLOptionElement>> list;
for_each_child_of_type<HTMLOptionElement>([&](HTMLOptionElement const& option_element) {
list.append(option_element);
list.append(JS::make_handle(const_cast<HTMLOptionElement&>(option_element)));
});
for_each_child_of_type<HTMLOptGroupElement>([&](HTMLOptGroupElement const& optgroup_element) {
optgroup_element.for_each_child_of_type<HTMLOptionElement>([&](HTMLOptionElement const& option_element) {
list.append(option_element);
list.append(JS::make_handle(const_cast<HTMLOptionElement&>(option_element)));
});
});
@ -69,7 +72,7 @@ int HTMLSelectElement::selected_index() const
int index = 0;
for (auto const& option_element : list_of_options()) {
if (option_element.selected())
if (option_element->selected())
return index;
++index;
}
@ -83,14 +86,14 @@ void HTMLSelectElement::set_selected_index(int index)
// if any, must have its selectedness set to true and its dirtiness set to true.
auto options = list_of_options();
for (auto& option : options)
option.m_selected = false;
option->m_selected = false;
if (index < 0 || index >= static_cast<int>(options.size()))
return;
auto& selected_option = options[index];
selected_option.m_selected = true;
selected_option.m_dirty = true;
selected_option->m_selected = true;
selected_option->m_dirty = true;
}
}