diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index fc163df6670..59e270c1b27 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -554,14 +554,15 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector) } } -void dump_rule(CSS::CSSRule const& rule) +ErrorOr dump_rule(CSS::CSSRule const& rule) { StringBuilder builder; - dump_rule(builder, rule); + TRY(dump_rule(builder, rule)); dbgln("{}", builder.string_view()); + return {}; } -void dump_rule(StringBuilder& builder, CSS::CSSRule const& rule, int indent_levels) +ErrorOr dump_rule(StringBuilder& builder, CSS::CSSRule const& rule, int indent_levels) { indent(builder, indent_levels); builder.appendff("{}:\n", rule.class_name()); @@ -574,15 +575,16 @@ void dump_rule(StringBuilder& builder, CSS::CSSRule const& rule, int indent_leve dump_import_rule(builder, verify_cast(rule), indent_levels); break; case CSS::CSSRule::Type::Media: - dump_media_rule(builder, verify_cast(rule), indent_levels); + TRY(dump_media_rule(builder, verify_cast(rule), indent_levels)); break; case CSS::CSSRule::Type::Style: - dump_style_rule(builder, verify_cast(rule), indent_levels); + TRY(dump_style_rule(builder, verify_cast(rule), indent_levels)); break; case CSS::CSSRule::Type::Supports: - dump_supports_rule(builder, verify_cast(rule), indent_levels); + TRY(dump_supports_rule(builder, verify_cast(rule), indent_levels)); break; } + return {}; } void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rule, int indent_levels) @@ -612,27 +614,27 @@ void dump_import_rule(StringBuilder& builder, CSS::CSSImportRule const& rule, in builder.appendff(" Document URL: {}\n", rule.url()); } -void dump_media_rule(StringBuilder& builder, CSS::CSSMediaRule const& media, int indent_levels) +ErrorOr dump_media_rule(StringBuilder& builder, CSS::CSSMediaRule const& media, int indent_levels) { indent(builder, indent_levels); builder.appendff(" Media: {}\n Rules ({}):\n", media.condition_text(), media.css_rules().length()); - for (auto& rule : media.css_rules()) { - dump_rule(builder, rule, indent_levels + 1); - } + for (auto& rule : media.css_rules()) + TRY(dump_rule(builder, rule, indent_levels + 1)); + return {}; } -void dump_supports_rule(StringBuilder& builder, CSS::CSSSupportsRule const& supports, int indent_levels) +ErrorOr dump_supports_rule(StringBuilder& builder, CSS::CSSSupportsRule const& supports, int indent_levels) { indent(builder, indent_levels); builder.appendff(" Supports: {}\n Rules ({}):\n", supports.condition_text(), supports.css_rules().length()); - for (auto& rule : supports.css_rules()) { - dump_rule(builder, rule, indent_levels + 1); - } + for (auto& rule : supports.css_rules()) + TRY(dump_rule(builder, rule, indent_levels + 1)); + return {}; } -void dump_style_rule(StringBuilder& builder, CSS::CSSStyleRule const& rule, int indent_levels) +ErrorOr dump_style_rule(StringBuilder& builder, CSS::CSSStyleRule const& rule, int indent_levels) { for (auto& selector : rule.selectors()) { dump_selector(builder, selector); @@ -642,36 +644,38 @@ void dump_style_rule(StringBuilder& builder, CSS::CSSStyleRule const& rule, int auto& style_declaration = verify_cast(rule.declaration()); for (auto& property : style_declaration.properties()) { indent(builder, indent_levels); - builder.appendff(" {}: '{}'", CSS::string_from_property_id(property.property_id), property.value->to_string()); + builder.appendff(" {}: '{}'", CSS::string_from_property_id(property.property_id), TRY(property.value->to_string())); if (property.important == CSS::Important::Yes) builder.append(" \033[31;1m!important\033[0m"sv); builder.append('\n'); } for (auto& property : style_declaration.custom_properties()) { indent(builder, indent_levels); - builder.appendff(" {}: '{}'", property.key, property.value.value->to_string()); + builder.appendff(" {}: '{}'", property.key, TRY(property.value.value->to_string())); if (property.value.important == CSS::Important::Yes) builder.append(" \033[31;1m!important\033[0m"sv); builder.append('\n'); } + return {}; } -void dump_sheet(CSS::StyleSheet const& sheet) +ErrorOr dump_sheet(CSS::StyleSheet const& sheet) { StringBuilder builder; - dump_sheet(builder, sheet); + TRY(dump_sheet(builder, sheet)); dbgln("{}", builder.string_view()); + return {}; } -void dump_sheet(StringBuilder& builder, CSS::StyleSheet const& sheet) +ErrorOr dump_sheet(StringBuilder& builder, CSS::StyleSheet const& sheet) { auto& css_stylesheet = verify_cast(sheet); builder.appendff("CSSStyleSheet{{{}}}: {} rule(s)\n", &sheet, css_stylesheet.rules().length()); - for (auto& rule : css_stylesheet.rules()) { - dump_rule(builder, rule); - } + for (auto& rule : css_stylesheet.rules()) + TRY(dump_rule(builder, rule)); + return {}; } } diff --git a/Userland/Libraries/LibWeb/Dump.h b/Userland/Libraries/LibWeb/Dump.h index a76b104a2a4..28688bca259 100644 --- a/Userland/Libraries/LibWeb/Dump.h +++ b/Userland/Libraries/LibWeb/Dump.h @@ -16,15 +16,15 @@ void dump_tree(StringBuilder&, DOM::Node const&); void dump_tree(DOM::Node const&); void dump_tree(StringBuilder&, Layout::Node const&, bool show_box_model = false, bool show_specified_style = false, bool colorize = false); void dump_tree(Layout::Node const&, bool show_box_model = true, bool show_specified_style = false); -void dump_sheet(StringBuilder&, CSS::StyleSheet const&); -void dump_sheet(CSS::StyleSheet const&); -void dump_rule(StringBuilder&, CSS::CSSRule const&, int indent_levels = 0); -void dump_rule(CSS::CSSRule const&); +ErrorOr dump_sheet(StringBuilder&, CSS::StyleSheet const&); +ErrorOr dump_sheet(CSS::StyleSheet const&); +ErrorOr dump_rule(StringBuilder&, CSS::CSSRule const&, int indent_levels = 0); +ErrorOr dump_rule(CSS::CSSRule const&); void dump_font_face_rule(StringBuilder&, CSS::CSSFontFaceRule const&, int indent_levels = 0); void dump_import_rule(StringBuilder&, CSS::CSSImportRule const&, int indent_levels = 0); -void dump_media_rule(StringBuilder&, CSS::CSSMediaRule const&, int indent_levels = 0); -void dump_style_rule(StringBuilder&, CSS::CSSStyleRule const&, int indent_levels = 0); -void dump_supports_rule(StringBuilder&, CSS::CSSSupportsRule const&, int indent_levels = 0); +ErrorOr dump_media_rule(StringBuilder&, CSS::CSSMediaRule const&, int indent_levels = 0); +ErrorOr dump_style_rule(StringBuilder&, CSS::CSSStyleRule const&, int indent_levels = 0); +ErrorOr dump_supports_rule(StringBuilder&, CSS::CSSSupportsRule const&, int indent_levels = 0); void dump_selector(StringBuilder&, CSS::Selector const&); void dump_selector(CSS::Selector const&); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 89664bffbce..dd7971fac97 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -221,7 +221,8 @@ void ConnectionFromClient::debug_request(DeprecatedString const& request, Deprec if (request == "dump-style-sheets") { if (auto* doc = page().top_level_browsing_context().active_document()) { for (auto& sheet : doc->style_sheets().sheets()) { - Web::dump_sheet(sheet); + if (auto result = Web::dump_sheet(sheet); result.is_error()) + dbgln("Failed to dump style sheets: {}", result.error()); } } }