mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:47:44 +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
|
@ -6,25 +6,26 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/Bindings/DOMImplementationPrototype.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/DOM/DOMImplementation.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/DocumentType.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/Origin.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
JS::NonnullGCPtr<DOMImplementation> DOMImplementation::create(Document& document)
|
||||
{
|
||||
auto& window_object = document.preferred_window_object();
|
||||
return *window_object.heap().allocate<DOMImplementation>(window_object.realm(), document);
|
||||
auto& window = document.window();
|
||||
return *window.heap().allocate<DOMImplementation>(document.realm(), document);
|
||||
}
|
||||
|
||||
DOMImplementation::DOMImplementation(Document& document)
|
||||
: PlatformObject(document.preferred_window_object().ensure_web_prototype<Bindings::DOMImplementationPrototype>("DOMImplementation"))
|
||||
: PlatformObject(document.window().ensure_web_prototype<Bindings::DOMImplementationPrototype>("DOMImplementation"))
|
||||
, m_document(document)
|
||||
{
|
||||
}
|
||||
|
@ -38,23 +39,23 @@ void DOMImplementation::visit_edges(Cell::Visitor& visitor)
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocument
|
||||
ExceptionOr<NonnullRefPtr<Document>> DOMImplementation::create_document(String const& namespace_, String const& qualified_name, RefPtr<DocumentType> doctype) const
|
||||
ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_document(String const& namespace_, String const& qualified_name, JS::GCPtr<DocumentType> doctype) const
|
||||
{
|
||||
// FIXME: This should specifically be an XML document.
|
||||
auto xml_document = Document::create();
|
||||
auto xml_document = Document::create(Bindings::main_thread_internal_window_object());
|
||||
|
||||
xml_document->set_ready_for_post_load_tasks(true);
|
||||
|
||||
RefPtr<Element> element;
|
||||
JS::GCPtr<Element> element;
|
||||
|
||||
if (!qualified_name.is_empty())
|
||||
element = TRY(xml_document->create_element_ns(namespace_, qualified_name /* FIXME: and an empty dictionary */));
|
||||
|
||||
if (doctype)
|
||||
xml_document->append_child(doctype.release_nonnull());
|
||||
xml_document->append_child(*doctype);
|
||||
|
||||
if (element)
|
||||
xml_document->append_child(element.release_nonnull());
|
||||
xml_document->append_child(*element);
|
||||
|
||||
xml_document->set_origin(document().origin());
|
||||
|
||||
|
@ -69,16 +70,16 @@ ExceptionOr<NonnullRefPtr<Document>> DOMImplementation::create_document(String c
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
||||
NonnullRefPtr<Document> DOMImplementation::create_html_document(String const& title) const
|
||||
JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(String const& title) const
|
||||
{
|
||||
auto html_document = Document::create();
|
||||
auto html_document = Document::create(Bindings::main_thread_internal_window_object());
|
||||
|
||||
html_document->set_content_type("text/html");
|
||||
html_document->set_ready_for_post_load_tasks(true);
|
||||
|
||||
auto doctype = adopt_ref(*new DocumentType(html_document));
|
||||
auto doctype = heap().allocate<DocumentType>(realm(), html_document);
|
||||
doctype->set_name("html");
|
||||
html_document->append_child(doctype);
|
||||
html_document->append_child(*doctype);
|
||||
|
||||
auto html_element = create_element(html_document, HTML::TagNames::html, Namespace::HTML);
|
||||
html_document->append_child(html_element);
|
||||
|
@ -90,8 +91,8 @@ NonnullRefPtr<Document> DOMImplementation::create_html_document(String const& ti
|
|||
auto title_element = create_element(html_document, HTML::TagNames::title, Namespace::HTML);
|
||||
head_element->append_child(title_element);
|
||||
|
||||
auto text_node = adopt_ref(*new Text(html_document, title));
|
||||
title_element->append_child(text_node);
|
||||
auto text_node = heap().allocate<Text>(realm(), html_document, title);
|
||||
title_element->append_child(*text_node);
|
||||
}
|
||||
|
||||
auto body_element = create_element(html_document, HTML::TagNames::body, Namespace::HTML);
|
||||
|
@ -103,7 +104,7 @@ NonnullRefPtr<Document> DOMImplementation::create_html_document(String const& ti
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype
|
||||
ExceptionOr<NonnullRefPtr<DocumentType>> DOMImplementation::create_document_type(String const& qualified_name, String const& public_id, String const& system_id)
|
||||
ExceptionOr<JS::NonnullGCPtr<DocumentType>> DOMImplementation::create_document_type(String const& qualified_name, String const& public_id, String const& system_id)
|
||||
{
|
||||
TRY(Document::validate_qualified_name(qualified_name));
|
||||
auto document_type = DocumentType::create(document());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue