1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:57: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

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSConditionRulePrototype.h>
#include <LibWeb/CSS/CSSConditionRule.h>
#include <LibWeb/HTML/Window.h>
@ -14,7 +13,7 @@ namespace Web::CSS {
CSSConditionRule::CSSConditionRule(HTML::Window& window_object, CSSRuleList& rules)
: CSSGroupingRule(window_object, rules)
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSConditionRulePrototype>("CSSConditionRule"));
set_prototype(&window_object.cached_web_prototype("CSSConditionRule"));
}
void CSSConditionRule::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSFontFaceRulePrototype.h>
#include <LibWeb/CSS/CSSFontFaceRule.h>
#include <LibWeb/HTML/Window.h>
@ -20,7 +19,7 @@ CSSFontFaceRule::CSSFontFaceRule(HTML::Window& window_object, FontFace&& font_fa
: CSSRule(window_object)
, m_font_face(move(font_face))
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSFontFaceRulePrototype>("CSSFontFaceRule"));
set_prototype(&window_object.cached_web_prototype("CSSFontFaceRule"));
}
CSSStyleDeclaration* CSSFontFaceRule::style()

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSGroupingRulePrototype.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/CSSGroupingRule.h>
#include <LibWeb/CSS/CSSRuleList.h>
@ -17,7 +16,7 @@ CSSGroupingRule::CSSGroupingRule(HTML::Window& window_object, CSSRuleList& rules
: CSSRule(window_object)
, m_rules(rules)
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSGroupingRulePrototype>("CSSGroupingRule"));
set_prototype(&window_object.cached_web_prototype("CSSGroupingRule"));
for (auto& rule : m_rules)
rule.set_parent_rule(this);
}

View file

@ -8,7 +8,6 @@
#include <AK/Debug.h>
#include <AK/URL.h>
#include <LibWeb/Bindings/CSSImportRulePrototype.h>
#include <LibWeb/CSS/CSSImportRule.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h>
@ -28,7 +27,7 @@ CSSImportRule::CSSImportRule(AK::URL url, DOM::Document& document)
, m_url(move(url))
, m_document(document)
{
set_prototype(&document.window().ensure_web_prototype<Bindings::CSSImportRulePrototype>("CSSImportRule"));
set_prototype(&document.window().cached_web_prototype("CSSImportRule"));
dbgln_if(CSS_LOADER_DEBUG, "CSSImportRule: Loading import URL: {}", m_url);
auto request = LoadRequest::create_for_url_on_page(m_url, document.page());

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSMediaRulePrototype.h>
#include <LibWeb/CSS/CSSMediaRule.h>
#include <LibWeb/HTML/Window.h>
@ -20,7 +19,7 @@ CSSMediaRule::CSSMediaRule(HTML::Window& window_object, MediaList& media, CSSRul
: CSSConditionRule(window_object, rules)
, m_media(media)
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSMediaRulePrototype>("CSSMediaRule"));
set_prototype(&window_object.cached_web_prototype("CSSMediaRule"));
}
void CSSMediaRule::visit_edges(Cell::Visitor& visitor)

View file

@ -6,7 +6,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSRulePrototype.h>
#include <LibWeb/CSS/CSSRule.h>
#include <LibWeb/CSS/CSSStyleSheet.h>
#include <LibWeb/HTML/Window.h>
@ -14,7 +13,7 @@
namespace Web::CSS {
CSSRule::CSSRule(HTML::Window& window_object)
: PlatformObject(window_object.ensure_web_prototype<Bindings::CSSRulePrototype>("CSSRule"))
: PlatformObject(window_object.cached_web_prototype("CSSRule"))
{
}

View file

@ -5,7 +5,6 @@
*/
#include <AK/TypeCasts.h>
#include <LibWeb/Bindings/CSSRuleListPrototype.h>
#include <LibWeb/CSS/CSSImportRule.h>
#include <LibWeb/CSS/CSSMediaRule.h>
#include <LibWeb/CSS/CSSRule.h>
@ -25,7 +24,7 @@ CSSRuleList* CSSRuleList::create(HTML::Window& window_object, JS::MarkedVector<C
}
CSSRuleList::CSSRuleList(HTML::Window& window_object)
: Bindings::LegacyPlatformObject(window_object.ensure_web_prototype<Bindings::CSSRuleListPrototype>("CSSRuleList"))
: Bindings::LegacyPlatformObject(window_object.cached_web_prototype("CSSRuleList"))
{
}

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSStyleDeclarationPrototype.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h>
@ -14,7 +13,7 @@
namespace Web::CSS {
CSSStyleDeclaration::CSSStyleDeclaration(HTML::Window& window_object)
: PlatformObject(window_object.ensure_web_prototype<Bindings::CSSStyleDeclarationPrototype>("CSSStyleDeclaration"))
: PlatformObject(window_object.cached_web_prototype("CSSStyleDeclaration"))
{
}

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSStyleRulePrototype.h>
#include <LibWeb/CSS/CSSStyleRule.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/HTML/Window.h>
@ -21,7 +20,7 @@ CSSStyleRule::CSSStyleRule(HTML::Window& window_object, NonnullRefPtrVector<Sele
, m_selectors(move(selectors))
, m_declaration(declaration)
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSStyleRulePrototype>("CSSStyleRule"));
set_prototype(&window_object.cached_web_prototype("CSSStyleRule"));
}
void CSSStyleRule::visit_edges(Cell::Visitor& visitor)

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSStyleSheetPrototype.h>
#include <LibWeb/CSS/CSSStyleSheet.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/StyleSheetList.h>
@ -22,7 +21,7 @@ CSSStyleSheet::CSSStyleSheet(HTML::Window& window_object, CSSRuleList& rules, Op
: StyleSheet(window_object)
, m_rules(&rules)
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSStyleSheetPrototype>("CSSStyleSheet"));
set_prototype(&window_object.cached_web_prototype("CSSStyleSheet"));
if (location.has_value())
set_location(location->to_string());

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSSupportsRulePrototype.h>
#include <LibWeb/CSS/CSSSupportsRule.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/HTML/Window.h>
@ -20,7 +19,7 @@ CSSSupportsRule::CSSSupportsRule(HTML::Window& window_object, NonnullRefPtr<Supp
: CSSConditionRule(window_object, rules)
, m_supports(move(supports))
{
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSSupportsRulePrototype>("CSSSupportsRule"));
set_prototype(&window_object.cached_web_prototype("CSSSupportsRule"));
}
String CSSSupportsRule::condition_text() const

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/MediaListPrototype.h>
#include <LibWeb/CSS/MediaList.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/HTML/Window.h>
@ -18,7 +17,7 @@ MediaList* MediaList::create(HTML::Window& window_object, NonnullRefPtrVector<Me
}
MediaList::MediaList(HTML::Window& window_object, NonnullRefPtrVector<MediaQuery>&& media)
: Bindings::LegacyPlatformObject(window_object.ensure_web_prototype<Bindings::MediaListPrototype>("MediaList"))
: Bindings::LegacyPlatformObject(window_object.cached_web_prototype("MediaList"))
, m_media(move(media))
{
}

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/MediaQueryListPrototype.h>
#include <LibWeb/CSS/MediaQueryList.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/EventDispatcher.h>
@ -24,7 +23,7 @@ MediaQueryList::MediaQueryList(DOM::Document& document, NonnullRefPtrVector<Medi
, m_document(document)
, m_media(move(media))
{
set_prototype(&document.window().ensure_web_prototype<Bindings::MediaQueryListPrototype>("MediaQueryList"));
set_prototype(&document.window().cached_web_prototype("MediaQueryList"));
evaluate();
}

View file

@ -25,7 +25,7 @@ MediaQueryListEvent::MediaQueryListEvent(HTML::Window& window_object, FlyString
, m_media(event_init.media)
, m_matches(event_init.matches)
{
set_prototype(&window_object.ensure_web_prototype<Bindings::MediaQueryListEventPrototype>("MediaQueryListEvent"));
set_prototype(&window_object.cached_web_prototype("MediaQueryListEvent"));
}
MediaQueryListEvent::~MediaQueryListEvent() = default;

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/StyleSheetPrototype.h>
#include <LibWeb/CSS/CSSStyleSheet.h>
#include <LibWeb/CSS/StyleSheet.h>
#include <LibWeb/DOM/Element.h>
@ -14,7 +13,7 @@
namespace Web::CSS {
StyleSheet::StyleSheet(HTML::Window& window_object)
: PlatformObject(window_object.ensure_web_prototype<Bindings::StyleSheetPrototype>("StyleSheet"))
: PlatformObject(window_object.cached_web_prototype("StyleSheet"))
{
}

View file

@ -36,7 +36,7 @@ StyleSheetList* StyleSheetList::create(DOM::Document& document)
}
StyleSheetList::StyleSheetList(DOM::Document& document)
: Bindings::LegacyPlatformObject(document.window().ensure_web_prototype<Bindings::StyleSheetListPrototype>("StyleSheetList"))
: Bindings::LegacyPlatformObject(document.window().cached_web_prototype("StyleSheetList"))
, m_document(document)
{
}