mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 09:44:58 +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
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/HTMLTableElementPrototype.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
|
@ -12,6 +13,7 @@
|
|||
#include <LibWeb/HTML/HTMLTableElement.h>
|
||||
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -19,6 +21,7 @@ namespace Web::HTML {
|
|||
HTMLTableElement::HTMLTableElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
{
|
||||
set_prototype(&window().ensure_web_prototype<Bindings::HTMLTableElementPrototype>("HTMLTableElement"));
|
||||
}
|
||||
|
||||
HTMLTableElement::~HTMLTableElement() = default;
|
||||
|
@ -45,7 +48,7 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
|
|||
});
|
||||
}
|
||||
|
||||
RefPtr<HTMLTableCaptionElement> HTMLTableElement::caption()
|
||||
JS::GCPtr<HTMLTableCaptionElement> HTMLTableElement::caption()
|
||||
{
|
||||
return first_child_of_type<HTMLTableCaptionElement>();
|
||||
}
|
||||
|
@ -62,7 +65,7 @@ void HTMLTableElement::set_caption(HTMLTableCaptionElement* caption)
|
|||
pre_insert(*caption, first_child());
|
||||
}
|
||||
|
||||
NonnullRefPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
|
||||
JS::NonnullGCPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
|
||||
{
|
||||
auto maybe_caption = caption();
|
||||
if (maybe_caption) {
|
||||
|
@ -71,7 +74,7 @@ NonnullRefPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
|
|||
|
||||
auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML);
|
||||
pre_insert(caption, first_child());
|
||||
return static_ptr_cast<HTMLTableCaptionElement>(caption);
|
||||
return static_cast<HTMLTableCaptionElement&>(*caption);
|
||||
}
|
||||
|
||||
void HTMLTableElement::delete_caption()
|
||||
|
@ -82,7 +85,7 @@ void HTMLTableElement::delete_caption()
|
|||
}
|
||||
}
|
||||
|
||||
RefPtr<HTMLTableSectionElement> HTMLTableElement::t_head()
|
||||
JS::GCPtr<HTMLTableSectionElement> HTMLTableElement::t_head()
|
||||
{
|
||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||
if (is<HTMLTableSectionElement>(*child)) {
|
||||
|
@ -130,7 +133,7 @@ DOM::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement* the
|
|||
return {};
|
||||
}
|
||||
|
||||
NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
|
||||
JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
|
||||
{
|
||||
auto maybe_thead = t_head();
|
||||
if (maybe_thead)
|
||||
|
@ -158,7 +161,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
|
|||
|
||||
pre_insert(thead, child_to_append_after);
|
||||
|
||||
return static_ptr_cast<HTMLTableSectionElement>(thead);
|
||||
return static_cast<HTMLTableSectionElement&>(*thead);
|
||||
}
|
||||
|
||||
void HTMLTableElement::delete_t_head()
|
||||
|
@ -169,7 +172,7 @@ void HTMLTableElement::delete_t_head()
|
|||
}
|
||||
}
|
||||
|
||||
RefPtr<HTMLTableSectionElement> HTMLTableElement::t_foot()
|
||||
JS::GCPtr<HTMLTableSectionElement> HTMLTableElement::t_foot()
|
||||
{
|
||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||
if (is<HTMLTableSectionElement>(*child)) {
|
||||
|
@ -200,7 +203,7 @@ DOM::ExceptionOr<void> HTMLTableElement::set_t_foot(HTMLTableSectionElement* tfo
|
|||
return {};
|
||||
}
|
||||
|
||||
NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_foot()
|
||||
JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_foot()
|
||||
{
|
||||
auto maybe_tfoot = t_foot();
|
||||
if (maybe_tfoot)
|
||||
|
@ -208,7 +211,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_foot()
|
|||
|
||||
auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML);
|
||||
append_child(tfoot);
|
||||
return static_ptr_cast<HTMLTableSectionElement>(tfoot);
|
||||
return static_cast<HTMLTableSectionElement&>(*tfoot);
|
||||
}
|
||||
|
||||
void HTMLTableElement::delete_t_foot()
|
||||
|
@ -226,7 +229,7 @@ NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies()
|
|||
});
|
||||
}
|
||||
|
||||
NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
|
||||
JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
|
||||
{
|
||||
auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML);
|
||||
|
||||
|
@ -247,7 +250,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
|
|||
|
||||
pre_insert(tbody, child_to_append_after);
|
||||
|
||||
return static_ptr_cast<HTMLTableSectionElement>(tbody);
|
||||
return static_cast<HTMLTableSectionElement&>(*tbody);
|
||||
}
|
||||
|
||||
NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::rows()
|
||||
|
@ -278,7 +281,7 @@ NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::rows()
|
|||
});
|
||||
}
|
||||
|
||||
DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableElement::insert_row(long index)
|
||||
DOM::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableElement::insert_row(long index)
|
||||
{
|
||||
auto rows = this->rows();
|
||||
auto rows_length = rows->length();
|
||||
|
@ -286,7 +289,7 @@ DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableElement::insert_ro
|
|||
if (index < -1 || index > (long)rows_length) {
|
||||
return DOM::IndexSizeError::create("Index is negative or greater than the number of rows");
|
||||
}
|
||||
auto tr = static_ptr_cast<HTMLTableRowElement>(DOM::create_element(document(), TagNames::tr, Namespace::HTML));
|
||||
auto& tr = static_cast<HTMLTableRowElement&>(*DOM::create_element(document(), TagNames::tr, Namespace::HTML));
|
||||
if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) {
|
||||
auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML);
|
||||
tbody->append_child(tr);
|
||||
|
@ -300,7 +303,7 @@ DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableElement::insert_ro
|
|||
} else {
|
||||
rows->item(index)->parent_element()->insert_before(tr, rows->item(index));
|
||||
}
|
||||
return tr;
|
||||
return JS::NonnullGCPtr(tr);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/tables.html#dom-table-deleterow
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue