mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:27:43 +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
|
@ -12,27 +12,29 @@
|
|||
namespace Web::DOMParsing {
|
||||
|
||||
// https://w3c.github.io/DOM-Parsing/#dfn-fragment-parsing-algorithm
|
||||
static DOM::ExceptionOr<NonnullRefPtr<DOM::DocumentFragment>> parse_fragment(String const& markup, DOM::Element& context_element)
|
||||
static DOM::ExceptionOr<JS::NonnullGCPtr<DOM::DocumentFragment>> parse_fragment(String const& markup, DOM::Element& context_element)
|
||||
{
|
||||
// FIXME: Handle XML documents.
|
||||
|
||||
auto& realm = context_element.realm();
|
||||
|
||||
auto new_children = HTML::HTMLParser::parse_html_fragment(context_element, markup);
|
||||
auto fragment = make_ref_counted<DOM::DocumentFragment>(context_element.document());
|
||||
auto fragment = realm.heap().allocate<DOM::DocumentFragment>(realm, context_element.document());
|
||||
|
||||
for (auto& child : new_children) {
|
||||
// I don't know if this can throw here, but let's be safe.
|
||||
(void)TRY(fragment->append_child(child));
|
||||
(void)TRY(fragment->append_child(*child));
|
||||
}
|
||||
|
||||
return fragment;
|
||||
return JS::NonnullGCPtr(*fragment);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
|
||||
DOM::ExceptionOr<void> inner_html_setter(NonnullRefPtr<DOM::Node> context_object, String const& value)
|
||||
DOM::ExceptionOr<void> inner_html_setter(JS::NonnullGCPtr<DOM::Node> context_object, String const& value)
|
||||
{
|
||||
// 1. Let context element be the context object's host if the context object is a ShadowRoot object, or the context object otherwise.
|
||||
// (This is handled in Element and ShadowRoot)
|
||||
NonnullRefPtr<DOM::Element> context_element = is<DOM::ShadowRoot>(*context_object) ? *verify_cast<DOM::ShadowRoot>(*context_object).host() : verify_cast<DOM::Element>(*context_object);
|
||||
JS::NonnullGCPtr<DOM::Element> context_element = is<DOM::ShadowRoot>(*context_object) ? *verify_cast<DOM::ShadowRoot>(*context_object).host() : verify_cast<DOM::Element>(*context_object);
|
||||
|
||||
// 2. Let fragment be the result of invoking the fragment parsing algorithm with the new value as markup, and with context element.
|
||||
auto fragment = TRY(parse_fragment(value, context_element));
|
||||
|
|
|
@ -14,6 +14,6 @@
|
|||
namespace Web::DOMParsing {
|
||||
|
||||
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
|
||||
DOM::ExceptionOr<void> inner_html_setter(NonnullRefPtr<DOM::Node> context_object, String const& value);
|
||||
DOM::ExceptionOr<void> inner_html_setter(JS::NonnullGCPtr<DOM::Node> context_object, String const& value);
|
||||
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ XMLSerializer::XMLSerializer() = default;
|
|||
XMLSerializer::~XMLSerializer() = default;
|
||||
|
||||
// https://w3c.github.io/DOM-Parsing/#dom-xmlserializer-serializetostring
|
||||
DOM::ExceptionOr<String> XMLSerializer::serialize_to_string(NonnullRefPtr<DOM::Node> root)
|
||||
DOM::ExceptionOr<String> XMLSerializer::serialize_to_string(JS::NonnullGCPtr<DOM::Node> root)
|
||||
{
|
||||
// The serializeToString(root) method must produce an XML serialization of root passing a value of false for the require well-formed parameter, and return the result.
|
||||
return serialize_node_to_xml_string(move(root), RequireWellFormed::No);
|
||||
return serialize_node_to_xml_string(root, RequireWellFormed::No);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/DOM-Parsing/#dfn-add
|
||||
|
@ -103,10 +103,10 @@ static bool prefix_is_in_prefix_map(String const& prefix, HashMap<FlyString, Vec
|
|||
return candidates_list_iterator->value.contains_slow(prefix);
|
||||
}
|
||||
|
||||
DOM::ExceptionOr<String> serialize_node_to_xml_string_impl(NonnullRefPtr<DOM::Node> root, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<String>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
|
||||
DOM::ExceptionOr<String> serialize_node_to_xml_string_impl(JS::NonnullGCPtr<DOM::Node> root, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<String>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
|
||||
|
||||
// https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization
|
||||
DOM::ExceptionOr<String> serialize_node_to_xml_string(NonnullRefPtr<DOM::Node> root, RequireWellFormed require_well_formed)
|
||||
DOM::ExceptionOr<String> serialize_node_to_xml_string(JS::NonnullGCPtr<DOM::Node> root, RequireWellFormed require_well_formed)
|
||||
{
|
||||
// 1. Let namespace be a context namespace with value null. The context namespace tracks the XML serialization algorithm's current default namespace.
|
||||
// The context namespace is changed when either an Element Node has a default namespace declaration, or the algorithm generates a default namespace declaration
|
||||
|
@ -139,7 +139,7 @@ static DOM::ExceptionOr<String> serialize_document_type(DOM::DocumentType const&
|
|||
static DOM::ExceptionOr<String> serialize_processing_instruction(DOM::ProcessingInstruction const& processing_instruction, RequireWellFormed require_well_formed);
|
||||
|
||||
// https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization-algorithm
|
||||
DOM::ExceptionOr<String> serialize_node_to_xml_string_impl(NonnullRefPtr<DOM::Node> root, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<String>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
|
||||
DOM::ExceptionOr<String> serialize_node_to_xml_string_impl(JS::NonnullGCPtr<DOM::Node> root, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<String>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
|
||||
{
|
||||
// Each of the following algorithms for producing an XML serialization of a DOM node take as input a node to serialize and the following arguments:
|
||||
// - A context namespace namespace
|
||||
|
@ -155,43 +155,43 @@ DOM::ExceptionOr<String> serialize_node_to_xml_string_impl(NonnullRefPtr<DOM::No
|
|||
if (is<DOM::Element>(*root)) {
|
||||
// -> Element
|
||||
// Run the algorithm for XML serializing an Element node node.
|
||||
return serialize_element(static_ptr_cast<DOM::Element>(root), namespace_, namespace_prefix_map, prefix_index, require_well_formed);
|
||||
return serialize_element(static_cast<DOM::Element&>(*root), namespace_, namespace_prefix_map, prefix_index, require_well_formed);
|
||||
}
|
||||
|
||||
if (is<DOM::Document>(*root)) {
|
||||
// -> Document
|
||||
// Run the algorithm for XML serializing a Document node node.
|
||||
return serialize_document(static_ptr_cast<DOM::Document>(root), namespace_, namespace_prefix_map, prefix_index, require_well_formed);
|
||||
return serialize_document(static_cast<DOM::Document&>(*root), namespace_, namespace_prefix_map, prefix_index, require_well_formed);
|
||||
}
|
||||
|
||||
if (is<DOM::Comment>(*root)) {
|
||||
// -> Comment
|
||||
// Run the algorithm for XML serializing a Comment node node.
|
||||
return serialize_comment(static_ptr_cast<DOM::Comment>(root), require_well_formed);
|
||||
return serialize_comment(static_cast<DOM::Comment&>(*root), require_well_formed);
|
||||
}
|
||||
|
||||
if (is<DOM::Text>(*root) || is<DOM::CDATASection>(*root)) {
|
||||
// -> Text
|
||||
// Run the algorithm for XML serializing a Text node node.
|
||||
return serialize_text(static_ptr_cast<DOM::Text>(root), require_well_formed);
|
||||
return serialize_text(static_cast<DOM::Text&>(*root), require_well_formed);
|
||||
}
|
||||
|
||||
if (is<DOM::DocumentFragment>(*root)) {
|
||||
// -> DocumentFragment
|
||||
// Run the algorithm for XML serializing a DocumentFragment node node.
|
||||
return serialize_document_fragment(static_ptr_cast<DOM::DocumentFragment>(root), namespace_, namespace_prefix_map, prefix_index, require_well_formed);
|
||||
return serialize_document_fragment(static_cast<DOM::DocumentFragment&>(*root), namespace_, namespace_prefix_map, prefix_index, require_well_formed);
|
||||
}
|
||||
|
||||
if (is<DOM::DocumentType>(*root)) {
|
||||
// -> DocumentType
|
||||
// Run the algorithm for XML serializing a DocumentType node node.
|
||||
return serialize_document_type(static_ptr_cast<DOM::DocumentType>(root), require_well_formed);
|
||||
return serialize_document_type(static_cast<DOM::DocumentType&>(*root), require_well_formed);
|
||||
}
|
||||
|
||||
if (is<DOM::ProcessingInstruction>(*root)) {
|
||||
// -> ProcessingInstruction
|
||||
// Run the algorithm for XML serializing a ProcessingInstruction node node.
|
||||
return serialize_processing_instruction(static_ptr_cast<DOM::ProcessingInstruction>(root), require_well_formed);
|
||||
return serialize_processing_instruction(static_cast<DOM::ProcessingInstruction&>(*root), require_well_formed);
|
||||
}
|
||||
|
||||
if (is<DOM::Attribute>(*root)) {
|
||||
|
|
|
@ -18,14 +18,14 @@ class XMLSerializer final
|
|||
public:
|
||||
using WrapperType = Bindings::XMLSerializerWrapper;
|
||||
|
||||
static NonnullRefPtr<XMLSerializer> create_with_global_object(Bindings::WindowObject&)
|
||||
static NonnullRefPtr<XMLSerializer> create_with_global_object(HTML::Window&)
|
||||
{
|
||||
return adopt_ref(*new XMLSerializer());
|
||||
}
|
||||
|
||||
virtual ~XMLSerializer() override;
|
||||
|
||||
DOM::ExceptionOr<String> serialize_to_string(NonnullRefPtr<DOM::Node> root);
|
||||
DOM::ExceptionOr<String> serialize_to_string(JS::NonnullGCPtr<DOM::Node> root);
|
||||
|
||||
private:
|
||||
XMLSerializer();
|
||||
|
@ -36,6 +36,6 @@ enum class RequireWellFormed {
|
|||
Yes,
|
||||
};
|
||||
|
||||
DOM::ExceptionOr<String> serialize_node_to_xml_string(NonnullRefPtr<DOM::Node> root, RequireWellFormed require_well_formed);
|
||||
DOM::ExceptionOr<String> serialize_node_to_xml_string(JS::NonnullGCPtr<DOM::Node> root, RequireWellFormed require_well_formed);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue