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
Notes: sideshowbarker 2024-07-17 07:28:15 +09:00
445 changed files with 4797 additions and 4268 deletions

View file

@ -5,10 +5,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/HTMLTableSectionElementPrototype.h>
#include <LibWeb/DOM/ElementFactory.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/HTML/HTMLTableRowElement.h>
#include <LibWeb/HTML/HTMLTableSectionElement.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Namespace.h>
namespace Web::HTML {
@ -16,6 +18,7 @@ namespace Web::HTML {
HTMLTableSectionElement::HTMLTableSectionElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().ensure_web_prototype<Bindings::HTMLTableSectionElementPrototype>("HTMLTableSectionElement"));
}
HTMLTableSectionElement::~HTMLTableSectionElement() = default;
@ -34,7 +37,7 @@ NonnullRefPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
}
// https://html.spec.whatwg.org/multipage/tables.html#dom-tbody-insertrow
DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableSectionElement::insert_row(long index)
DOM::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableSectionElement::insert_row(long index)
{
auto rows_collection = rows();
auto rows_collection_size = static_cast<long>(rows_collection->length());
@ -44,17 +47,17 @@ DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableSectionElement::in
return DOM::IndexSizeError::create("Index is negative or greater than the number of rows");
// 2. Let table row be the result of creating an element given this element's node document, tr, and the HTML namespace.
auto table_row = static_ptr_cast<HTMLTableRowElement>(DOM::create_element(document(), TagNames::tr, Namespace::HTML));
auto& table_row = static_cast<HTMLTableRowElement&>(*DOM::create_element(document(), TagNames::tr, Namespace::HTML));
// 3. If index is 1 or equal to the number of items in the rows collection, then append table row to this element.
if (index == -1 || index == rows_collection_size)
append_child(table_row);
// 4. Otherwise, insert table row as a child of this element, immediately before the index-th tr element in the rows collection.
else
table_row->insert_before(*this, rows_collection->item(index));
table_row.insert_before(*this, rows_collection->item(index));
// 5. Return table row.
return table_row;
return JS::NonnullGCPtr(table_row);
}
// https://html.spec.whatwg.org/multipage/tables.html#dom-tbody-deleterow