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

LibWeb: Use cached_web_prototype() as much as possible

Unlike ensure_web_prototype<T>(), the cached version doesn't require the
prototype type to be fully formed, so we can use it without including
the FooPrototype.h header. It's also a bit less verbose. :^)
This commit is contained in:
Andreas Kling 2022-09-03 18:43:24 +02:00
parent a85542958c
commit ffad902c07
165 changed files with 176 additions and 325 deletions

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/AbortControllerPrototype.h>
#include <LibWeb/DOM/AbortController.h>
#include <LibWeb/DOM/AbortSignal.h>
@ -21,7 +20,7 @@ AbortController::AbortController(HTML::Window& window, JS::NonnullGCPtr<AbortSig
: PlatformObject(window.realm())
, m_signal(move(signal))
{
set_prototype(&window.ensure_web_prototype<Bindings::AbortControllerPrototype>("AbortController"));
set_prototype(&window.cached_web_prototype("AbortController"));
}
AbortController::~AbortController() = default;

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/AbstractRangePrototype.h>
#include <LibWeb/DOM/AbstractRange.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Window.h>
@ -12,7 +11,7 @@
namespace Web::DOM {
AbstractRange::AbstractRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset)
: Bindings::PlatformObject(start_container.document().window().ensure_web_prototype<Bindings::AbstractRangePrototype>("AbstractRange"))
: Bindings::PlatformObject(start_container.document().window().cached_web_prototype("AbstractRange"))
, m_start_container(start_container)
, m_start_offset(start_offset)
, m_end_container(end_container)

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/AttributePrototype.h>
#include <LibWeb/DOM/Attribute.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
@ -24,7 +23,7 @@ Attribute::Attribute(Document& document, FlyString local_name, String value, Ele
, m_value(move(value))
, m_owner_element(owner_element)
{
set_prototype(&window().ensure_web_prototype<Bindings::AttributePrototype>("Attribute"));
set_prototype(&window().cached_web_prototype("Attribute"));
}
void Attribute::visit_edges(Cell::Visitor& visitor)

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CDATASectionPrototype.h>
#include <LibWeb/DOM/CDATASection.h>
#include <LibWeb/HTML/Window.h>
@ -13,7 +12,7 @@ namespace Web::DOM {
CDATASection::CDATASection(Document& document, String const& data)
: Text(document, NodeType::CDATA_SECTION_NODE, data)
{
set_prototype(&window().ensure_web_prototype<Bindings::CDATASectionPrototype>("CDATASection"));
set_prototype(&window().cached_web_prototype("CDATASection"));
}
CDATASection::~CDATASection() = default;

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CustomEventPrototype.h>
#include <LibWeb/DOM/CustomEvent.h>
#include <LibWeb/HTML/Window.h>
@ -24,14 +23,14 @@ CustomEvent* CustomEvent::create_with_global_object(HTML::Window& window_object,
CustomEvent::CustomEvent(HTML::Window& window_object, FlyString const& event_name)
: Event(window_object, event_name)
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CustomEventPrototype>("CustomEvent"));
set_prototype(&window_object.cached_web_prototype("CustomEvent"));
}
CustomEvent::CustomEvent(HTML::Window& window_object, FlyString const& event_name, CustomEventInit const& event_init)
: Event(window_object, event_name, event_init)
, m_detail(event_init.detail)
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CustomEventPrototype>("CustomEvent"));
set_prototype(&window_object.cached_web_prototype("CustomEvent"));
}
CustomEvent::~CustomEvent() = default;

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/DOMImplementationPrototype.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/DOM/DOMImplementation.h>
#include <LibWeb/DOM/Document.h>
@ -25,7 +24,7 @@ JS::NonnullGCPtr<DOMImplementation> DOMImplementation::create(Document& document
}
DOMImplementation::DOMImplementation(Document& document)
: PlatformObject(document.window().ensure_web_prototype<Bindings::DOMImplementationPrototype>("DOMImplementation"))
: PlatformObject(document.window().cached_web_prototype("DOMImplementation"))
, m_document(document)
{
}

View file

@ -7,7 +7,6 @@
#include <AK/CharacterTypes.h>
#include <AK/StringBuilder.h>
#include <LibWeb/Bindings/DOMTokenListPrototype.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/DOMTokenList.h>
#include <LibWeb/DOM/Document.h>
@ -62,7 +61,7 @@ DOMTokenList* DOMTokenList::create(Element const& associated_element, FlyString
// https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A2
DOMTokenList::DOMTokenList(Element const& associated_element, FlyString associated_attribute)
: Bindings::LegacyPlatformObject(associated_element.document().window().ensure_web_prototype<Bindings::DOMTokenListPrototype>("DOMTokenList"))
: Bindings::LegacyPlatformObject(associated_element.window().cached_web_prototype("DOMTokenList"))
, m_associated_element(associated_element)
, m_associated_attribute(move(associated_attribute))
{

View file

@ -14,7 +14,6 @@
#include <LibJS/Interpreter.h>
#include <LibJS/Parser.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibWeb/Bindings/DocumentPrototype.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/MediaQueryList.h>
#include <LibWeb/CSS/MediaQueryListEvent.h>
@ -283,7 +282,7 @@ Document::Document(HTML::Window& window, const AK::URL& url)
, m_url(url)
, m_window(window)
{
set_prototype(&window.ensure_web_prototype<Bindings::DocumentPrototype>("Document"));
set_prototype(&window.cached_web_prototype("Document"));
HTML::main_thread_event_loop().register_document({}, *this);

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/DocumentFragmentPrototype.h>
#include <LibWeb/DOM/DocumentFragment.h>
#include <LibWeb/HTML/Window.h>
@ -13,7 +12,7 @@ namespace Web::DOM {
DocumentFragment::DocumentFragment(Document& document)
: ParentNode(document, NodeType::DOCUMENT_FRAGMENT_NODE)
{
set_prototype(&window().ensure_web_prototype<Bindings::DocumentFragmentPrototype>("DocumentFragment"));
set_prototype(&window().cached_web_prototype("DocumentFragment"));
}
void DocumentFragment::visit_edges(Cell::Visitor& visitor)

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/DocumentTypePrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentType.h>
@ -18,7 +17,7 @@ JS::NonnullGCPtr<DocumentType> DocumentType::create(Document& document)
DocumentType::DocumentType(Document& document)
: Node(document, NodeType::DOCUMENT_TYPE_NODE)
{
set_prototype(&window().ensure_web_prototype<Bindings::DocumentTypePrototype>("DocumentType"));
set_prototype(&window().cached_web_prototype("DocumentType"));
}
}

View file

@ -8,7 +8,6 @@
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
#include <AK/StringBuilder.h>
#include <LibWeb/Bindings/ElementPrototype.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
@ -48,8 +47,7 @@ Element::Element(Document& document, DOM::QualifiedName qualified_name)
, m_qualified_name(move(qualified_name))
, m_attributes(NamedNodeMap::create(*this))
{
set_prototype(&document.window().ensure_web_prototype<Bindings::ElementPrototype>("Element"));
set_prototype(&window().cached_web_prototype("Element"));
make_html_uppercased_qualified_name();
}

View file

@ -7,7 +7,6 @@
*/
#include <AK/TypeCasts.h>
#include <LibWeb/Bindings/EventPrototype.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/ShadowRoot.h>
@ -25,15 +24,15 @@ JS::NonnullGCPtr<Event> Event::create_with_global_object(HTML::Window& window_ob
return create(window_object, event_name, event_init);
}
Event::Event(HTML::Window& window_object, FlyString const& type)
: PlatformObject(window_object.ensure_web_prototype<Bindings::EventPrototype>("Event"))
Event::Event(HTML::Window& window, FlyString const& type)
: PlatformObject(window.cached_web_prototype("Event"))
, m_type(type)
, m_initialized(true)
{
}
Event::Event(HTML::Window& window_object, FlyString const& type, EventInit const& event_init)
: PlatformObject(window_object.ensure_web_prototype<Bindings::EventPrototype>("Event"))
Event::Event(HTML::Window& window, FlyString const& type, EventInit const& event_init)
: PlatformObject(window.cached_web_prototype("Event"))
, m_type(type)
, m_bubbles(event_init.bubbles)
, m_cancelable(event_init.cancelable)

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/HTMLCollectionPrototype.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/ParentNode.h>
@ -20,7 +19,7 @@ JS::NonnullGCPtr<HTMLCollection> HTMLCollection::create(ParentNode& root, Functi
}
HTMLCollection::HTMLCollection(ParentNode& root, Function<bool(Element const&)> filter)
: LegacyPlatformObject(root.window().ensure_web_prototype<Bindings::HTMLCollectionPrototype>("HTMLCollection"))
: LegacyPlatformObject(root.window().cached_web_prototype("HTMLCollection"))
, m_root(root)
, m_filter(move(filter))
{

View file

@ -5,7 +5,6 @@
*/
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Bindings/MutationObserverPrototype.h>
#include <LibWeb/DOM/MutationObserver.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/HTML/Window.h>
@ -22,7 +21,7 @@ MutationObserver::MutationObserver(HTML::Window& window, JS::GCPtr<Bindings::Cal
: PlatformObject(window.realm())
, m_callback(move(callback))
{
set_prototype(&window.ensure_web_prototype<Bindings::MutationObserverPrototype>("MutationObserver"));
set_prototype(&window.cached_web_prototype("MutationObserver"));
// 1. Set thiss callback to callback.

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/MutationRecordPrototype.h>
#include <LibWeb/DOM/MutationRecord.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/NodeList.h>
@ -30,7 +29,7 @@ MutationRecord::MutationRecord(HTML::Window& window, FlyString const& type, Node
, m_attribute_namespace(attribute_namespace)
, m_old_value(old_value)
{
set_prototype(&window.ensure_web_prototype<Bindings::MutationRecordPrototype>("MutationRecord"));
set_prototype(&window.cached_web_prototype("MutationRecord"));
}
MutationRecord::~MutationRecord() = default;

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/NamedNodeMapPrototype.h>
#include <LibWeb/DOM/Attribute.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/NamedNodeMap.h>
@ -20,7 +19,7 @@ JS::NonnullGCPtr<NamedNodeMap> NamedNodeMap::create(Element& element)
}
NamedNodeMap::NamedNodeMap(Element& element)
: Bindings::LegacyPlatformObject(element.document().window().ensure_web_prototype<Bindings::NamedNodeMapPrototype>("NamedNodeMap"))
: Bindings::LegacyPlatformObject(element.window().cached_web_prototype("NamedNodeMap"))
, m_element(element)
{
}

View file

@ -6,7 +6,6 @@
#include <LibWeb/Bindings/DOMExceptionWrapper.h>
#include <LibWeb/Bindings/IDLAbstractOperations.h>
#include <LibWeb/Bindings/NodeIteratorPrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/NodeIterator.h>
@ -14,7 +13,7 @@
namespace Web::DOM {
NodeIterator::NodeIterator(Node& root)
: PlatformObject(root.document().window().ensure_web_prototype<Bindings::NodeIteratorPrototype>("NodeIterator"))
: PlatformObject(root.window().cached_web_prototype("NodeIterator"))
, m_root(root)
, m_reference({ root })
{

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/NodeListPrototype.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/NodeList.h>
#include <LibWeb/HTML/Window.h>
@ -12,7 +11,7 @@
namespace Web::DOM {
NodeList::NodeList(HTML::Window& window)
: LegacyPlatformObject(window.ensure_web_prototype<Bindings::NodeListPrototype>("NodeList"))
: LegacyPlatformObject(window.cached_web_prototype("NodeList"))
{
}

View file

@ -6,7 +6,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/RangePrototype.h>
#include <LibWeb/DOM/Comment.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentFragment.h>
@ -50,13 +49,13 @@ JS::NonnullGCPtr<Range> Range::create_with_global_object(HTML::Window& window)
Range::Range(Document& document)
: Range(document, 0, document, 0)
{
set_prototype(&document.window().ensure_web_prototype<Bindings::RangePrototype>("Range"));
set_prototype(&document.window().cached_web_prototype("Range"));
}
Range::Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset)
: AbstractRange(start_container, start_offset, end_container, end_offset)
{
set_prototype(&start_container.document().window().ensure_web_prototype<Bindings::RangePrototype>("Range"));
set_prototype(&start_container.window().cached_web_prototype("Range"));
live_ranges().set(this);
}

View file

@ -6,7 +6,6 @@
*/
#include <AK/TypeCasts.h>
#include <LibWeb/Bindings/StaticRangePrototype.h>
#include <LibWeb/DOM/Attribute.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentType.h>
@ -18,7 +17,7 @@ namespace Web::DOM {
StaticRange::StaticRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset)
: AbstractRange(start_container, start_offset, end_container, end_offset)
{
set_prototype(&start_container.document().window().ensure_web_prototype<Bindings::StaticRangePrototype>("StaticRange"));
set_prototype(&start_container.document().window().cached_web_prototype("StaticRange"));
}
StaticRange::~StaticRange() = default;

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/TextPrototype.h>
#include <LibWeb/DOM/Range.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/HTMLInputElement.h>
@ -16,13 +15,13 @@ namespace Web::DOM {
Text::Text(Document& document, String const& data)
: CharacterData(document, NodeType::TEXT_NODE, data)
{
set_prototype(&window().ensure_web_prototype<Bindings::TextPrototype>("Text"));
set_prototype(&window().cached_web_prototype("Text"));
}
Text::Text(Document& document, NodeType type, String const& data)
: CharacterData(document, type, data)
{
set_prototype(&window().ensure_web_prototype<Bindings::TextPrototype>("Text"));
set_prototype(&window().cached_web_prototype("Text"));
}
void Text::visit_edges(Cell::Visitor& visitor)

View file

@ -6,7 +6,6 @@
#include <LibWeb/Bindings/DOMExceptionWrapper.h>
#include <LibWeb/Bindings/IDLAbstractOperations.h>
#include <LibWeb/Bindings/TreeWalkerPrototype.h>
#include <LibWeb/Bindings/Wrapper.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/Document.h>
@ -17,7 +16,7 @@
namespace Web::DOM {
TreeWalker::TreeWalker(Node& root)
: PlatformObject(root.document().window().ensure_web_prototype<Bindings::TreeWalkerPrototype>("TreeWalker"))
: PlatformObject(root.window().cached_web_prototype("TreeWalker"))
, m_root(root)
, m_current(root)
{