mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +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,6 +6,7 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/DocumentFragment.h>
|
||||
#include <LibWeb/DOM/NodeOperations.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
|
@ -13,7 +14,7 @@
|
|||
namespace Web::DOM {
|
||||
|
||||
// https://dom.spec.whatwg.org/#converting-nodes-into-a-node
|
||||
ExceptionOr<NonnullRefPtr<Node>> convert_nodes_to_single_node(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes, DOM::Document& document)
|
||||
ExceptionOr<JS::NonnullGCPtr<Node>> convert_nodes_to_single_node(Vector<Variant<JS::Handle<Node>, String>> const& nodes, DOM::Document& document)
|
||||
{
|
||||
// 1. Let node be null.
|
||||
// 2. Replace each string in nodes with a new Text node whose data is the string and node document is document.
|
||||
|
@ -21,18 +22,18 @@ ExceptionOr<NonnullRefPtr<Node>> convert_nodes_to_single_node(Vector<Variant<Non
|
|||
// 4. Otherwise, set node to a new DocumentFragment node whose node document is document, and then append each node in nodes, if any, to it.
|
||||
// 5. Return node.
|
||||
|
||||
auto potentially_convert_string_to_text_node = [&document](Variant<NonnullRefPtr<Node>, String> const& node) -> NonnullRefPtr<Node> {
|
||||
if (node.has<NonnullRefPtr<Node>>())
|
||||
return node.get<NonnullRefPtr<Node>>();
|
||||
auto potentially_convert_string_to_text_node = [&document](Variant<JS::Handle<Node>, String> const& node) -> JS::NonnullGCPtr<Node> {
|
||||
if (node.has<JS::Handle<Node>>())
|
||||
return *node.get<JS::Handle<Node>>();
|
||||
|
||||
return adopt_ref(*new Text(document, node.get<String>()));
|
||||
return *document.heap().allocate<DOM::Text>(document.realm(), document, node.get<String>());
|
||||
};
|
||||
|
||||
if (nodes.size() == 1)
|
||||
return potentially_convert_string_to_text_node(nodes.first());
|
||||
|
||||
// This is NNRP<Node> instead of NNRP<DocumentFragment> to be compatible with the return type.
|
||||
NonnullRefPtr<Node> document_fragment = adopt_ref(*new DocumentFragment(document));
|
||||
// This is NNGCP<Node> instead of NNGCP<DocumentFragment> to be compatible with the return type.
|
||||
JS::NonnullGCPtr<Node> document_fragment = *document.heap().allocate<DOM::DocumentFragment>(document.realm(), document);
|
||||
for (auto& unconverted_node : nodes) {
|
||||
auto node = potentially_convert_string_to_text_node(unconverted_node);
|
||||
(void)TRY(document_fragment->append_child(node));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue