1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:17:36 +00:00

LibWeb: Make MutationRecord GC-allocated

This commit is contained in:
Andreas Kling 2022-09-01 17:13:18 +02:00
parent 48e0066371
commit 43ec0f734f
9 changed files with 72 additions and 71 deletions

View file

@ -6,33 +6,44 @@
#pragma once
#include <AK/RefCounted.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::DOM {
// https://dom.spec.whatwg.org/#mutationrecord
// NOTE: This is implemented as a pure virtual interface with the actual implementation in the CPP file to prevent this circular dependency: Node.h -> MutationRecord.h -> MutationObserver.h -> Node.h
// This is also why this uses raw pointers and references, since using (NN)RP requires us to include the templated type, even in a header specifying a function return type.
class MutationRecord
: public RefCounted<MutationRecord>
, public Bindings::Wrappable {
class MutationRecord : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(MutationRecord, Bindings::PlatformObject);
public:
using WrapperType = Bindings::MutationRecordWrapper;
static JS::NonnullGCPtr<MutationRecord> create(HTML::Window&, FlyString const& type, Node& target, NodeList& added_nodes, NodeList& removed_nodes, Node* previous_sibling, Node* next_sibling, String const& attribute_name, String const& attribute_namespace, String const& old_value);
static NonnullRefPtr<MutationRecord> create(FlyString const& type, Node& target, NodeList& added_nodes, NodeList& removed_nodes, Node* previous_sibling, Node* next_sibling, String const& attribute_name, String const& attribute_namespace, String const& old_value);
virtual ~MutationRecord() override;
virtual ~MutationRecord() override = default;
FlyString const& type() const { return m_type; }
Node const* target() const { return m_target; }
NodeList const* added_nodes() const { return m_added_nodes; }
NodeList const* removed_nodes() const { return m_removed_nodes; }
Node const* previous_sibling() const { return m_previous_sibling; }
Node const* next_sibling() const { return m_next_sibling; }
String const& attribute_name() const { return m_attribute_name; }
String const& attribute_namespace() const { return m_attribute_namespace; }
String const& old_value() const { return m_old_value; }
virtual FlyString const& type() const = 0;
virtual Node const* target() const = 0;
virtual NodeList const* added_nodes() const = 0;
virtual NodeList const* removed_nodes() const = 0;
virtual Node const* previous_sibling() const = 0;
virtual Node const* next_sibling() const = 0;
virtual String const& attribute_name() const = 0;
virtual String const& attribute_namespace() const = 0;
virtual String const& old_value() const = 0;
private:
MutationRecord(HTML::Window& window, FlyString const& type, Node& target, NodeList& added_nodes, NodeList& removed_nodes, Node* previous_sibling, Node* next_sibling, String const& attribute_name, String const& attribute_namespace, String const& old_value);
virtual void visit_edges(Cell::Visitor&) override;
FlyString m_type;
JS::GCPtr<Node> m_target;
JS::GCPtr<NodeList> m_added_nodes;
JS::GCPtr<NodeList> m_removed_nodes;
JS::GCPtr<Node> m_previous_sibling;
JS::GCPtr<Node> m_next_sibling;
String m_attribute_name;
String m_attribute_namespace;
String m_old_value;
};
}
WRAPPER_HACK(MutationRecord, Web::DOM)