diff --git a/AK/TypeCasts.h b/AK/TypeCasts.h index e254e3642d4..e85dab1f08d 100644 --- a/AK/TypeCasts.h +++ b/AK/TypeCasts.h @@ -28,7 +28,7 @@ ALWAYS_INLINE bool is(InputType* input) } template -ALWAYS_INLINE CopyConst* downcast(InputType* input) +ALWAYS_INLINE CopyConst* verify_cast(InputType* input) { static_assert(IsBaseOf); VERIFY(!input || is(*input)); @@ -36,7 +36,7 @@ ALWAYS_INLINE CopyConst* downcast(InputType* input) } template -ALWAYS_INLINE CopyConst& downcast(InputType& input) +ALWAYS_INLINE CopyConst& verify_cast(InputType& input) { static_assert(IsBaseOf); VERIFY(is(input)); @@ -45,5 +45,5 @@ ALWAYS_INLINE CopyConst& downcast(InputType& input) } -using AK::downcast; using AK::is; +using AK::verify_cast; diff --git a/AK/Variant.h b/AK/Variant.h index 83c884d3494..ede7a3dd541 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -319,7 +319,7 @@ public: } template - Variant downcast() && + Variant verify_cast() && { Variant instance { Variant::invalid_index, Detail::VariantConstructTag {} }; visit([&](auto& value) { @@ -331,7 +331,7 @@ public: } template - Variant downcast() & + Variant verify_cast() & { Variant instance { Variant::invalid_index, Detail::VariantConstructTag {} }; visit([&](const auto& value) { diff --git a/Tests/AK/TestVariant.cpp b/Tests/AK/TestVariant.cpp index 1495fda1a60..2c1b0c725ff 100644 --- a/Tests/AK/TestVariant.cpp +++ b/Tests/AK/TestVariant.cpp @@ -77,17 +77,17 @@ TEST_CASE(move_moves) EXPECT(second_variant.has()); } -TEST_CASE(downcast) +TEST_CASE(verify_cast) { Variant one_integer_to_rule_them_all { static_cast(42) }; - auto fake_integer = one_integer_to_rule_them_all.downcast(); + auto fake_integer = one_integer_to_rule_them_all.verify_cast(); EXPECT(fake_integer.has()); EXPECT(one_integer_to_rule_them_all.has()); EXPECT_EQ(fake_integer.get(), 42); EXPECT_EQ(one_integer_to_rule_them_all.get(), 42); fake_integer = static_cast(60); - one_integer_to_rule_them_all = fake_integer.downcast().downcast().downcast(); + one_integer_to_rule_them_all = fake_integer.verify_cast().verify_cast().verify_cast(); EXPECT(fake_integer.has()); EXPECT(one_integer_to_rule_them_all.has()); EXPECT_EQ(fake_integer.get(), 60); diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index a00feabe783..f8cf9c9b49b 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -479,7 +479,7 @@ GUI::TabWidget& BrowserWindow::tab_widget() Tab& BrowserWindow::active_tab() { - return downcast(*tab_widget().active_widget()); + return verify_cast(*tab_widget().active_widget()); } void BrowserWindow::set_window_title_for_tab(Tab const& tab) diff --git a/Userland/Applications/Browser/InspectorWidget.cpp b/Userland/Applications/Browser/InspectorWidget.cpp index 115f1ed2818..3d1d8a3f82e 100644 --- a/Userland/Applications/Browser/InspectorWidget.cpp +++ b/Userland/Applications/Browser/InspectorWidget.cpp @@ -22,7 +22,7 @@ void InspectorWidget::set_inspected_node(Web::DOM::Node* node) { m_document->set_inspected_node(node); if (node && node->is_element()) { - auto& element = downcast(*node); + auto& element = verify_cast(*node); if (element.specified_css_values()) { m_style_table_view->set_model(Web::StylePropertiesModel::create(*element.specified_css_values())); m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(*element.computed_style())); diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index bbce9285220..9748e260386 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char** argv) auto current_image_editor = [&]() -> PixelPaint::ImageEditor* { if (!tab_widget.active_widget()) return nullptr; - return downcast(tab_widget.active_widget()); + return verify_cast(tab_widget.active_widget()); }; Function)> create_new_editor; @@ -552,14 +552,14 @@ int main(int argc, char** argv) }; tab_widget.on_tab_close_click = [&](auto& widget) { - auto& image_editor = downcast(widget); + auto& image_editor = verify_cast(widget); tab_widget.deferred_invoke([&](auto&) { tab_widget.remove_tab(image_editor); }); }; tab_widget.on_change = [&](auto& widget) { - auto& image_editor = downcast(widget); + auto& image_editor = verify_cast(widget); palette_widget.set_image_editor(image_editor); layer_list_widget.set_image(&image_editor.image()); layer_properties_widget.set_layer(nullptr); diff --git a/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp b/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp index e3b4111b8c1..23999e4f0e8 100644 --- a/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp +++ b/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp @@ -74,7 +74,7 @@ void ThreadStackWidget::refresh() void ThreadStackWidget::custom_event(Core::CustomEvent& event) { - auto& completion_event = downcast(event); + auto& completion_event = verify_cast(event); StringBuilder builder; diff --git a/Userland/Libraries/LibGUI/StackWidget.cpp b/Userland/Libraries/LibGUI/StackWidget.cpp index 84b375872df..1a618a51c66 100644 --- a/Userland/Libraries/LibGUI/StackWidget.cpp +++ b/Userland/Libraries/LibGUI/StackWidget.cpp @@ -54,7 +54,7 @@ void StackWidget::child_event(Core::ChildEvent& event) { if (!event.child() || !is(*event.child())) return Widget::child_event(event); - auto& child = downcast(*event.child()); + auto& child = verify_cast(*event.child()); if (event.type() == Event::ChildAdded) { if (!m_active_widget) set_active_widget(&child); diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp index 4f0572fefa4..4017d22ce3f 100644 --- a/Userland/Libraries/LibGUI/TabWidget.cpp +++ b/Userland/Libraries/LibGUI/TabWidget.cpp @@ -134,7 +134,7 @@ void TabWidget::child_event(Core::ChildEvent& event) { if (!event.child() || !is(*event.child())) return Widget::child_event(event); - auto& child = downcast(*event.child()); + auto& child = verify_cast(*event.child()); if (event.type() == Event::ChildAdded) { if (!m_active_widget) set_active_widget(&child); diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index 30654a4cef1..2b91f686d99 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -147,22 +147,22 @@ void Widget::child_event(Core::ChildEvent& event) if (event.type() == Event::ChildAdded) { if (event.child() && is(*event.child()) && layout()) { if (event.insertion_before_child() && is(event.insertion_before_child())) - layout()->insert_widget_before(downcast(*event.child()), downcast(*event.insertion_before_child())); + layout()->insert_widget_before(verify_cast(*event.child()), verify_cast(*event.insertion_before_child())); else - layout()->add_widget(downcast(*event.child())); + layout()->add_widget(verify_cast(*event.child())); } if (window() && event.child() && is(*event.child())) - window()->did_add_widget({}, downcast(*event.child())); + window()->did_add_widget({}, verify_cast(*event.child())); } if (event.type() == Event::ChildRemoved) { if (layout()) { if (event.child() && is(*event.child())) - layout()->remove_widget(downcast(*event.child())); + layout()->remove_widget(verify_cast(*event.child())); else invalidate_layout(); } if (window() && event.child() && is(*event.child())) - window()->did_remove_widget({}, downcast(*event.child())); + window()->did_remove_widget({}, verify_cast(*event.child())); update(); } return Core::Object::child_event(event); @@ -563,7 +563,7 @@ Widget* Widget::child_at(const Gfx::IntPoint& point) const for (int i = children().size() - 1; i >= 0; --i) { if (!is(children()[i])) continue; - auto& child = downcast(children()[i]); + auto& child = verify_cast(children()[i]); if (!child.is_visible()) continue; if (child.content_rect().contains(point)) diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h index 38a3db98d43..647d75b279b 100644 --- a/Userland/Libraries/LibGUI/Widget.h +++ b/Userland/Libraries/LibGUI/Widget.h @@ -245,7 +245,7 @@ public: { for_each_child([&](auto& child) { if (is(child)) - return callback(downcast(child)); + return callback(verify_cast(child)); return IterationDecision::Continue; }); } @@ -370,13 +370,13 @@ private: inline Widget* Widget::parent_widget() { if (parent() && is(*parent())) - return &downcast(*parent()); + return &verify_cast(*parent()); return nullptr; } inline const Widget* Widget::parent_widget() const { if (parent() && is(*parent())) - return &downcast(*parent()); + return &verify_cast(*parent()); return nullptr; } } diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 5f13e32c165..50b1e1cc80e 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1691,7 +1691,7 @@ NonnullRefPtr Parser::parse_variable_declaration(bool for_l declarations.append(create_ast_node( { m_state.current_token.filename(), rule_start.position(), position() }, - move(target).downcast, NonnullRefPtr>(), + move(target).verify_cast, NonnullRefPtr>(), move(init))); if (match(TokenType::Comma)) { diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp index 49580e31b15..a75590515cb 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp @@ -397,7 +397,7 @@ Optional AbstractMachine::allocate_all_initial_phase(Module module_instance.exports().append(ExportInstance { entry.name(), - move(address).downcast(), + move(address).verify_cast(), }); } }); diff --git a/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp b/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp index 7115b0ba34a..8de111ab1b4 100644 --- a/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp +++ b/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp @@ -41,7 +41,7 @@ bool CSSStyleDeclarationWrapper::put(const JS::PropertyName& name, JS::Value val return false; ScopeGuard style_invalidation_guard = [&] { - auto& declaration = downcast(impl()); + auto& declaration = verify_cast(impl()); if (auto* element = declaration.element()) element->invalidate_style(); }; diff --git a/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp b/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp index 77b57cadda1..eed54b961cf 100644 --- a/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp +++ b/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp @@ -164,163 +164,163 @@ namespace Web::Bindings { NodeWrapper* wrap(JS::GlobalObject& global_object, DOM::Node& node) { if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) - return static_cast(wrap_impl(global_object, downcast(node))); + return static_cast(wrap_impl(global_object, verify_cast(node))); return static_cast(wrap_impl(global_object, node)); } diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h index ea9904de492..3c701ae2281 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h @@ -36,9 +36,9 @@ public: { for (auto& rule : m_rules) if (rule.type() == CSSRule::Type::Style) { - callback(downcast(rule)); + callback(verify_cast(rule)); } else if (rule.type() == CSSRule::Type::Import) { - const auto& import_rule = downcast(rule); + const auto& import_rule = verify_cast(rule); if (import_rule.has_import_result()) import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback); } @@ -49,7 +49,7 @@ public: { for (auto& rule : m_rules) if (rule.type() == CSSRule::Type::Import) { - auto& import_rule = downcast(rule); + auto& import_rule = verify_cast(rule); if (!import_rule.has_import_result()) { callback(import_rule); return true; diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp index bd7e24ae60c..7669a57f6f8 100644 --- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -212,7 +212,7 @@ static bool matches(const CSS::Selector& selector, int component_list_index, con for (auto* ancestor = element.parent(); ancestor; ancestor = ancestor->parent()) { if (!is(*ancestor)) continue; - if (matches(selector, component_list_index - 1, downcast(*ancestor))) + if (matches(selector, component_list_index - 1, verify_cast(*ancestor))) return true; } return false; @@ -220,7 +220,7 @@ static bool matches(const CSS::Selector& selector, int component_list_index, con VERIFY(component_list_index != 0); if (!element.parent() || !is(*element.parent())) return false; - return matches(selector, component_list_index - 1, downcast(*element.parent())); + return matches(selector, component_list_index - 1, verify_cast(*element.parent())); case CSS::Selector::ComplexSelector::Relation::AdjacentSibling: VERIFY(component_list_index != 0); if (auto* sibling = element.previous_element_sibling()) diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 0140059dcf3..be62c097f03 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -278,11 +278,11 @@ Optional StyleProperties::flex_grow_factor() const auto value = property(CSS::PropertyID::FlexGrow); if (!value.has_value()) return {}; - if (value.value()->is_length() && downcast(value.value().ptr())->to_length().raw_value() == 0) + if (value.value()->is_length() && verify_cast(value.value().ptr())->to_length().raw_value() == 0) return { 0 }; if (!value.value()->is_numeric()) return {}; - auto numeric = downcast(value.value().ptr()); + auto numeric = verify_cast(value.value().ptr()); return numeric->value(); } @@ -291,11 +291,11 @@ Optional StyleProperties::flex_shrink_factor() const auto value = property(CSS::PropertyID::FlexShrink); if (!value.has_value()) return {}; - if (value.value()->is_length() && downcast(value.value().ptr())->to_length().raw_value() == 0) + if (value.value()->is_length() && verify_cast(value.value().ptr())->to_length().raw_value() == 0) return { 0 }; if (!value.value()->is_numeric()) return {}; - auto numeric = downcast(value.value().ptr()); + auto numeric = verify_cast(value.value().ptr()); return numeric->value(); } diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f1c3d239e13..712c963f124 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -188,7 +188,7 @@ HTML::HTMLHtmlElement* Document::html_element() { auto* html = document_element(); if (is(html)) - return downcast(html); + return verify_cast(html); return nullptr; } @@ -423,7 +423,7 @@ static void update_style_recursively(DOM::Node& node) node.for_each_child([&](auto& child) { if (child.needs_style_update()) { if (is(child)) - downcast(child).recompute_style(); + verify_cast(child).recompute_style(); child.set_needs_style_update(false); } if (child.child_needs_style_update()) { @@ -836,7 +836,7 @@ ExceptionOr> Document::adopt_node_binding(NonnullRefPtr(*node)) return DOM::HierarchyRequestError::create("Cannot adopt a shadow root into a document"); - if (is(*node) && downcast(*node).host()) + if (is(*node) && verify_cast(*node).host()) return node; adopt_node(*node); diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index dae0af495b3..26f5e0af68f 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -290,7 +290,7 @@ String Element::inner_html() const Function recurse = [&](auto& node) { for (auto* child = node.first_child(); child; child = child->next_sibling()) { if (child->is_element()) { - auto& element = downcast(*child); + auto& element = verify_cast(*child); builder.append('<'); builder.append(element.local_name()); element.for_each_attribute([&](auto& name, auto& value) { @@ -311,7 +311,7 @@ String Element::inner_html() const builder.append('>'); } if (child->is_text()) { - auto& text = downcast(*child); + auto& text = verify_cast(*child); builder.append(escape_string(text.data(), false)); } // FIXME: Also handle Comment, ProcessingInstruction, DocumentType diff --git a/Userland/Libraries/LibWeb/DOM/Event.cpp b/Userland/Libraries/LibWeb/DOM/Event.cpp index 77dd356e403..73d0aaa3057 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.cpp +++ b/Userland/Libraries/LibWeb/DOM/Event.cpp @@ -18,11 +18,11 @@ void Event::append_to_path(EventTarget& invocation_target, RefPtr s bool root_of_closed_tree = false; if (is(invocation_target)) { - auto& invocation_target_node = downcast(invocation_target); + auto& invocation_target_node = verify_cast(invocation_target); if (is(invocation_target_node.root())) invocation_target_in_shadow_tree = true; if (is(invocation_target_node)) { - auto& invocation_target_shadow_root = downcast(invocation_target_node); + auto& invocation_target_shadow_root = verify_cast(invocation_target_node); root_of_closed_tree = invocation_target_shadow_root.closed(); } } diff --git a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp index 78eccef06aa..c4d4133dc41 100644 --- a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp @@ -35,14 +35,14 @@ static EventTarget* retarget(EventTarget* left, [[maybe_unused]] EventTarget* ri if (!is(left)) return left; - auto* left_node = downcast(left); + auto* left_node = verify_cast(left); auto* left_root = left_node->root(); if (!is(left_root)) return left; // FIXME: If right is a node and left’s root is a shadow-including inclusive ancestor of right, return left. - auto* left_shadow_root = downcast(left_root); + auto* left_shadow_root = verify_cast(left_root); left = left_shadow_root->host(); } } @@ -76,7 +76,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector current_event; if (is(global)) { - auto& bindings_window_global = downcast(global); + auto& bindings_window_global = verify_cast(global); auto& window_impl = bindings_window_global.impl(); current_event = window_impl.current_event(); if (!invocation_target_in_shadow_tree) @@ -97,7 +97,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector(global)) { - auto& bindings_window_global = downcast(global); + auto& bindings_window_global = verify_cast(global); auto& window_impl = bindings_window_global.impl(); window_impl.set_current_event(current_event); } @@ -162,7 +162,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr target, NonnullRefPtr< target_override = target; } else { // NOTE: This can be done because legacy_target_override is only set for events targeted at Window. - target_override = downcast(*target).document(); + target_override = verify_cast(*target).document(); } RefPtr activation_target; @@ -232,13 +232,13 @@ bool EventDispatcher::dispatch(NonnullRefPtr target, NonnullRefPtr< VERIFY(clear_targets_struct.has_value()); if (is(clear_targets_struct.value().shadow_adjusted_target.ptr())) { - auto& shadow_adjusted_target_node = downcast(*clear_targets_struct.value().shadow_adjusted_target); + auto& shadow_adjusted_target_node = verify_cast(*clear_targets_struct.value().shadow_adjusted_target); if (is(shadow_adjusted_target_node.root())) clear_targets = true; } if (!clear_targets && is(clear_targets_struct.value().related_target.ptr())) { - auto& related_target_node = downcast(*clear_targets_struct.value().related_target); + auto& related_target_node = verify_cast(*clear_targets_struct.value().related_target); if (is(related_target_node.root())) clear_targets = true; } @@ -246,7 +246,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr target, NonnullRefPtr< if (!clear_targets) { for (auto touch_target : clear_targets_struct.value().touch_target_list) { if (is(*touch_target.ptr())) { - auto& touch_target_node = downcast(*touch_target.ptr()); + auto& touch_target_node = verify_cast(*touch_target.ptr()); if (is(touch_target_node.root())) { clear_targets = true; break; diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index e84bca283ec..058cd1f459e 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -51,8 +51,8 @@ Node::~Node() const HTML::HTMLAnchorElement* Node::enclosing_link_element() const { for (auto* node = this; node; node = node->parent()) { - if (is(*node) && downcast(*node).has_attribute(HTML::AttributeNames::href)) - return downcast(node); + if (is(*node) && verify_cast(*node).has_attribute(HTML::AttributeNames::href)) + return verify_cast(node); } return nullptr; } @@ -65,8 +65,8 @@ const HTML::HTMLElement* Node::enclosing_html_element() const const HTML::HTMLElement* Node::enclosing_html_element_with_attribute(const FlyString& attribute) const { for (auto* node = this; node; node = node->parent()) { - if (is(*node) && downcast(*node).has_attribute(attribute)) - return downcast(node); + if (is(*node) && verify_cast(*node).has_attribute(attribute)) + return verify_cast(node); } return nullptr; } @@ -83,7 +83,7 @@ String Node::text_content() const void Node::set_text_content(const String& content) { if (is_text()) { - downcast(this)->set_data(content); + verify_cast(this)->set_data(content); } else { remove_all_children(); append_child(document().create_text_node(content)); @@ -123,9 +123,9 @@ String Node::child_text_content() const return String::empty(); StringBuilder builder; - downcast(*this).for_each_child([&](auto& child) { + verify_cast(*this).for_each_child([&](auto& child) { if (is(child)) - builder.append(downcast(child).text_content()); + builder.append(verify_cast(child).text_content()); }); return builder.build(); } @@ -142,7 +142,7 @@ Node* Node::shadow_including_root() { auto node_root = root(); if (is(node_root)) - return downcast(node_root)->host()->shadow_including_root(); + return verify_cast(node_root)->host()->shadow_including_root(); return node_root; } @@ -155,14 +155,14 @@ Element* Node::parent_element() { if (!parent() || !is(parent())) return nullptr; - return downcast(parent()); + return verify_cast(parent()); } const Element* Node::parent_element() const { if (!parent() || !is(parent())) return nullptr; - return downcast(parent()); + return verify_cast(parent()); } // https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity @@ -187,7 +187,7 @@ ExceptionOr Node::ensure_pre_insertion_validity(NonnullRefPtr node, if (is(this)) { if (is(*node)) { - auto node_element_child_count = downcast(*node).child_element_count(); + auto node_element_child_count = verify_cast(*node).child_element_count(); if ((node_element_child_count > 1 || node->has_child_of_type()) || (node_element_child_count == 1 && (has_child_of_type() || is(child.ptr()) /* FIXME: or child is non-null and a doctype is following child. */))) { return DOM::HierarchyRequestError::create("Invalid node type for insertion"); @@ -209,7 +209,7 @@ void Node::insert_before(NonnullRefPtr node, RefPtr child, bool supp { NonnullRefPtrVector nodes; if (is(*node)) - nodes = downcast(*node).child_nodes(); + nodes = verify_cast(*node).child_nodes(); else nodes.append(node); @@ -369,7 +369,7 @@ ExceptionOr> Node::replace_child(NonnullRefPtr node, N if (is(this)) { if (is(*node)) { - auto node_element_child_count = downcast(*node).child_element_count(); + auto node_element_child_count = verify_cast(*node).child_element_count(); if ((node_element_child_count > 1 || node->has_child_of_type()) || (node_element_child_count == 1 && (first_child_of_type() != child /* FIXME: or a doctype is following child. */))) { return DOM::HierarchyRequestError::create("Invalid node type for insertion"); @@ -411,7 +411,7 @@ NonnullRefPtr Node::clone_node(Document* document, bool clone_children) co document = m_document; RefPtr copy; if (is(this)) { - auto& element = *downcast(this); + auto& element = *verify_cast(this); auto qualified_name = QualifiedName(element.local_name(), element.prefix(), element.namespace_()); auto element_copy = adopt_ref(*new Element(*document, move(qualified_name))); element.for_each_attribute([&](auto& name, auto& value) { @@ -419,7 +419,7 @@ NonnullRefPtr Node::clone_node(Document* document, bool clone_children) co }); copy = move(element_copy); } else if (is(this)) { - auto document_ = downcast(this); + auto document_ = verify_cast(this); auto document_copy = Document::create(document_->url()); document_copy->set_encoding(document_->encoding()); document_copy->set_content_type(document_->content_type()); @@ -428,22 +428,22 @@ NonnullRefPtr Node::clone_node(Document* document, bool clone_children) co // FIXME: Set type ("xml" or "html") copy = move(document_copy); } else if (is(this)) { - auto document_type = downcast(this); + auto document_type = verify_cast(this); auto document_type_copy = adopt_ref(*new DocumentType(*document)); document_type_copy->set_name(document_type->name()); document_type_copy->set_public_id(document_type->public_id()); document_type_copy->set_system_id(document_type->system_id()); copy = move(document_type_copy); } else if (is(this)) { - auto text = downcast(this); + auto text = verify_cast(this); auto text_copy = adopt_ref(*new Text(*document, text->data())); copy = move(text_copy); } else if (is(this)) { - auto comment = downcast(this); + auto comment = verify_cast(this); auto comment_copy = adopt_ref(*new Comment(*document, comment->data())); copy = move(comment_copy); } else if (is(this)) { - auto processing_instruction = downcast(this); + auto processing_instruction = verify_cast(this); auto processing_instruction_copy = adopt_ref(*new ProcessingInstruction(*document, processing_instruction->data(), processing_instruction->target())); copy = move(processing_instruction_copy); } else { @@ -490,7 +490,7 @@ JS::Object* Node::create_wrapper(JS::GlobalObject& global_object) void Node::removed_last_ref() { if (is(*this)) { - downcast(*this).removed_last_ref(); + verify_cast(*this).removed_last_ref(); return; } m_deletion_has_begun = true; @@ -534,8 +534,8 @@ void Node::inserted() ParentNode* Node::parent_or_shadow_host() { if (is(*this)) - return downcast(*this).host(); - return downcast(parent()); + return verify_cast(*this).host(); + return verify_cast(parent()); } NonnullRefPtrVector Node::child_nodes() const @@ -595,7 +595,7 @@ u16 Node::compare_document_position(RefPtr other) // https://dom.spec.whatwg.org/#concept-tree-host-including-inclusive-ancestor bool Node::is_host_including_inclusive_ancestor_of(const Node& other) const { - return is_inclusive_ancestor_of(other) || (is(other.root()) && downcast(other.root())->host() && is_inclusive_ancestor_of(*downcast(other.root())->host().ptr())); + return is_inclusive_ancestor_of(other) || (is(other.root()) && verify_cast(other.root())->host() && is_inclusive_ancestor_of(*verify_cast(other.root())->host().ptr())); } // https://dom.spec.whatwg.org/#dom-node-ownerdocument diff --git a/Userland/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h b/Userland/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h index ba38305342b..c63b117a01d 100644 --- a/Userland/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h +++ b/Userland/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h @@ -19,7 +19,7 @@ public: { for (auto* sibling = static_cast(this)->previous_sibling(); sibling; sibling = sibling->previous_sibling()) { if (is(*sibling)) - return downcast(sibling); + return verify_cast(sibling); } return nullptr; } @@ -28,7 +28,7 @@ public: { for (auto* sibling = static_cast(this)->next_sibling(); sibling; sibling = sibling->next_sibling()) { if (is(*sibling)) - return downcast(sibling); + return verify_cast(sibling); } return nullptr; } @@ -37,7 +37,7 @@ public: { for (auto* node = static_cast(this)->next_in_pre_order(); node; node = node->next_in_pre_order()) { if (is(*node)) - return downcast(node); + return verify_cast(node); } return nullptr; } diff --git a/Userland/Libraries/LibWeb/DOM/Position.cpp b/Userland/Libraries/LibWeb/DOM/Position.cpp index e4dc8cd67cf..fca20bc24ad 100644 --- a/Userland/Libraries/LibWeb/DOM/Position.cpp +++ b/Userland/Libraries/LibWeb/DOM/Position.cpp @@ -34,7 +34,7 @@ bool Position::increment_offset() if (!is(*m_node)) return false; - auto& node = downcast(*m_node); + auto& node = verify_cast(*m_node); auto text = Utf8View(node.data()); for (auto iterator = text.begin(); !iterator.done(); ++iterator) { @@ -53,7 +53,7 @@ bool Position::decrement_offset() if (m_offset == 0 || !is(*m_node)) return false; - auto& node = downcast(*m_node); + auto& node = verify_cast(*m_node); auto text = Utf8View(node.data()); size_t last_smaller_offset = 0; @@ -76,7 +76,7 @@ bool Position::offset_is_at_end_of_node() const if (!is(*m_node)) return false; - auto& node = downcast(*m_node); + auto& node = verify_cast(*m_node); auto text = node.data(); return m_offset == text.length(); } diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp index de9b47db754..07dc13ed384 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp @@ -19,7 +19,7 @@ ShadowRoot::ShadowRoot(Document& document, Element& host) EventTarget* ShadowRoot::get_parent(const Event& event) { if (!event.composed()) { - auto& events_first_invocation_target = downcast(*event.path().first().invocation_target); + auto& events_first_invocation_target = verify_cast(*event.path().first().invocation_target); if (events_first_invocation_target.root() == this) return nullptr; } diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.cpp b/Userland/Libraries/LibWeb/DOMTreeModel.cpp index ddd74793056..5857c78445c 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.cpp +++ b/Userland/Libraries/LibWeb/DOMTreeModel.cpp @@ -110,10 +110,10 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol } if (role == GUI::ModelRole::Display) { if (node.is_text()) - return with_whitespace_collapsed(downcast(node).data()); + return with_whitespace_collapsed(verify_cast(node).data()); if (!node.is_element()) return node.node_name(); - auto& element = downcast(node); + auto& element = verify_cast(node); StringBuilder builder; builder.append('<'); builder.append(element.local_name()); diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index bcf3116aea8..d30ca56b7d1 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -40,19 +40,19 @@ void dump_tree(StringBuilder& builder, const DOM::Node& node) for (int i = 0; i < indent; ++i) builder.append(" "); if (is(node)) { - builder.appendff("<{}", downcast(node).local_name()); - downcast(node).for_each_attribute([&](auto& name, auto& value) { + builder.appendff("<{}", verify_cast(node).local_name()); + verify_cast(node).for_each_attribute([&](auto& name, auto& value) { builder.appendff(" {}={}", name, value); }); builder.append(">\n"); } else if (is(node)) { - builder.appendff("\"{}\"\n", downcast(node).data()); + builder.appendff("\"{}\"\n", verify_cast(node).data()); } else { builder.appendff("{}\n", node.node_name()); } ++indent; - if (is(node) && downcast(node).shadow_root()) { - dump_tree(*downcast(node).shadow_root()); + if (is(node) && verify_cast(node).shadow_root()) { + dump_tree(*verify_cast(node).shadow_root()); } if (is(node)) { if (!is(node)) { @@ -60,7 +60,7 @@ void dump_tree(StringBuilder& builder, const DOM::Node& node) dump_tree(child); }); } else { - auto& template_element = downcast(node); + auto& template_element = verify_cast(node); dump_tree(template_element.content()); } } @@ -84,13 +84,13 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho if (layout_node.is_anonymous()) tag_name = "(anonymous)"; else if (is(layout_node.dom_node())) - tag_name = downcast(*layout_node.dom_node()).local_name(); + tag_name = verify_cast(*layout_node.dom_node()).local_name(); else tag_name = layout_node.dom_node()->node_name(); String identifier = ""; if (layout_node.dom_node() && is(*layout_node.dom_node())) { - auto& element = downcast(*layout_node.dom_node()); + auto& element = verify_cast(*layout_node.dom_node()); StringBuilder builder; auto id = element.attribute(HTML::AttributeNames::id); if (!id.is_empty()) { @@ -139,7 +139,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho builder.appendff(" @{:p}", &layout_node); builder.append("\n"); } else { - auto& box = downcast(layout_node); + auto& box = verify_cast(layout_node); builder.appendff("{}{}{} <{}{}{}{}> ", box_color_on, box.class_name().substring_view(13), @@ -231,13 +231,13 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho } } - if (show_specified_style && layout_node.dom_node() && layout_node.dom_node()->is_element() && downcast(layout_node.dom_node())->specified_css_values()) { + if (show_specified_style && layout_node.dom_node() && layout_node.dom_node()->is_element() && verify_cast(layout_node.dom_node())->specified_css_values()) { struct NameAndValue { String name; String value; }; Vector properties; - downcast(*layout_node.dom_node()).specified_css_values()->for_each_property([&](auto property_id, auto& value) { + verify_cast(*layout_node.dom_node()).specified_css_values()->for_each_property([&](auto property_id, auto& value) { properties.append({ CSS::string_from_property_id(property_id), value.to_string() }); }); quick_sort(properties, [](auto& a, auto& b) { return a.name < b.name; }); @@ -417,10 +417,10 @@ void dump_rule(StringBuilder& builder, const CSS::CSSRule& rule) builder.appendff("{}:\n", rule.class_name()); switch (rule.type()) { case CSS::CSSRule::Type::Style: - dump_style_rule(builder, downcast(rule)); + dump_style_rule(builder, verify_cast(rule)); break; case CSS::CSSRule::Type::Import: - dump_import_rule(builder, downcast(rule)); + dump_import_rule(builder, verify_cast(rule)); break; default: VERIFY_NOT_REACHED(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 9d8ca1b5d67..599515d41f3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -110,7 +110,7 @@ String HTMLElement::inner_text() Function recurse = [&](auto& node) { for (auto* child = node.first_child(); child; child = child->next_sibling()) { if (is(child)) - builder.append(downcast(*child).text_for_rendering()); + builder.append(verify_cast(*child).text_for_rendering()); if (is(child)) builder.append('\n'); recurse(*child); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index fb104c377a8..1d94ea1f908 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -98,7 +98,7 @@ void HTMLFormElement::submit_form(RefPtr submitter, bool from_submi Vector parameters; for_each_in_inclusive_subtree_of_type([&](auto& node) { - auto& input = downcast(node); + auto& input = verify_cast(node); if (!input.name().is_null() && (input.type() != "submit" || &input == submitter)) parameters.append({ input.name(), input.value() }); return IterationDecision::Continue; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp index 16a1de0fba0..379b1ed0a2b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp @@ -30,7 +30,7 @@ void HTMLStyleElement::children_changed() StringBuilder builder; for_each_child([&](auto& child) { if (is(child)) - builder.append(downcast(child).text_content()); + builder.append(verify_cast(child).text_content()); }); m_css_loader.load_from_text(builder.to_string()); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index ab63c2bd430..16e44a3078a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -84,7 +84,7 @@ RefPtr HTMLTableElement::t_head() { for (auto* child = first_child(); child; child = child->next_sibling()) { if (is(*child)) { - auto table_section_element = &downcast(*child); + auto table_section_element = &verify_cast(*child); if (table_section_element->tag_name() == TagNames::thead) return table_section_element; } @@ -110,7 +110,7 @@ DOM::ExceptionOr HTMLTableElement::set_t_head(HTMLTableSectionElement& the if (is(*child)) continue; if (is(*child)) { - auto table_col_element = &downcast(*child); + auto table_col_element = &verify_cast(*child); if (table_col_element->tag_name() == TagNames::colgroup) continue; } @@ -141,7 +141,7 @@ NonnullRefPtr HTMLTableElement::create_t_head() if (is(*child)) continue; if (is(*child)) { - auto table_col_element = &downcast(*child); + auto table_col_element = &verify_cast(*child); if (table_col_element->tag_name() == TagNames::colgroup) continue; } @@ -168,7 +168,7 @@ RefPtr HTMLTableElement::t_foot() { for (auto* child = first_child(); child; child = child->next_sibling()) { if (is(*child)) { - auto table_section_element = &downcast(*child); + auto table_section_element = &verify_cast(*child); if (table_section_element->tag_name() == TagNames::tfoot) return table_section_element; } @@ -228,7 +228,7 @@ NonnullRefPtr HTMLTableElement::create_t_body() if (!is(*child)) continue; if (is(*child)) { - auto table_section_element = &downcast(*child); + auto table_section_element = &verify_cast(*child); if (table_section_element->tag_name() == TagNames::tbody) { // We have found an element which is a we'll insert after this child_to_append_after = child->next_sibling(); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 77e49a51557..cdf0e0a4f89 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -411,7 +411,7 @@ HTMLDocumentParser::AdjustedInsertionLocation HTMLDocumentParser::find_appropria auto last_table = m_stack_of_open_elements.last_element_with_tag_name(HTML::TagNames::table); if (last_template.element && (!last_table.element || last_template.index > last_table.index)) { // This returns the template content, so no need to check the parent is a template. - return { downcast(last_template.element)->content(), nullptr }; + return { verify_cast(last_template.element)->content(), nullptr }; } if (!last_table.element) { VERIFY(m_parsing_fragment); @@ -428,7 +428,7 @@ HTMLDocumentParser::AdjustedInsertionLocation HTMLDocumentParser::find_appropria } if (is(*adjusted_insertion_location.parent)) - return { downcast(*adjusted_insertion_location.parent).content(), nullptr }; + return { verify_cast(*adjusted_insertion_location.parent).content(), nullptr }; return adjusted_insertion_location; } @@ -497,7 +497,7 @@ void HTMLDocumentParser::handle_before_head(HTMLToken& token) if (token.is_start_tag() && token.tag_name() == HTML::TagNames::head) { auto element = insert_html_element(token); - m_head_element = downcast(*element); + m_head_element = verify_cast(*element); m_insertion_mode = InsertionMode::InHead; return; } @@ -512,7 +512,7 @@ void HTMLDocumentParser::handle_before_head(HTMLToken& token) } AnythingElse: - m_head_element = downcast(*insert_html_element(HTMLToken::make_start_tag(HTML::TagNames::head))); + m_head_element = verify_cast(*insert_html_element(HTMLToken::make_start_tag(HTML::TagNames::head))); m_insertion_mode = InsertionMode::InHead; process_using_the_rules_for(InsertionMode::InHead, token); return; @@ -583,7 +583,7 @@ void HTMLDocumentParser::handle_in_head(HTMLToken& token) if (token.is_start_tag() && token.tag_name() == HTML::TagNames::script) { auto adjusted_insertion_location = find_appropriate_place_for_inserting_node(); auto element = create_element_for(token, Namespace::HTML); - auto& script_element = downcast(*element); + auto& script_element = verify_cast(*element); script_element.set_parser_document({}, document()); script_element.set_non_blocking({}, false); @@ -706,7 +706,7 @@ DOM::Text* HTMLDocumentParser::find_character_insertion_node() if (adjusted_insertion_location.parent->is_document()) return nullptr; if (adjusted_insertion_location.parent->last_child() && adjusted_insertion_location.parent->last_child()->is_text()) - return downcast(adjusted_insertion_location.parent->last_child()); + return verify_cast(adjusted_insertion_location.parent->last_child()); auto new_text_node = adopt_ref(*new DOM::Text(document(), "")); adjusted_insertion_location.parent->append_child(new_text_node); return new_text_node; @@ -1268,7 +1268,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token) close_a_p_element(); auto element = insert_html_element(token); if (!m_stack_of_open_elements.contains(HTML::TagNames::template_)) - m_form_element = downcast(*element); + m_form_element = verify_cast(*element); return; } @@ -1877,7 +1877,7 @@ void HTMLDocumentParser::handle_text(HTMLToken& token) if (token.is_end_of_file()) { log_parse_error(); if (current_node().local_name() == HTML::TagNames::script) - downcast(current_node()).set_already_started({}, true); + verify_cast(current_node()).set_already_started({}, true); m_stack_of_open_elements.pop(); m_insertion_mode = m_original_insertion_mode; process_using_the_rules_for(m_insertion_mode, token); @@ -1887,7 +1887,7 @@ void HTMLDocumentParser::handle_text(HTMLToken& token) // Make sure the