mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:47:45 +00:00
LibWeb: Move passing of Web object prototypes out of constructors
This commit is contained in:
parent
834202aeb9
commit
af75493883
35 changed files with 157 additions and 23 deletions
|
@ -11,7 +11,7 @@
|
|||
namespace Web::DOM {
|
||||
|
||||
AbstractRange::AbstractRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset)
|
||||
: Bindings::PlatformObject(Bindings::cached_web_prototype(start_container.realm(), "AbstractRange"))
|
||||
: Bindings::PlatformObject(start_container.realm())
|
||||
, m_start_container(start_container)
|
||||
, m_start_offset(start_offset)
|
||||
, m_end_container(end_container)
|
||||
|
@ -21,6 +21,12 @@ AbstractRange::AbstractRange(Node& start_container, u32 start_offset, Node& end_
|
|||
|
||||
AbstractRange::~AbstractRange() = default;
|
||||
|
||||
void AbstractRange::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::AbstractRangePrototype>(realm, "AbstractRange"));
|
||||
}
|
||||
|
||||
void AbstractRange::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
protected:
|
||||
AbstractRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
JS::NonnullGCPtr<Node> m_start_container;
|
||||
|
|
|
@ -24,13 +24,19 @@ JS::NonnullGCPtr<DOMImplementation> DOMImplementation::create(Document& document
|
|||
}
|
||||
|
||||
DOMImplementation::DOMImplementation(Document& document)
|
||||
: PlatformObject(Bindings::cached_web_prototype(document.realm(), "DOMImplementation"))
|
||||
: PlatformObject(document.realm())
|
||||
, m_document(document)
|
||||
{
|
||||
}
|
||||
|
||||
DOMImplementation::~DOMImplementation() = default;
|
||||
|
||||
void DOMImplementation::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMImplementationPrototype>(realm, "DOMImplementation"));
|
||||
}
|
||||
|
||||
void DOMImplementation::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
private:
|
||||
explicit DOMImplementation(Document&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Document& document() { return m_document; }
|
||||
|
|
|
@ -60,7 +60,7 @@ DOMTokenList* DOMTokenList::create(Element const& associated_element, Deprecated
|
|||
|
||||
// https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A2
|
||||
DOMTokenList::DOMTokenList(Element const& associated_element, DeprecatedFlyString associated_attribute)
|
||||
: Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(associated_element.realm(), "DOMTokenList"))
|
||||
: Bindings::LegacyPlatformObject(associated_element.realm())
|
||||
, m_associated_element(associated_element)
|
||||
, m_associated_attribute(move(associated_attribute))
|
||||
{
|
||||
|
@ -68,6 +68,12 @@ DOMTokenList::DOMTokenList(Element const& associated_element, DeprecatedFlyStrin
|
|||
associated_attribute_changed(value);
|
||||
}
|
||||
|
||||
void DOMTokenList::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMTokenListPrototype>(realm, "DOMTokenList"));
|
||||
}
|
||||
|
||||
void DOMTokenList::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
private:
|
||||
DOMTokenList(Element const& associated_element, DeprecatedFlyString associated_attribute);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
WebIDL::ExceptionOr<void> validate_token(StringView token) const;
|
||||
|
|
|
@ -25,14 +25,14 @@ JS::NonnullGCPtr<Event> Event::construct_impl(JS::Realm& realm, DeprecatedFlyStr
|
|||
}
|
||||
|
||||
Event::Event(JS::Realm& realm, DeprecatedFlyString const& type)
|
||||
: PlatformObject(Bindings::cached_web_prototype(realm, "Event"))
|
||||
: PlatformObject(realm)
|
||||
, m_type(type)
|
||||
, m_initialized(true)
|
||||
{
|
||||
}
|
||||
|
||||
Event::Event(JS::Realm& realm, DeprecatedFlyString const& type, EventInit const& event_init)
|
||||
: PlatformObject(Bindings::cached_web_prototype(realm, "Event"))
|
||||
: PlatformObject(realm)
|
||||
, m_type(type)
|
||||
, m_bubbles(event_init.bubbles)
|
||||
, m_cancelable(event_init.cancelable)
|
||||
|
@ -41,6 +41,12 @@ Event::Event(JS::Realm& realm, DeprecatedFlyString const& type, EventInit const&
|
|||
{
|
||||
}
|
||||
|
||||
void Event::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::EventPrototype>(realm, "Event"));
|
||||
}
|
||||
|
||||
void Event::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -145,6 +145,8 @@ public:
|
|||
|
||||
protected:
|
||||
void initialize_event(DeprecatedString const&, bool, bool);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -19,7 +19,7 @@ JS::NonnullGCPtr<HTMLCollection> HTMLCollection::create(ParentNode& root, Functi
|
|||
}
|
||||
|
||||
HTMLCollection::HTMLCollection(ParentNode& root, Function<bool(Element const&)> filter)
|
||||
: LegacyPlatformObject(Bindings::cached_web_prototype(root.realm(), "HTMLCollection"))
|
||||
: LegacyPlatformObject(root.realm())
|
||||
, m_root(root)
|
||||
, m_filter(move(filter))
|
||||
{
|
||||
|
@ -27,6 +27,12 @@ HTMLCollection::HTMLCollection(ParentNode& root, Function<bool(Element const&)>
|
|||
|
||||
HTMLCollection::~HTMLCollection() = default;
|
||||
|
||||
void HTMLCollection::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLCollectionPrototype>(realm, "HTMLCollection"));
|
||||
}
|
||||
|
||||
void HTMLCollection::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
protected:
|
||||
HTMLCollection(ParentNode& root, Function<bool(Element const&)> filter);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
JS::NonnullGCPtr<ParentNode> root() { return *m_root; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -20,11 +20,17 @@ JS::NonnullGCPtr<NamedNodeMap> NamedNodeMap::create(Element& element)
|
|||
}
|
||||
|
||||
NamedNodeMap::NamedNodeMap(Element& element)
|
||||
: Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(element.realm(), "NamedNodeMap"))
|
||||
: Bindings::LegacyPlatformObject(element.realm())
|
||||
, m_element(element)
|
||||
{
|
||||
}
|
||||
|
||||
void NamedNodeMap::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::NamedNodeMapPrototype>(realm, "NamedNodeMap"));
|
||||
}
|
||||
|
||||
void NamedNodeMap::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
private:
|
||||
explicit NamedNodeMap(Element&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Element& associated_element() { return *m_element; }
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Web::DOM {
|
||||
|
||||
NodeIterator::NodeIterator(Node& root)
|
||||
: PlatformObject(Bindings::cached_web_prototype(root.realm(), "NodeIterator"))
|
||||
: PlatformObject(root.realm())
|
||||
, m_root(root)
|
||||
, m_reference({ root })
|
||||
{
|
||||
|
@ -21,6 +21,12 @@ NodeIterator::NodeIterator(Node& root)
|
|||
|
||||
NodeIterator::~NodeIterator() = default;
|
||||
|
||||
void NodeIterator::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::NodeIteratorPrototype>(realm, "NodeIterator"));
|
||||
}
|
||||
|
||||
void NodeIterator::finalize()
|
||||
{
|
||||
Base::finalize();
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
private:
|
||||
explicit NodeIterator(Node& root);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
virtual void finalize() override;
|
||||
|
||||
|
|
|
@ -11,12 +11,18 @@
|
|||
namespace Web::DOM {
|
||||
|
||||
NodeList::NodeList(JS::Realm& realm)
|
||||
: LegacyPlatformObject(Bindings::cached_web_prototype(realm, "NodeList"))
|
||||
: LegacyPlatformObject(realm)
|
||||
{
|
||||
}
|
||||
|
||||
NodeList::~NodeList() = default;
|
||||
|
||||
void NodeList::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::NodeListPrototype>(realm, "NodeList"));
|
||||
}
|
||||
|
||||
JS::Value NodeList::item_value(size_t index) const
|
||||
{
|
||||
auto* node = item(index);
|
||||
|
|
|
@ -26,6 +26,8 @@ public:
|
|||
|
||||
protected:
|
||||
explicit NodeList(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace Web::DOM {
|
||||
|
||||
TreeWalker::TreeWalker(Node& root)
|
||||
: PlatformObject(Bindings::cached_web_prototype(root.realm(), "TreeWalker"))
|
||||
: PlatformObject(root.realm())
|
||||
, m_root(root)
|
||||
, m_current(root)
|
||||
{
|
||||
|
@ -22,6 +22,12 @@ TreeWalker::TreeWalker(Node& root)
|
|||
|
||||
TreeWalker::~TreeWalker() = default;
|
||||
|
||||
void TreeWalker::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::TreeWalkerPrototype>(realm, "TreeWalker"));
|
||||
}
|
||||
|
||||
void TreeWalker::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
private:
|
||||
explicit TreeWalker(Node& root);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
enum class ChildTraversalType {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue