From aeee98b3a1ec6fea99105cf9cb11bfd3e3ae1615 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 10 Oct 2023 15:00:58 +0330 Subject: [PATCH] AK+Everywhere: Remove the null state of DeprecatedString This commit removes DeprecatedString's "null" state, and replaces all its users with one of the following: - A normal, empty DeprecatedString - Optional Note that null states of DeprecatedFlyString/StringView/etc are *not* affected by this commit. However, DeprecatedString::empty() is now considered equal to a null StringView. --- AK/DeprecatedFlyString.cpp | 4 +- AK/DeprecatedString.cpp | 24 +++----- AK/DeprecatedString.h | 55 ++++++------------- AK/GenericLexer.cpp | 2 +- AK/GenericLexer.h | 2 +- AK/JsonParser.cpp | 2 - AK/JsonValue.cpp | 10 +--- AK/LexicalPath.cpp | 3 - AK/StringImpl.cpp | 12 +--- AK/StringView.cpp | 4 +- AK/URL.cpp | 12 ++-- .../Tools/CodeGenerators/IPCCompiler/main.cpp | 2 +- .../BindingsGenerator/IDLGenerators.cpp | 8 +-- Meta/Lagom/Tools/IPCMagicLinter/main.cpp | 4 +- Tests/AK/TestCircularDeque.cpp | 2 +- Tests/AK/TestDeprecatedString.cpp | 10 +--- Tests/AK/TestHashMap.cpp | 2 +- Tests/AK/TestHashTable.cpp | 2 +- Tests/AK/TestJSON.cpp | 4 -- Tests/AK/TestVector.cpp | 2 - Tests/LibC/TestRealpath.cpp | 2 +- Tests/LibJS/test262-runner.cpp | 27 +++++---- .../DisplaySettings/MonitorSettingsWidget.cpp | 2 +- Userland/Applications/Mail/MailWidget.cpp | 6 +- .../Applications/NetworkSettings/main.cpp | 2 +- .../Applications/SoundPlayer/M3UParser.cpp | 2 +- Userland/Applications/SoundPlayer/Player.cpp | 3 - .../Spreadsheet/SpreadsheetView.cpp | 2 +- .../SystemMonitor/MemoryStatsWidget.cpp | 2 +- .../Applications/TextEditor/MainWidget.cpp | 2 +- .../HackStudio/Debugger/BacktraceModel.cpp | 2 +- .../DevTools/HackStudio/Debugger/Debugger.cpp | 2 +- .../DevTools/HackStudio/EditorWrapper.cpp | 2 +- Userland/DevTools/HackStudio/Git/GitRepo.cpp | 32 +++++------ Userland/DevTools/HackStudio/Git/GitRepo.h | 4 +- .../DevTools/HackStudio/HackStudioWidget.cpp | 8 +-- .../HackStudio/LanguageServers/FileDB.cpp | 4 +- .../HackStudio/LanguageServers/FileDB.h | 2 +- Userland/DevTools/HackStudio/Locator.cpp | 2 +- Userland/Libraries/LibC/unistd.cpp | 6 +- .../Cpp/CppComprehensionEngine.cpp | 6 +- .../LibCodeComprehension/Cpp/Tests.cpp | 4 +- .../Libraries/LibCodeComprehension/FileDB.cpp | 4 +- .../Libraries/LibCodeComprehension/FileDB.h | 12 +++- Userland/Libraries/LibCore/Account.cpp | 24 ++++---- Userland/Libraries/LibCore/Account.h | 8 +-- Userland/Libraries/LibCore/ConfigFile.cpp | 7 +-- Userland/Libraries/LibCore/ConfigFile.h | 10 +++- Userland/Libraries/LibCore/System.cpp | 25 ++++++--- .../LibCore/SystemServerTakeover.cpp | 2 +- Userland/Libraries/LibCpp/Preprocessor.cpp | 4 +- Userland/Libraries/LibDNS/Packet.cpp | 2 +- Userland/Libraries/LibDebug/DebugInfo.cpp | 2 +- Userland/Libraries/LibELF/Image.cpp | 2 +- .../LibFileSystemAccessClient/Client.cpp | 2 +- Userland/Libraries/LibGUI/AbstractView.cpp | 23 ++++---- Userland/Libraries/LibGUI/AbstractView.h | 2 +- Userland/Libraries/LibGUI/FilePicker.cpp | 26 +++------ Userland/Libraries/LibGUI/FilePicker.h | 4 +- Userland/Libraries/LibGUI/FileSystemModel.cpp | 6 +- .../Libraries/LibGUI/ModelEditingDelegate.h | 5 +- Userland/Libraries/LibGUI/TableView.cpp | 4 +- Userland/Libraries/LibGUI/Variant.h | 1 - Userland/Libraries/LibGemini/Line.cpp | 2 +- Userland/Libraries/LibHTTP/Job.cpp | 14 ----- .../Libraries/LibJS/Runtime/JSONObject.cpp | 28 +++++----- Userland/Libraries/LibJS/Runtime/JSONObject.h | 4 +- .../LibJS/Runtime/PrimitiveString.cpp | 2 +- Userland/Libraries/LibJS/Runtime/VM.cpp | 2 +- Userland/Libraries/LibJS/Token.cpp | 6 +- Userland/Libraries/LibPDF/Parser.cpp | 2 - Userland/Libraries/LibSQL/AST/AST.h | 6 +- Userland/Libraries/LibSQL/AST/Parser.cpp | 14 ++--- Userland/Libraries/LibSQL/AST/Parser.h | 2 +- Userland/Libraries/LibTLS/Handshake.cpp | 4 +- .../Libraries/LibTest/JavaScriptTestRunner.h | 7 ++- Userland/Libraries/LibVT/Attribute.h | 2 +- Userland/Libraries/LibVT/TerminalWidget.cpp | 14 ++--- Userland/Libraries/LibVT/TerminalWidget.h | 4 +- .../Libraries/LibWeb/CSS/CSSNamespaceRule.cpp | 2 +- .../Libraries/LibWeb/CSS/CSSStyleRule.cpp | 10 ++-- .../Libraries/LibWeb/CSS/SelectorEngine.cpp | 6 +- Userland/Libraries/LibWeb/DOM/Attr.cpp | 6 +- Userland/Libraries/LibWeb/DOM/Attr.h | 2 +- Userland/Libraries/LibWeb/DOM/Element.cpp | 28 +++++----- Userland/Libraries/LibWeb/DOM/Element.h | 6 +- Userland/Libraries/LibWeb/DOM/Node.cpp | 24 +++----- Userland/Libraries/LibWeb/DOM/Node.h | 2 +- .../LibWeb/DOM/StyleElementUtils.cpp | 15 ++--- .../Libraries/LibWeb/DOM/StyleElementUtils.h | 2 +- .../LibWeb/DOMParsing/XMLSerializer.cpp | 14 +++-- Userland/Libraries/LibWeb/Dump.cpp | 2 +- .../LibWeb/HTML/HTMLAnchorElement.cpp | 8 +-- .../Libraries/LibWeb/HTML/HTMLAnchorElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLAreaElement.cpp | 8 +-- .../Libraries/LibWeb/HTML/HTMLAreaElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLBaseElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLBaseElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLBodyElement.cpp | 16 +++--- .../Libraries/LibWeb/HTML/HTMLBodyElement.h | 2 +- .../LibWeb/HTML/HTMLDetailsElement.cpp | 4 +- .../LibWeb/HTML/HTMLDetailsElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLElement.cpp | 14 ++--- Userland/Libraries/LibWeb/HTML/HTMLElement.h | 4 +- .../LibWeb/HTML/HTMLFrameSetElement.cpp | 8 +-- .../LibWeb/HTML/HTMLFrameSetElement.h | 2 +- .../LibWeb/HTML/HTMLHyperlinkElementUtils.cpp | 8 +-- .../LibWeb/HTML/HTMLHyperlinkElementUtils.h | 2 +- .../LibWeb/HTML/HTMLIFrameElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLIFrameElement.h | 2 +- .../LibWeb/HTML/HTMLImageElement.cpp | 34 ++++++------ .../Libraries/LibWeb/HTML/HTMLImageElement.h | 2 +- .../LibWeb/HTML/HTMLInputElement.cpp | 25 +++++---- .../Libraries/LibWeb/HTML/HTMLInputElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLLabelElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 17 +++--- .../Libraries/LibWeb/HTML/HTMLLinkElement.h | 2 +- .../LibWeb/HTML/HTMLMediaElement.cpp | 6 +- .../Libraries/LibWeb/HTML/HTMLMediaElement.h | 2 +- .../LibWeb/HTML/HTMLObjectElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLObjectElement.h | 2 +- .../LibWeb/HTML/HTMLOptionElement.cpp | 4 +- .../Libraries/LibWeb/HTML/HTMLOptionElement.h | 2 +- .../LibWeb/HTML/HTMLScriptElement.cpp | 10 ++-- .../Libraries/LibWeb/HTML/HTMLScriptElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLSlotElement.cpp | 8 +-- .../LibWeb/HTML/HTMLVideoElement.cpp | 6 +- .../Libraries/LibWeb/HTML/HTMLVideoElement.h | 2 +- .../LibWeb/HTML/NavigableContainer.cpp | 6 +- Userland/Libraries/LibWeb/HTML/Origin.h | 11 ++-- .../LibWeb/Layout/BlockFormattingContext.cpp | 5 +- Userland/Libraries/LibWeb/Layout/Label.cpp | 6 +- .../LibWeb/Layout/ListItemMarkerBox.h | 4 +- Userland/Libraries/LibWeb/Layout/TextNode.cpp | 4 +- Userland/Libraries/LibWeb/Layout/TextNode.h | 2 +- .../Libraries/LibWeb/Page/EventHandler.cpp | 4 +- .../LibWeb/Painting/MarkerPaintable.cpp | 8 ++- .../Libraries/LibWeb/SVG/SVGCircleElement.cpp | 8 +-- .../Libraries/LibWeb/SVG/SVGCircleElement.h | 2 +- Userland/Libraries/LibWeb/SVG/SVGElement.cpp | 2 +- Userland/Libraries/LibWeb/SVG/SVGElement.h | 2 +- .../LibWeb/SVG/SVGEllipseElement.cpp | 10 ++-- .../Libraries/LibWeb/SVG/SVGEllipseElement.h | 2 +- .../LibWeb/SVG/SVGGradientElement.cpp | 8 +-- .../Libraries/LibWeb/SVG/SVGGradientElement.h | 2 +- .../LibWeb/SVG/SVGGraphicsElement.cpp | 4 +- .../Libraries/LibWeb/SVG/SVGGraphicsElement.h | 2 +- .../Libraries/LibWeb/SVG/SVGLineElement.cpp | 10 ++-- .../Libraries/LibWeb/SVG/SVGLineElement.h | 2 +- .../LibWeb/SVG/SVGLinearGradientElement.cpp | 10 ++-- .../LibWeb/SVG/SVGLinearGradientElement.h | 2 +- .../Libraries/LibWeb/SVG/SVGMaskElement.cpp | 6 +- .../Libraries/LibWeb/SVG/SVGMaskElement.h | 2 +- .../Libraries/LibWeb/SVG/SVGPathElement.cpp | 4 +- .../Libraries/LibWeb/SVG/SVGPathElement.h | 2 +- .../LibWeb/SVG/SVGPolygonElement.cpp | 4 +- .../Libraries/LibWeb/SVG/SVGPolygonElement.h | 2 +- .../LibWeb/SVG/SVGPolylineElement.cpp | 4 +- .../Libraries/LibWeb/SVG/SVGPolylineElement.h | 2 +- .../LibWeb/SVG/SVGRadialGradientElement.cpp | 14 ++--- .../LibWeb/SVG/SVGRadialGradientElement.h | 2 +- .../Libraries/LibWeb/SVG/SVGRectElement.cpp | 14 ++--- .../Libraries/LibWeb/SVG/SVGRectElement.h | 2 +- .../Libraries/LibWeb/SVG/SVGSVGElement.cpp | 10 ++-- Userland/Libraries/LibWeb/SVG/SVGSVGElement.h | 2 +- .../Libraries/LibWeb/SVG/SVGStopElement.cpp | 4 +- .../Libraries/LibWeb/SVG/SVGStopElement.h | 2 +- .../Libraries/LibWeb/SVG/SVGSymbolElement.cpp | 4 +- .../Libraries/LibWeb/SVG/SVGSymbolElement.h | 2 +- .../LibWeb/SVG/SVGTextPositioningElement.cpp | 10 ++-- .../LibWeb/SVG/SVGTextPositioningElement.h | 2 +- .../Libraries/LibWeb/SVG/SVGUseElement.cpp | 8 +-- Userland/Libraries/LibWeb/SVG/SVGUseElement.h | 2 +- .../Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 2 +- Userland/Services/LaunchServer/Launcher.cpp | 2 +- Userland/Services/SystemServer/Service.cpp | 26 ++++----- Userland/Services/SystemServer/Service.h | 6 +- .../Services/Taskbar/QuickLaunchWidget.cpp | 2 +- .../Services/WindowServer/ScreenLayout.ipp | 2 +- Userland/Shell/Shell.cpp | 21 ++++--- Userland/Shell/Shell.h | 4 +- Userland/Utilities/ini.cpp | 2 +- Userland/Utilities/ls.cpp | 8 +-- Userland/Utilities/markdown-check.cpp | 3 +- Userland/Utilities/mktemp.cpp | 8 +-- Userland/Utilities/paste.cpp | 4 +- Userland/Utilities/su.cpp | 4 +- Userland/Utilities/sysctl.cpp | 12 ++-- Userland/Utilities/wallpaper.cpp | 2 +- 189 files changed, 597 insertions(+), 652 deletions(-) diff --git a/AK/DeprecatedFlyString.cpp b/AK/DeprecatedFlyString.cpp index bb302df90b5..cc9f50de78a 100644 --- a/AK/DeprecatedFlyString.cpp +++ b/AK/DeprecatedFlyString.cpp @@ -38,8 +38,6 @@ void DeprecatedFlyString::did_destroy_impl(Badge, StringImpl& impl) DeprecatedFlyString::DeprecatedFlyString(DeprecatedString const& string) { - if (string.is_null()) - return; if (string.impl()->is_fly()) { m_impl = string.impl(); return; @@ -60,7 +58,7 @@ DeprecatedFlyString::DeprecatedFlyString(StringView string) if (string.is_null()) return; auto it = fly_impls().find(string.hash(), [&](auto& candidate) { - return string == candidate; + return string == *candidate; }); if (it == fly_impls().end()) { auto new_string = string.to_deprecated_string(); diff --git a/AK/DeprecatedString.cpp b/AK/DeprecatedString.cpp index ac1a07a7eeb..74184daa49a 100644 --- a/AK/DeprecatedString.cpp +++ b/AK/DeprecatedString.cpp @@ -28,6 +28,9 @@ bool DeprecatedString::operator==(DeprecatedString const& other) const bool DeprecatedString::operator==(StringView other) const { + if (other.is_null()) + return is_empty(); + return view() == other; } @@ -55,9 +58,7 @@ bool DeprecatedString::copy_characters_to_buffer(char* buffer, size_t buffer_siz DeprecatedString DeprecatedString::isolated_copy() const { - if (!m_impl) - return {}; - if (!m_impl->length()) + if (m_impl->length() == 0) return empty(); char* buffer; auto impl = StringImpl::create_uninitialized(length(), buffer); @@ -69,7 +70,6 @@ DeprecatedString DeprecatedString::substring(size_t start, size_t length) const { if (!length) return DeprecatedString::empty(); - VERIFY(m_impl); VERIFY(!Checked::addition_would_overflow(start, length)); VERIFY(start + length <= m_impl->length()); return { characters() + start, length }; @@ -77,14 +77,12 @@ DeprecatedString DeprecatedString::substring(size_t start, size_t length) const DeprecatedString DeprecatedString::substring(size_t start) const { - VERIFY(m_impl); VERIFY(start <= length()); return { characters() + start, length() - start }; } StringView DeprecatedString::substring_view(size_t start, size_t length) const { - VERIFY(m_impl); VERIFY(!Checked::addition_would_overflow(start, length)); VERIFY(start + length <= m_impl->length()); return { characters() + start, length }; @@ -92,7 +90,6 @@ StringView DeprecatedString::substring_view(size_t start, size_t length) const StringView DeprecatedString::substring_view(size_t start) const { - VERIFY(m_impl); VERIFY(start <= length()); return { characters() + start, length() - start }; } @@ -157,8 +154,6 @@ Vector DeprecatedString::split_view(char const separator, SplitBehav ByteBuffer DeprecatedString::to_byte_buffer() const { - if (!m_impl) - return {}; // FIXME: Handle OOM failure. return ByteBuffer::copy(bytes()).release_value_but_fixme_should_propagate_errors(); } @@ -379,21 +374,17 @@ DeprecatedString escape_html_entities(StringView html) } DeprecatedString::DeprecatedString(DeprecatedFlyString const& string) - : m_impl(string.impl()) + : m_impl(*string.impl()) { } DeprecatedString DeprecatedString::to_lowercase() const { - if (!m_impl) - return {}; return m_impl->to_lowercase(); } DeprecatedString DeprecatedString::to_uppercase() const { - if (!m_impl) - return {}; return m_impl->to_uppercase(); } @@ -414,6 +405,9 @@ DeprecatedString DeprecatedString::invert_case() const bool DeprecatedString::operator==(char const* cstring) const { + if (!cstring) + return is_empty(); + return view() == cstring; } @@ -438,7 +432,7 @@ ErrorOr DeprecatedString::from_utf8(ReadonlyBytes bytes) { if (!Utf8View(bytes).validate()) return Error::from_string_literal("DeprecatedString::from_utf8: Input was not valid UTF-8"); - return DeprecatedString { StringImpl::create(bytes) }; + return DeprecatedString { *StringImpl::create(bytes) }; } } diff --git a/AK/DeprecatedString.h b/AK/DeprecatedString.h index 72cecc95a45..ad939d0c21e 100644 --- a/AK/DeprecatedString.h +++ b/AK/DeprecatedString.h @@ -40,10 +40,13 @@ class DeprecatedString { public: ~DeprecatedString() = default; - DeprecatedString() = default; + DeprecatedString() + : m_impl(StringImpl::the_empty_stringimpl()) + { + } DeprecatedString(StringView view) - : m_impl(StringImpl::create(view.characters_without_null_termination(), view.length())) + : m_impl(*StringImpl::create(view.characters_without_null_termination(), view.length())) { } @@ -55,20 +58,21 @@ public: DeprecatedString(DeprecatedString&& other) : m_impl(move(other.m_impl)) { + other.m_impl = StringImpl::the_empty_stringimpl(); } DeprecatedString(char const* cstring, ShouldChomp shouldChomp = NoChomp) - : m_impl(StringImpl::create(cstring, shouldChomp)) + : m_impl(*StringImpl::create(cstring, shouldChomp)) { } DeprecatedString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp) - : m_impl(StringImpl::create(cstring, length, shouldChomp)) + : m_impl(*StringImpl::create(cstring, length, shouldChomp)) { } explicit DeprecatedString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp) - : m_impl(StringImpl::create(bytes, shouldChomp)) + : m_impl(*StringImpl::create(bytes, shouldChomp)) { } @@ -77,18 +81,8 @@ public: { } - DeprecatedString(StringImpl const* impl) - : m_impl(impl) - { - } - - DeprecatedString(RefPtr&& impl) - : m_impl(move(impl)) - { - } - DeprecatedString(NonnullRefPtr&& impl) - : m_impl(move(impl)) + : m_impl(*move(impl)) { } @@ -174,31 +168,25 @@ public: [[nodiscard]] StringView substring_view(size_t start, size_t length) const; [[nodiscard]] StringView substring_view(size_t start) const; - [[nodiscard]] bool is_null() const { return !m_impl; } [[nodiscard]] ALWAYS_INLINE bool is_empty() const { return length() == 0; } - [[nodiscard]] ALWAYS_INLINE size_t length() const { return m_impl ? m_impl->length() : 0; } - // Includes NUL-terminator, if non-nullptr. - [[nodiscard]] ALWAYS_INLINE char const* characters() const { return m_impl ? m_impl->characters() : nullptr; } + [[nodiscard]] ALWAYS_INLINE size_t length() const { return m_impl->length(); } + // Includes NUL-terminator. + [[nodiscard]] ALWAYS_INLINE char const* characters() const { return m_impl->characters(); } [[nodiscard]] bool copy_characters_to_buffer(char* buffer, size_t buffer_size) const; [[nodiscard]] ALWAYS_INLINE ReadonlyBytes bytes() const { - if (m_impl) { - return m_impl->bytes(); - } - return {}; + return m_impl->bytes(); } [[nodiscard]] ALWAYS_INLINE char const& operator[](size_t i) const { - VERIFY(!is_null()); return (*m_impl)[i]; } [[nodiscard]] ALWAYS_INLINE u8 byte_at(size_t i) const { - VERIFY(!is_null()); return bit_cast((*m_impl)[i]); } @@ -251,22 +239,15 @@ public: return *this; } - DeprecatedString& operator=(nullptr_t) + template T> + DeprecatedString& operator=(T bytes) { - m_impl = nullptr; - return *this; - } - - DeprecatedString& operator=(ReadonlyBytes bytes) - { - m_impl = StringImpl::create(bytes); + m_impl = *StringImpl::create(bytes); return *this; } [[nodiscard]] u32 hash() const { - if (!m_impl) - return 0; return m_impl->hash(); } @@ -323,7 +304,7 @@ public: } private: - RefPtr m_impl; + NonnullRefPtr m_impl; }; template<> diff --git a/AK/GenericLexer.cpp b/AK/GenericLexer.cpp index 40dc0caaf7f..5061e10b6ad 100644 --- a/AK/GenericLexer.cpp +++ b/AK/GenericLexer.cpp @@ -129,7 +129,7 @@ StringView GenericLexer::consume_quoted_string(char escape_char) } #ifndef KERNEL -DeprecatedString GenericLexer::consume_and_unescape_string(char escape_char) +Optional GenericLexer::consume_and_unescape_string(char escape_char) { auto view = consume_quoted_string(escape_char); if (view.is_null()) diff --git a/AK/GenericLexer.h b/AK/GenericLexer.h index d37af0608d2..f791f92c41c 100644 --- a/AK/GenericLexer.h +++ b/AK/GenericLexer.h @@ -119,7 +119,7 @@ public: StringView consume_until(StringView); StringView consume_quoted_string(char escape_char = 0); #ifndef KERNEL - DeprecatedString consume_and_unescape_string(char escape_char = '\\'); + Optional consume_and_unescape_string(char escape_char = '\\'); #endif enum class UnicodeEscapeError { diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index 3bd729f1b35..9c0ad3279a0 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -132,8 +132,6 @@ ErrorOr JsonParser::parse_object() break; ignore_while(is_space); auto name = TRY(consume_and_unescape_string()); - if (name.is_null()) - return Error::from_string_literal("JsonParser: Expected object property name"); ignore_while(is_space); if (!consume_specific(':')) return Error::from_string_literal("JsonParser: Expected ':'"); diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index e7cc3562cd2..14166eda4dc 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -174,13 +174,9 @@ JsonValue::JsonValue(double value) JsonValue::JsonValue(DeprecatedString const& value) { - if (value.is_null()) { - m_type = Type::Null; - } else { - m_type = Type::String; - m_value.as_string = const_cast(value.impl()); - m_value.as_string->ref(); - } + m_type = Type::String; + m_value.as_string = const_cast(value.impl()); + m_value.as_string->ref(); } JsonValue::JsonValue(StringView value) diff --git a/AK/LexicalPath.cpp b/AK/LexicalPath.cpp index c50fc56b9e1..b6c2181c296 100644 --- a/AK/LexicalPath.cpp +++ b/AK/LexicalPath.cpp @@ -90,9 +90,6 @@ bool LexicalPath::is_child_of(LexicalPath const& possible_parent) const DeprecatedString LexicalPath::canonicalized_path(DeprecatedString path) { - if (path.is_null()) - return {}; - // NOTE: We never allow an empty m_string, if it's empty, we just set it to '.'. if (path.is_empty()) return "."; diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 1c7d8b6d070..69fffb5bb4e 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -47,9 +47,6 @@ NonnullRefPtr StringImpl::create_uninitialized(size_t length, RefPtr StringImpl::create(char const* cstring, size_t length, ShouldChomp should_chomp) { - if (!cstring) - return nullptr; - if (should_chomp) { while (length) { char last_ch = cstring[length - 1]; @@ -72,10 +69,7 @@ RefPtr StringImpl::create(char const* cstring, size_t length, RefPtr StringImpl::create(char const* cstring, ShouldChomp shouldChomp) { - if (!cstring) - return nullptr; - - if (!*cstring) + if (!cstring || !*cstring) return the_empty_stringimpl(); return create(cstring, strlen(cstring), shouldChomp); @@ -88,8 +82,6 @@ RefPtr StringImpl::create(ReadonlyBytes bytes, ShouldChomp sho RefPtr StringImpl::create_lowercased(char const* cstring, size_t length) { - if (!cstring) - return nullptr; if (!length) return the_empty_stringimpl(); char* buffer; @@ -101,8 +93,6 @@ RefPtr StringImpl::create_lowercased(char const* cstring, size RefPtr StringImpl::create_uppercased(char const* cstring, size_t length) { - if (!cstring) - return nullptr; if (!length) return the_empty_stringimpl(); char* buffer; diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 66d8d54ab27..92ffe4fe94c 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -178,12 +178,12 @@ bool StringView::equals_ignoring_ascii_case(StringView other) const #ifndef KERNEL DeprecatedString StringView::to_lowercase_string() const { - return StringImpl::create_lowercased(characters_without_null_termination(), length()); + return StringImpl::create_lowercased(characters_without_null_termination(), length()).release_nonnull(); } DeprecatedString StringView::to_uppercase_string() const { - return StringImpl::create_uppercased(characters_without_null_termination(), length()); + return StringImpl::create_uppercased(characters_without_null_termination(), length()).release_nonnull(); } DeprecatedString StringView::to_titlecase_string() const diff --git a/AK/URL.cpp b/AK/URL.cpp index 61f965e720c..9d90a5d3f23 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -191,13 +191,11 @@ URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString URL url; url.set_scheme("file"_string); - // NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string. - // This is because a file URL always needs a non-null hostname. - url.set_host(hostname.is_null() || hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors()); + url.set_host(hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors()); url.set_paths(lexical_path.parts()); if (path.ends_with('/')) url.append_slash(); - if (!fragment.is_null()) + if (!fragment.is_empty()) url.set_fragment(String::from_deprecated_string(fragment).release_value_but_fixme_should_propagate_errors()); return url; } @@ -208,14 +206,12 @@ URL URL::create_with_help_scheme(DeprecatedString const& path, DeprecatedString URL url; url.set_scheme("help"_string); - // NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string. - // This is because a file URL always needs a non-null hostname. - url.set_host(hostname.is_null() || hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors()); + url.set_host(hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors()); url.set_paths(lexical_path.parts()); if (path.ends_with('/')) url.append_slash(); - if (!fragment.is_null()) + if (!fragment.is_empty()) url.set_fragment(String::from_deprecated_string(fragment).release_value_but_fixme_should_propagate_errors()); return url; } diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp index 273d0e70dbf..adda62b3cd1 100644 --- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp @@ -311,7 +311,7 @@ void do_message(SourceGenerator message_generator, DeprecatedString const& name, class @message.pascal_name@ final : public IPC::Message { public:)~~~"); - if (!response_type.is_null()) + if (!response_type.is_empty()) message_generator.appendln(R"~~~( typedef class @message.response_type@ ResponseType;)~~~"); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index c0fed26f0de..9d59ea556d9 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -785,7 +785,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter } i++; } - if (current_dictionary->parent_name.is_null()) + if (current_dictionary->parent_name.is_empty()) break; VERIFY(interface.dictionaries.contains(current_dictionary->parent_name)); current_dictionary = &interface.dictionaries.find(current_dictionary->parent_name)->value; @@ -1755,7 +1755,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString )~~~"); } - if (current_dictionary->parent_name.is_null()) + if (current_dictionary->parent_name.is_empty()) break; VERIFY(interface.dictionaries.contains(current_dictionary->parent_name)); current_dictionary = &interface.dictionaries.find(current_dictionary->parent_name)->value; @@ -2352,7 +2352,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu if (attribute.extended_attributes.contains("Reflect")) { auto attribute_name = attribute.extended_attributes.get("Reflect").value(); - if (attribute_name.is_null()) + if (attribute_name.is_empty()) attribute_name = attribute.name; attribute_name = make_input_acceptable_cpp(attribute_name); @@ -2837,7 +2837,7 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm) if (attribute.extended_attributes.contains("Reflect")) { auto attribute_name = attribute.extended_attributes.get("Reflect").value(); - if (attribute_name.is_null()) + if (attribute_name.is_empty()) attribute_name = attribute.name; attribute_name = make_input_acceptable_cpp(attribute_name); diff --git a/Meta/Lagom/Tools/IPCMagicLinter/main.cpp b/Meta/Lagom/Tools/IPCMagicLinter/main.cpp index 133bbc410db..e79937ee416 100644 --- a/Meta/Lagom/Tools/IPCMagicLinter/main.cpp +++ b/Meta/Lagom/Tools/IPCMagicLinter/main.cpp @@ -52,7 +52,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (!line.starts_with("endpoint "sv)) continue; auto line_endpoint_name = line.substring_view("endpoint "sv.length()); - if (!endpoint_name.is_null()) { + if (!endpoint_name.is_empty()) { // Note: If there are three or more endpoints defined in a file, these errors will look a bit wonky. // However, that's fine, because it shouldn't happen in the first place. warnln("Error: Multiple endpoints in file '{}': Found {} and {}", filename, endpoint_name, line_endpoint_name); @@ -72,7 +72,7 @@ ErrorOr serenity_main(Main::Arguments arguments) had_errors = true; continue; // next file } - if (endpoint_name.is_null()) { + if (endpoint_name.is_empty()) { // If this happens, this file probably needs to parse the endpoint name more carefully. warnln("Error: Could not detect endpoint name in file '{}'", filename); had_errors = true; diff --git a/Tests/AK/TestCircularDeque.cpp b/Tests/AK/TestCircularDeque.cpp index 8346eca2daa..55da938080f 100644 --- a/Tests/AK/TestCircularDeque.cpp +++ b/Tests/AK/TestCircularDeque.cpp @@ -41,7 +41,7 @@ TEST_CASE(enqueue_begin_being_moved_from) DeprecatedString str { "test" }; strings.enqueue_begin(move(str)); - EXPECT(str.is_null()); + EXPECT(str.is_empty()); } TEST_CASE(deque_end) diff --git a/Tests/AK/TestDeprecatedString.cpp b/Tests/AK/TestDeprecatedString.cpp index 0b6687f4064..1add9f16405 100644 --- a/Tests/AK/TestDeprecatedString.cpp +++ b/Tests/AK/TestDeprecatedString.cpp @@ -14,11 +14,9 @@ TEST_CASE(construct_empty) { - EXPECT(DeprecatedString().is_null()); EXPECT(DeprecatedString().is_empty()); - EXPECT(!DeprecatedString().characters()); + EXPECT(DeprecatedString().characters() != nullptr); - EXPECT(!DeprecatedString("").is_null()); EXPECT(DeprecatedString("").is_empty()); EXPECT(DeprecatedString("").characters() != nullptr); @@ -29,7 +27,6 @@ TEST_CASE(construct_contents) { DeprecatedString test_string = "ABCDEF"; EXPECT(!test_string.is_empty()); - EXPECT(!test_string.is_null()); EXPECT_EQ(test_string.length(), 6u); EXPECT_EQ(test_string.length(), strlen(test_string.characters())); EXPECT(test_string.characters() != nullptr); @@ -42,7 +39,7 @@ TEST_CASE(construct_contents) TEST_CASE(equal) { - EXPECT_NE(DeprecatedString::empty(), DeprecatedString {}); + EXPECT_EQ(DeprecatedString::empty(), DeprecatedString {}); } TEST_CASE(compare) @@ -116,7 +113,7 @@ TEST_CASE(move_string) auto test_string_copy = test_string; auto test_string_move = move(test_string_copy); EXPECT_EQ(test_string, test_string_move); - EXPECT(test_string_copy.is_null()); + EXPECT(test_string_copy.is_empty()); } TEST_CASE(repeated) @@ -253,7 +250,6 @@ TEST_CASE(builder_zero_initial_capacity) StringBuilder builder(0); builder.append(""sv); auto built = builder.to_deprecated_string(); - EXPECT_EQ(built.is_null(), false); EXPECT_EQ(built.length(), 0u); } diff --git a/Tests/AK/TestHashMap.cpp b/Tests/AK/TestHashMap.cpp index 8b274c7acb1..df7c5560a89 100644 --- a/Tests/AK/TestHashMap.cpp +++ b/Tests/AK/TestHashMap.cpp @@ -49,7 +49,7 @@ TEST_CASE(range_loop) int loop_counter = 0; for (auto& it : number_to_string) { - EXPECT_EQ(it.value.is_null(), false); + EXPECT_EQ(it.value.is_empty(), false); ++loop_counter; } EXPECT_EQ(loop_counter, 3); diff --git a/Tests/AK/TestHashTable.cpp b/Tests/AK/TestHashTable.cpp index c399418b7b5..a6e18845eda 100644 --- a/Tests/AK/TestHashTable.cpp +++ b/Tests/AK/TestHashTable.cpp @@ -64,7 +64,7 @@ TEST_CASE(range_loop) int loop_counter = 0; for (auto& it : strings) { - EXPECT_EQ(it.is_null(), false); + EXPECT_EQ(it.is_empty(), false); ++loop_counter; } EXPECT_EQ(loop_counter, 3); diff --git a/Tests/AK/TestJSON.cpp b/Tests/AK/TestJSON.cpp index 8fecf333a5a..7527868ae7e 100644 --- a/Tests/AK/TestJSON.cpp +++ b/Tests/AK/TestJSON.cpp @@ -60,7 +60,6 @@ TEST_CASE(json_empty_string) { auto json = JsonValue::from_string("\"\""sv).value(); EXPECT_EQ(json.type(), JsonValue::Type::String); - EXPECT_EQ(json.as_string().is_null(), false); EXPECT_EQ(json.as_string().is_empty(), true); } @@ -68,7 +67,6 @@ TEST_CASE(json_string) { auto json = JsonValue::from_string("\"A\""sv).value(); EXPECT_EQ(json.type(), JsonValue::Type::String); - EXPECT_EQ(json.as_string().is_null(), false); EXPECT_EQ(json.as_string().length(), size_t { 1 }); EXPECT_EQ(json.as_string() == "A", true); } @@ -77,7 +75,6 @@ TEST_CASE(json_utf8_character) { auto json = JsonValue::from_string("\"\\u0041\""sv).value(); EXPECT_EQ(json.type(), JsonValue::Type::String); - EXPECT_EQ(json.as_string().is_null(), false); EXPECT_EQ(json.as_string().length(), size_t { 1 }); EXPECT_EQ(json.as_string() == "A", true); } @@ -92,7 +89,6 @@ TEST_CASE(json_utf8_multibyte) auto& json = json_or_error.value(); EXPECT_EQ(json.type(), JsonValue::Type::String); - EXPECT_EQ(json.as_string().is_null(), false); EXPECT_EQ(json.as_string().length(), size_t { 2 }); EXPECT_EQ(json.as_string() == "š", true); EXPECT_EQ(json.as_string() == "\xc5\xa1", true); diff --git a/Tests/AK/TestVector.cpp b/Tests/AK/TestVector.cpp index 5e63dee85d8..edbd451dd78 100644 --- a/Tests/AK/TestVector.cpp +++ b/Tests/AK/TestVector.cpp @@ -44,14 +44,12 @@ TEST_CASE(strings) int loop_counter = 0; for (DeprecatedString const& string : strings) { - EXPECT(!string.is_null()); EXPECT(!string.is_empty()); ++loop_counter; } loop_counter = 0; for (auto& string : (const_cast const&>(strings))) { - EXPECT(!string.is_null()); EXPECT(!string.is_empty()); ++loop_counter; } diff --git a/Tests/LibC/TestRealpath.cpp b/Tests/LibC/TestRealpath.cpp index 86c259f66b1..613858fc9cf 100644 --- a/Tests/LibC/TestRealpath.cpp +++ b/Tests/LibC/TestRealpath.cpp @@ -21,7 +21,7 @@ static constexpr char PATH_LOREM_250[] = "This-is-an-annoyingly-long-name-that-s static constexpr size_t ITERATION_DEPTH = 17; -static void check_result(char const* what, DeprecatedString const& expected, char const* actual) +static void check_result(char const* what, StringView expected, char const* actual) { if (expected != actual) FAIL(DeprecatedString::formatted("Expected {} to be \"{}\" ({} characters)", what, actual, actual ? strlen(actual) : 0)); diff --git a/Tests/LibJS/test262-runner.cpp b/Tests/LibJS/test262-runner.cpp index 68f5e26907a..2eb837c23f4 100644 --- a/Tests/LibJS/test262-runner.cpp +++ b/Tests/LibJS/test262-runner.cpp @@ -337,7 +337,7 @@ static Result extract_metadata(StringView source failed_message = "Failed to find phase in negative attributes"; break; } - if (metadata.type.is_null()) { + if (metadata.type.is_empty()) { failed_message = "Failed to find type in negative attributes"; break; } @@ -640,7 +640,7 @@ int main(int argc, char** argv) auto collect_output = [&] { fflush(stdout); auto nread = read(stdout_pipe[0], buffer, BUFFER_SIZE); - DeprecatedString value; + Optional value; if (nread > 0) { value = DeprecatedString { buffer, static_cast(nread) }; @@ -743,15 +743,16 @@ int main(int argc, char** argv) auto result = run_test(original_contents, path, metadata); DISARM_TIMER(); - DeprecatedString first_output = collect_output(); - if (!first_output.is_null()) - result_object.set("output", first_output); + auto first_output = collect_output(); + if (first_output.has_value()) + result_object.set("output", *first_output); passed = verify_test(result, metadata, result_object); + auto output = first_output.value_or(""); if (metadata.is_async && !s_parse_only) { - if (!first_output.contains("Test262:AsyncTestComplete"sv) || first_output.contains("Test262:AsyncTestFailure"sv)) { + if (!output.contains("Test262:AsyncTestComplete"sv) || output.contains("Test262:AsyncTestFailure"sv)) { result_object.set("async_fail", true); - if (first_output.is_null()) + if (!first_output.has_value()) result_object.set("output", JsonValue { AK::JsonValue::Type::Null }); passed = false; @@ -766,15 +767,17 @@ int main(int argc, char** argv) auto result = run_test(with_strict, path, metadata); DISARM_TIMER(); - DeprecatedString first_output = collect_output(); - if (!first_output.is_null()) - result_object.set("strict_output", first_output); + auto first_output = collect_output(); + if (first_output.has_value()) + result_object.set("strict_output", *first_output); passed = verify_test(result, metadata, result_object); + auto output = first_output.value_or(""); + if (metadata.is_async && !s_parse_only) { - if (!first_output.contains("Test262:AsyncTestComplete"sv) || first_output.contains("Test262:AsyncTestFailure"sv)) { + if (!output.contains("Test262:AsyncTestComplete"sv) || output.contains("Test262:AsyncTestFailure"sv)) { result_object.set("async_fail", true); - if (first_output.is_null()) + if (!first_output.has_value()) result_object.set("output", JsonValue { AK::JsonValue::Type::Null }); passed = false; diff --git a/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp b/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp index 6c99ecd4679..39b2c52438f 100644 --- a/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp @@ -141,7 +141,7 @@ static ErrorOr display_name_from_edid(EDID::Parser const& edid) auto product_name = edid.display_product_name(); auto build_manufacturer_product_name = [&]() -> ErrorOr { - if (product_name.is_null() || product_name.is_empty()) + if (product_name.is_empty()) return TRY(String::from_deprecated_string(manufacturer_name)); return String::formatted("{} {}", manufacturer_name, product_name); }; diff --git a/Userland/Applications/Mail/MailWidget.cpp b/Userland/Applications/Mail/MailWidget.cpp index 689742582aa..5a095a137e8 100644 --- a/Userland/Applications/Mail/MailWidget.cpp +++ b/Userland/Applications/Mail/MailWidget.cpp @@ -319,7 +319,7 @@ void MailWidget::selected_mailbox(GUI::ModelIndex const& index) DeprecatedString date = internal_date.to_deprecated_string(); DeprecatedString subject = envelope.subject.value_or("(No subject)"); if (subject.contains("=?"sv) && subject.contains("?="sv)) { - subject = MUST(IMAP::decode_rfc2047_encoded_words(subject)); + subject = MUST(IMAP::decode_rfc2047_encoded_words(subject)).span(); } StringBuilder sender_builder; @@ -491,9 +491,9 @@ void MailWidget::selected_email_to_load(GUI::ModelIndex const& index) } else if (selected_alternative_encoding.equals_ignoring_ascii_case("base64"sv)) { auto decoded_base64 = decode_base64(encoded_data); if (!decoded_base64.is_error()) - decoded_data = decoded_base64.release_value(); + decoded_data = decoded_base64.release_value().span(); } else if (selected_alternative_encoding.equals_ignoring_ascii_case("quoted-printable"sv)) { - decoded_data = IMAP::decode_quoted_printable(encoded_data).release_value_but_fixme_should_propagate_errors(); + decoded_data = IMAP::decode_quoted_printable(encoded_data).release_value_but_fixme_should_propagate_errors().span(); } else { dbgln("Mail: Unimplemented decoder for encoding: {}", selected_alternative_encoding); GUI::MessageBox::show(window(), DeprecatedString::formatted("The e-mail encoding '{}' is currently unsupported.", selected_alternative_encoding), "Unsupported"sv, GUI::MessageBox::Type::Information); diff --git a/Userland/Applications/NetworkSettings/main.cpp b/Userland/Applications/NetworkSettings/main.cpp index cdd4998d66f..e963ea41dd5 100644 --- a/Userland/Applications/NetworkSettings/main.cpp +++ b/Userland/Applications/NetworkSettings/main.cpp @@ -24,7 +24,7 @@ ErrorOr serenity_main(Main::Arguments args) TRY(Core::System::unveil("/tmp/portal/window", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); - DeprecatedString adapter; + StringView adapter; Core::ArgsParser parser; parser.add_positional_argument(adapter, "Adapter to display settings for", "adapter", Core::ArgsParser::Required::No); diff --git a/Userland/Applications/SoundPlayer/M3UParser.cpp b/Userland/Applications/SoundPlayer/M3UParser.cpp index 26f7f40618d..a5778592ebd 100644 --- a/Userland/Applications/SoundPlayer/M3UParser.cpp +++ b/Userland/Applications/SoundPlayer/M3UParser.cpp @@ -26,7 +26,7 @@ NonnullOwnPtr M3UParser::from_file(StringView path) NonnullOwnPtr M3UParser::from_memory(DeprecatedString const& m3u_contents, bool utf8) { auto parser = make(); - VERIFY(!m3u_contents.is_null() && !m3u_contents.is_empty() && !m3u_contents.is_whitespace()); + VERIFY(!m3u_contents.is_empty() && !m3u_contents.is_whitespace()); parser->m_m3u_raw_data = m3u_contents; parser->m_use_utf8 = utf8; return parser; diff --git a/Userland/Applications/SoundPlayer/Player.cpp b/Userland/Applications/SoundPlayer/Player.cpp index 87946d5297c..3ff8c2ae891 100644 --- a/Userland/Applications/SoundPlayer/Player.cpp +++ b/Userland/Applications/SoundPlayer/Player.cpp @@ -40,9 +40,6 @@ Player::Player(Audio::ConnectionToServer& audio_client_connection) void Player::play_file_path(DeprecatedString const& path) { - if (path.is_null()) - return; - if (!FileSystem::exists(path)) { audio_load_error(path, "File does not exist"sv); return; diff --git a/Userland/Applications/Spreadsheet/SpreadsheetView.cpp b/Userland/Applications/Spreadsheet/SpreadsheetView.cpp index 039cbefce91..a9210ce9ab8 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetView.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetView.cpp @@ -22,7 +22,7 @@ namespace Spreadsheet { void SpreadsheetView::EditingDelegate::set_value(GUI::Variant const& value, GUI::ModelEditingDelegate::SelectionBehavior selection_behavior) { - if (value.as_string().is_null()) { + if (!value.is_valid()) { StringModelEditingDelegate::set_value("", selection_behavior); commit(); return; diff --git a/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp b/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp index f907d605c7c..8d6c6246e6b 100644 --- a/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp +++ b/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp @@ -74,7 +74,7 @@ void MemoryStatsWidget::set_graph_widget(GraphWidget& graph) void MemoryStatsWidget::set_graph_widget_via_name(DeprecatedString name) { m_graph_widget_name = move(name); - if (!m_graph_widget_name.is_null()) { + if (!m_graph_widget_name.is_empty()) { // FIXME: We assume here that the graph widget is a sibling or descendant of a sibling. This prevents more complex hierarchies. auto* maybe_graph = parent_widget()->find_descendant_of_type_named(m_graph_widget_name); if (maybe_graph) { diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index a186297d276..b256d6662db 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -279,7 +279,7 @@ MainWidget::MainWidget() m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) { auto extension = m_extension; - if (extension.is_null() && m_editor->syntax_highlighter()) + if (extension.is_empty() && m_editor->syntax_highlighter()) extension = Syntax::common_language_extension(m_editor->syntax_highlighter()->language()); auto response = FileSystemAccessClient::Client::the().save_file(window(), m_name, extension); diff --git a/Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp b/Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp index a600e0e1497..c6835f0e7ae 100644 --- a/Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp +++ b/Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp @@ -47,7 +47,7 @@ Vector BacktraceModel::create_backtrace(Debug::Proces if (frame_index > 0) --current_instruction; DeprecatedString name = lib->debug_info->elf().symbolicate(current_instruction - lib->base_address); - if (name.is_null()) { + if (name.is_empty()) { dbgln("BacktraceModel: couldn't find containing function for address: {:p} (library={})", current_instruction, lib->name); name = ""; } diff --git a/Userland/DevTools/HackStudio/Debugger/Debugger.cpp b/Userland/DevTools/HackStudio/Debugger/Debugger.cpp index 2ab1a0cbc89..9664029552a 100644 --- a/Userland/DevTools/HackStudio/Debugger/Debugger.cpp +++ b/Userland/DevTools/HackStudio/Debugger/Debugger.cpp @@ -134,7 +134,7 @@ void Debugger::start() Debugger::CreateDebugSessionResult Debugger::create_debug_session() { - if (!m_executable_path.is_null()) { + if (!m_executable_path.is_empty()) { auto child_setup_callback = [this]() { if (m_child_setup_callback) return m_child_setup_callback(); diff --git a/Userland/DevTools/HackStudio/EditorWrapper.cpp b/Userland/DevTools/HackStudio/EditorWrapper.cpp index ca6d4a63c2a..b52ad842db9 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.cpp +++ b/Userland/DevTools/HackStudio/EditorWrapper.cpp @@ -113,7 +113,7 @@ void EditorWrapper::set_project_root(DeprecatedString const& project_root) void EditorWrapper::update_title() { StringBuilder title; - if (m_filename.is_null()) + if (m_filename.is_empty()) title.append(untitled_label); else title.append(m_filename); diff --git a/Userland/DevTools/HackStudio/Git/GitRepo.cpp b/Userland/DevTools/HackStudio/Git/GitRepo.cpp index 2fb11b2021c..7b3b0e9ba1e 100644 --- a/Userland/DevTools/HackStudio/Git/GitRepo.cpp +++ b/Userland/DevTools/HackStudio/Git/GitRepo.cpp @@ -24,7 +24,7 @@ GitRepo::CreateResult GitRepo::try_to_create(DeprecatedString const& repository_ RefPtr GitRepo::initialize_repository(DeprecatedString const& repository_root) { auto res = command_wrapper({ "init" }, repository_root); - if (res.is_null()) + if (!res.has_value()) return {}; VERIFY(git_repo_exists(repository_root)); @@ -42,25 +42,25 @@ Vector GitRepo::unstaged_files() const Vector GitRepo::staged_files() const { auto raw_result = command({ "diff", "--cached", "--name-only" }); - if (raw_result.is_null()) + if (!raw_result.has_value()) return {}; - return parse_files_list(raw_result); + return parse_files_list(*raw_result); } Vector GitRepo::modified_files() const { auto raw_result = command({ "ls-files", "--modified", "--exclude-standard" }); - if (raw_result.is_null()) + if (!raw_result.has_value()) return {}; - return parse_files_list(raw_result); + return parse_files_list(*raw_result); } Vector GitRepo::untracked_files() const { auto raw_result = command({ "ls-files", "--others", "--exclude-standard" }); - if (raw_result.is_null()) + if (!raw_result.has_value()) return {}; - return parse_files_list(raw_result); + return parse_files_list(*raw_result); } Vector GitRepo::parse_files_list(DeprecatedString const& raw_result) @@ -73,12 +73,12 @@ Vector GitRepo::parse_files_list(DeprecatedString const& raw_r return files; } -DeprecatedString GitRepo::command(Vector const& command_parts) const +Optional GitRepo::command(Vector const& command_parts) const { return command_wrapper(command_parts, m_repository_root); } -DeprecatedString GitRepo::command_wrapper(Vector const& command_parts, DeprecatedString const& chdir) +Optional GitRepo::command_wrapper(Vector const& command_parts, DeprecatedString const& chdir) { auto const result = Core::command("git", command_parts, LexicalPath(chdir)); if (result.is_error() || result.value().exit_code != 0) @@ -88,27 +88,27 @@ DeprecatedString GitRepo::command_wrapper(Vector const& comman bool GitRepo::git_is_installed() { - return !command_wrapper({ "--help" }, "/").is_null(); + return command_wrapper({ "--help" }, "/").has_value(); } bool GitRepo::git_repo_exists(DeprecatedString const& repo_root) { - return !command_wrapper({ "status" }, repo_root).is_null(); + return command_wrapper({ "status" }, repo_root).has_value(); } bool GitRepo::stage(DeprecatedString const& file) { - return !command({ "add", file }).is_null(); + return command({ "add", file }).has_value(); } bool GitRepo::unstage(DeprecatedString const& file) { - return !command({ "reset", "HEAD", "--", file }).is_null(); + return command({ "reset", "HEAD", "--", file }).has_value(); } bool GitRepo::commit(DeprecatedString const& message) { - return !command({ "commit", "-m", message }).is_null(); + return command({ "commit", "-m", message }).has_value(); } Optional GitRepo::original_file_content(DeprecatedString const& file) const @@ -124,10 +124,10 @@ Optional GitRepo::unstaged_diff(DeprecatedString const& file) bool GitRepo::is_tracked(DeprecatedString const& file) const { auto res = command({ "ls-files", file }); - if (res.is_null()) + if (!res.has_value()) return false; - return !res.is_empty(); + return !res->is_empty(); } } diff --git a/Userland/DevTools/HackStudio/Git/GitRepo.h b/Userland/DevTools/HackStudio/Git/GitRepo.h index dec84e76fdd..e4598359ca1 100644 --- a/Userland/DevTools/HackStudio/Git/GitRepo.h +++ b/Userland/DevTools/HackStudio/Git/GitRepo.h @@ -45,7 +45,7 @@ private: static bool git_is_installed(); static bool git_repo_exists(DeprecatedString const& repo_root); - static DeprecatedString command_wrapper(Vector const& command_parts, DeprecatedString const& chdir); + static Optional command_wrapper(Vector const& command_parts, DeprecatedString const& chdir); static Vector parse_files_list(DeprecatedString const&); explicit GitRepo(DeprecatedString const& repository_root) @@ -56,7 +56,7 @@ private: Vector modified_files() const; Vector untracked_files() const; - DeprecatedString command(Vector const& command_parts) const; + Optional command(Vector const& command_parts) const; DeprecatedString m_repository_root; }; diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index db322fc706a..2305984657f 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -909,15 +909,15 @@ NonnullRefPtr HackStudioWidget::create_save_as_action() auto suggested_path = FileSystem::absolute_path(old_path.string()).release_value_but_fixme_should_propagate_errors(); Optional save_path = GUI::FilePicker::get_save_filepath(window(), - old_filename.is_null() ? "Untitled"sv : old_path.title(), - old_filename.is_null() ? "txt"sv : old_path.extension(), + old_filename.is_empty() ? "Untitled"sv : old_path.title(), + old_filename.is_empty() ? "txt"sv : old_path.extension(), suggested_path); if (!save_path.has_value()) { return; } DeprecatedString const relative_file_path = LexicalPath::relative_path(save_path.value(), m_project->root_path()); - if (current_editor_wrapper().filename().is_null()) { + if (current_editor_wrapper().filename().is_empty()) { current_editor_wrapper().set_filename(relative_file_path); } else { for (auto& editor_wrapper : m_all_editor_wrappers) { @@ -1729,7 +1729,7 @@ void HackStudioWidget::update_current_editor_title() void HackStudioWidget::on_cursor_change() { update_statusbar(); - if (current_editor_wrapper().filename().is_null()) + if (current_editor_wrapper().filename().is_empty()) return; auto current_location = current_project_location(); diff --git a/Userland/DevTools/HackStudio/LanguageServers/FileDB.cpp b/Userland/DevTools/HackStudio/LanguageServers/FileDB.cpp index 15673d56a5c..5bfb6448c89 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/FileDB.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/FileDB.cpp @@ -68,9 +68,9 @@ DeprecatedString FileDB::to_absolute_path(DeprecatedString const& filename) cons if (LexicalPath { filename }.is_absolute()) { return filename; } - if (m_project_root.is_null()) + if (!m_project_root.has_value()) return filename; - return LexicalPath { DeprecatedString::formatted("{}/{}", m_project_root, filename) }.string(); + return LexicalPath { DeprecatedString::formatted("{}/{}", *m_project_root, filename) }.string(); } ErrorOr> FileDB::create_from_filesystem(DeprecatedString const& filename) const diff --git a/Userland/DevTools/HackStudio/LanguageServers/FileDB.h b/Userland/DevTools/HackStudio/LanguageServers/FileDB.h index 02f25c3ff9f..35b743306d0 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/FileDB.h +++ b/Userland/DevTools/HackStudio/LanguageServers/FileDB.h @@ -38,7 +38,7 @@ private: private: HashMap> m_open_files; - DeprecatedString m_project_root; + Optional m_project_root; }; } diff --git a/Userland/DevTools/HackStudio/Locator.cpp b/Userland/DevTools/HackStudio/Locator.cpp index ef602d6804a..582bc2ff0a1 100644 --- a/Userland/DevTools/HackStudio/Locator.cpp +++ b/Userland/DevTools/HackStudio/Locator.cpp @@ -60,7 +60,7 @@ public: } if (suggestion.is_symbol_declaration()) { if (index.column() == Column::Name) { - if (suggestion.as_symbol_declaration.value().scope.is_null()) + if (!suggestion.as_symbol_declaration.value().scope.is_empty()) return suggestion.as_symbol_declaration.value().name; return DeprecatedString::formatted("{}::{}", suggestion.as_symbol_declaration.value().scope, suggestion.as_symbol_declaration.value().name); } diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index 23b8becf3f2..028776c1813 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -881,17 +881,17 @@ void sync() syscall(SC_sync); } -static DeprecatedString getlogin_buffer; +static Optional getlogin_buffer {}; char* getlogin() { - if (getlogin_buffer.is_null()) { + if (!getlogin_buffer.has_value()) { if (auto* passwd = getpwuid(getuid())) { getlogin_buffer = DeprecatedString(passwd->pw_name); } endpwent(); } - return const_cast(getlogin_buffer.characters()); + return const_cast(getlogin_buffer->characters()); } // https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html diff --git a/Userland/Libraries/LibCodeComprehension/Cpp/CppComprehensionEngine.cpp b/Userland/Libraries/LibCodeComprehension/Cpp/CppComprehensionEngine.cpp index ceb5203894d..4d793d1d63f 100644 --- a/Userland/Libraries/LibCodeComprehension/Cpp/CppComprehensionEngine.cpp +++ b/Userland/Libraries/LibCodeComprehension/Cpp/CppComprehensionEngine.cpp @@ -210,7 +210,7 @@ Vector CppComprehensionEngine::autoc { VERIFY(parent.object()); auto type = type_of(document, *parent.object()); - if (type.is_null()) { + if (type.is_empty()) { dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "Could not infer type of object"); return {}; } @@ -385,7 +385,7 @@ DeprecatedString CppComprehensionEngine::document_path_from_include_path(StringV }; auto result = document_path_for_library_include(include_path); - if (result.is_null()) + if (result.is_empty()) result = document_path_for_user_defined_include(include_path); return result; @@ -703,7 +703,7 @@ Optional> CppComprehensionEng partial_include = partial_include.substring_view(0, partial_include.length() - 1).trim_whitespace(); } } else if (partial_include.starts_with('"')) { - include_root = filedb().project_root(); + include_root = filedb().project_root().value_or(""); if (partial_include.length() > 1 && partial_include.ends_with('\"')) { already_has_suffix = true; partial_include = partial_include.substring_view(0, partial_include.length() - 1).trim_whitespace(); diff --git a/Userland/Libraries/LibCodeComprehension/Cpp/Tests.cpp b/Userland/Libraries/LibCodeComprehension/Cpp/Tests.cpp index f17ce2e9d74..84a7774ab04 100644 --- a/Userland/Libraries/LibCodeComprehension/Cpp/Tests.cpp +++ b/Userland/Libraries/LibCodeComprehension/Cpp/Tests.cpp @@ -52,8 +52,8 @@ public: virtual Optional get_or_read_from_filesystem(StringView filename) const override { DeprecatedString target_filename = filename; - if (!project_root().is_null() && filename.starts_with(project_root())) { - target_filename = LexicalPath::relative_path(filename, project_root()); + if (project_root().has_value() && filename.starts_with(*project_root())) { + target_filename = LexicalPath::relative_path(filename, *project_root()); } return m_map.get(target_filename); } diff --git a/Userland/Libraries/LibCodeComprehension/FileDB.cpp b/Userland/Libraries/LibCodeComprehension/FileDB.cpp index 64edd56918f..684527c366f 100644 --- a/Userland/Libraries/LibCodeComprehension/FileDB.cpp +++ b/Userland/Libraries/LibCodeComprehension/FileDB.cpp @@ -14,9 +14,9 @@ DeprecatedString FileDB::to_absolute_path(StringView filename) const if (LexicalPath { filename }.is_absolute()) { return filename; } - if (m_project_root.is_null()) + if (!m_project_root.has_value()) return filename; - return LexicalPath { DeprecatedString::formatted("{}/{}", m_project_root, filename) }.string(); + return LexicalPath { DeprecatedString::formatted("{}/{}", *m_project_root, filename) }.string(); } } diff --git a/Userland/Libraries/LibCodeComprehension/FileDB.h b/Userland/Libraries/LibCodeComprehension/FileDB.h index 19495ae86ad..1947be59a28 100644 --- a/Userland/Libraries/LibCodeComprehension/FileDB.h +++ b/Userland/Libraries/LibCodeComprehension/FileDB.h @@ -19,15 +19,21 @@ public: virtual ~FileDB() = default; virtual Optional get_or_read_from_filesystem(StringView filename) const = 0; - void set_project_root(StringView project_root) { m_project_root = project_root; } - DeprecatedString const& project_root() const { return m_project_root; } + void set_project_root(StringView project_root) + { + if (project_root.is_null()) + m_project_root.clear(); + else + m_project_root = project_root; + } + Optional const& project_root() const { return m_project_root; } DeprecatedString to_absolute_path(StringView filename) const; protected: FileDB() = default; private: - DeprecatedString m_project_root; + Optional m_project_root; }; } diff --git a/Userland/Libraries/LibCore/Account.cpp b/Userland/Libraries/LibCore/Account.cpp index f62381cff55..031524c421d 100644 --- a/Userland/Libraries/LibCore/Account.cpp +++ b/Userland/Libraries/LibCore/Account.cpp @@ -162,16 +162,17 @@ ErrorOr> Account::all([[maybe_unused]] Read options) bool Account::authenticate(SecretString const& password) const { // If there was no shadow entry for this account, authentication always fails. - if (m_password_hash.is_null()) + if (!m_password_hash.has_value()) return false; // An empty passwd field indicates that no password is required to log in. - if (m_password_hash.is_empty()) + if (m_password_hash->is_empty()) return true; // FIXME: Use crypt_r if it can be built in lagom. - char* hash = crypt(password.characters(), m_password_hash.characters()); - return hash != nullptr && AK::timing_safe_compare(hash, m_password_hash.characters(), m_password_hash.length()); + auto const bytes = m_password_hash->characters(); + char* hash = crypt(password.characters(), bytes); + return hash != nullptr && AK::timing_safe_compare(hash, bytes, m_password_hash->length()); } ErrorOr Account::login() const @@ -190,24 +191,25 @@ void Account::set_password(SecretString const& password) void Account::set_password_enabled(bool enabled) { - if (enabled && m_password_hash != "" && m_password_hash[0] == '!') { - m_password_hash = m_password_hash.substring(1, m_password_hash.length() - 1); - } else if (!enabled && (m_password_hash == "" || m_password_hash[0] != '!')) { + auto flattened_password_hash = m_password_hash.value_or(DeprecatedString::empty()); + if (enabled && !flattened_password_hash.is_empty() && flattened_password_hash[0] == '!') { + m_password_hash = flattened_password_hash.substring(1, flattened_password_hash.length() - 1); + } else if (!enabled && (flattened_password_hash.is_empty() || flattened_password_hash[0] != '!')) { StringBuilder builder; builder.append('!'); - builder.append(m_password_hash); + builder.append(flattened_password_hash); m_password_hash = builder.to_deprecated_string(); } } void Account::delete_password() { - m_password_hash = ""; + m_password_hash = DeprecatedString::empty(); } Account::Account(passwd const& pwd, spwd const& spwd, Vector extra_gids) : m_username(pwd.pw_name) - , m_password_hash(spwd.sp_pwdp) + , m_password_hash(spwd.sp_pwdp ? Optional(spwd.sp_pwdp) : OptionalNone {}) , m_uid(pwd.pw_uid) , m_gid(pwd.pw_gid) , m_gecos(pwd.pw_gecos) @@ -300,7 +302,7 @@ ErrorOr Account::generate_shadow_file() const if (p->sp_namp == m_username) { if (m_deleted) continue; - builder.appendff("{}:{}", m_username, m_password_hash); + builder.appendff("{}:{}", m_username, m_password_hash.value_or(DeprecatedString::empty())); } else builder.appendff("{}:{}", p->sp_namp, p->sp_pwdp); diff --git a/Userland/Libraries/LibCore/Account.h b/Userland/Libraries/LibCore/Account.h index acd9e81c4db..c371ff4fa93 100644 --- a/Userland/Libraries/LibCore/Account.h +++ b/Userland/Libraries/LibCore/Account.h @@ -41,7 +41,7 @@ public: ErrorOr login() const; DeprecatedString username() const { return m_username; } - DeprecatedString password_hash() const { return m_password_hash; } + DeprecatedString password_hash() const { return m_password_hash.value_or(DeprecatedString::empty()); } // Setters only affect in-memory copy of password. // You must call sync to apply changes. @@ -56,9 +56,9 @@ public: void set_extra_gids(Vector extra_gids) { m_extra_gids = move(extra_gids); } void delete_password(); - // A null password means that this account was missing from /etc/shadow. + // A nonexistent password means that this account was missing from /etc/shadow. // It's considered to have a password in that case, and authentication will always fail. - bool has_password() const { return !m_password_hash.is_empty() || m_password_hash.is_null(); } + bool has_password() const { return !m_password_hash.has_value() || !m_password_hash->is_empty(); } uid_t uid() const { return m_uid; } gid_t gid() const { return m_gid; } @@ -82,7 +82,7 @@ private: DeprecatedString m_username; - DeprecatedString m_password_hash; + Optional m_password_hash; uid_t m_uid { 0 }; gid_t m_gid { 0 }; DeprecatedString m_gecos; diff --git a/Userland/Libraries/LibCore/ConfigFile.cpp b/Userland/Libraries/LibCore/ConfigFile.cpp index 4086710f8c4..8e392898bae 100644 --- a/Userland/Libraries/LibCore/ConfigFile.cpp +++ b/Userland/Libraries/LibCore/ConfigFile.cpp @@ -140,11 +140,10 @@ ErrorOr ConfigFile::reparse() return {}; } -DeprecatedString ConfigFile::read_entry(DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& default_value) const +Optional ConfigFile::read_entry_optional(const AK::DeprecatedString& group, const AK::DeprecatedString& key) const { - if (!has_key(group, key)) { - return default_value; - } + if (!has_key(group, key)) + return {}; auto it = m_groups.find(group); auto jt = it->value.find(key); return jt->value; diff --git a/Userland/Libraries/LibCore/ConfigFile.h b/Userland/Libraries/LibCore/ConfigFile.h index b8e4fc246bb..b2c7a0e8495 100644 --- a/Userland/Libraries/LibCore/ConfigFile.h +++ b/Userland/Libraries/LibCore/ConfigFile.h @@ -42,7 +42,11 @@ public: size_t num_groups() const { return m_groups.size(); } - DeprecatedString read_entry(DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& default_value = DeprecatedString()) const; + DeprecatedString read_entry(DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& default_value = {}) const + { + return read_entry_optional(group, key).value_or(default_value); + } + Optional read_entry_optional(DeprecatedString const& group, DeprecatedString const& key) const; bool read_bool_entry(DeprecatedString const& group, DeprecatedString const& key, bool default_value = false) const; template @@ -52,9 +56,9 @@ public: return default_value; if constexpr (IsSigned) - return read_entry(group, key).to_int().value_or(default_value); + return read_entry(group, key, "").to_int().value_or(default_value); else - return read_entry(group, key).to_uint().value_or(default_value); + return read_entry(group, key, "").to_uint().value_or(default_value); } void write_entry(DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value); diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index c7cc62c1aae..364bb776672 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -189,29 +189,40 @@ static ErrorOr unveil_dynamic_loader() ErrorOr unveil(StringView path, StringView permissions) { - auto const parsed_path = TRY(Core::SessionManagement::parse_path_with_sid(path)); - if (permissions.contains('x')) TRY(unveil_dynamic_loader()); Syscall::SC_unveil_params params { static_cast(UnveilFlags::CurrentProgram), - { parsed_path.characters(), parsed_path.length() }, - { permissions.characters_without_null_termination(), permissions.length() }, + { nullptr, 0 }, + { nullptr, 0 }, }; + + DeprecatedString parsed_path; + if (!path.is_null()) { + parsed_path = TRY(Core::SessionManagement::parse_path_with_sid(path)); + params.path = { parsed_path.characters(), parsed_path.length() }; + params.permissions = { permissions.characters_without_null_termination(), permissions.length() }; + } + int rc = syscall(SC_unveil, ¶ms); HANDLE_SYSCALL_RETURN_VALUE("unveil", rc, {}); } ErrorOr unveil_after_exec(StringView path, StringView permissions) { - auto const parsed_path = TRY(Core::SessionManagement::parse_path_with_sid(path)); - + DeprecatedString parsed_path; Syscall::SC_unveil_params params { static_cast(UnveilFlags::AfterExec), - { parsed_path.characters(), parsed_path.length() }, + { nullptr, 0 }, { permissions.characters_without_null_termination(), permissions.length() }, }; + + if (!path.is_null()) { + parsed_path = TRY(Core::SessionManagement::parse_path_with_sid(path)); + params.path = { parsed_path.characters(), parsed_path.length() }; + } + int rc = syscall(SC_unveil, ¶ms); HANDLE_SYSCALL_RETURN_VALUE("unveil", rc, {}); } diff --git a/Userland/Libraries/LibCore/SystemServerTakeover.cpp b/Userland/Libraries/LibCore/SystemServerTakeover.cpp index 48f346560e9..f622bf20a0b 100644 --- a/Userland/Libraries/LibCore/SystemServerTakeover.cpp +++ b/Userland/Libraries/LibCore/SystemServerTakeover.cpp @@ -41,7 +41,7 @@ ErrorOr> take_over_socket_from_system_server(De parse_sockets_from_system_server(); int fd; - if (socket_path.is_null()) { + if (socket_path.is_empty()) { // We want the first (and only) socket. VERIFY(s_overtaken_sockets.size() == 1); fd = s_overtaken_sockets.begin()->value; diff --git a/Userland/Libraries/LibCpp/Preprocessor.cpp b/Userland/Libraries/LibCpp/Preprocessor.cpp index 8316be3f3ca..8a0832c7637 100644 --- a/Userland/Libraries/LibCpp/Preprocessor.cpp +++ b/Userland/Libraries/LibCpp/Preprocessor.cpp @@ -102,7 +102,7 @@ void Preprocessor::handle_preprocessor_statement(StringView line) consume_whitespace(lexer); auto keyword = lexer.consume_until(' '); lexer.ignore(); - if (keyword.is_empty() || keyword.is_null() || keyword.is_whitespace()) + if (keyword.is_empty() || keyword.is_whitespace()) return; handle_preprocessor_keyword(keyword, lexer); @@ -243,7 +243,7 @@ void Preprocessor::handle_preprocessor_keyword(StringView keyword, GenericLexer& size_t Preprocessor::do_substitution(Vector const& tokens, size_t token_index, Definition const& defined_value) { - if (defined_value.value.is_null()) + if (defined_value.value.is_empty()) return token_index; Substitution sub; diff --git a/Userland/Libraries/LibDNS/Packet.cpp b/Userland/Libraries/LibDNS/Packet.cpp index 6b75b5e9731..abe5e25cb10 100644 --- a/Userland/Libraries/LibDNS/Packet.cpp +++ b/Userland/Libraries/LibDNS/Packet.cpp @@ -161,7 +161,7 @@ Optional Packet::from_raw_packet(u8 const* raw_data, size_t raw_size) case RecordType::AAAA: // Fall through case RecordType::SRV: - data = { record.data(), record.data_length() }; + data = ReadonlyBytes { record.data(), record.data_length() }; break; default: // FIXME: Parse some other record types perhaps? diff --git a/Userland/Libraries/LibDebug/DebugInfo.cpp b/Userland/Libraries/LibDebug/DebugInfo.cpp index 88eb5a70448..71d1229302c 100644 --- a/Userland/Libraries/LibDebug/DebugInfo.cpp +++ b/Userland/Libraries/LibDebug/DebugInfo.cpp @@ -95,7 +95,7 @@ ErrorOr DebugInfo::prepare_lines() auto compute_full_path = [&](DeprecatedFlyString const& file_path) -> Optional { if (file_path.view().contains("Toolchain/"sv) || file_path.view().contains("libgcc"sv)) return {}; - if (file_path.view().starts_with("./"sv) && !m_source_root.is_null()) + if (file_path.view().starts_with("./"sv) && !m_source_root.is_empty()) return LexicalPath::join(m_source_root, file_path).string(); if (auto index_of_serenity_slash = file_path.view().find("serenity/"sv); index_of_serenity_slash.has_value()) { auto start_index = index_of_serenity_slash.value() + "serenity/"sv.length(); diff --git a/Userland/Libraries/LibELF/Image.cpp b/Userland/Libraries/LibELF/Image.cpp index db11bf76f48..bf5ebeaed04 100644 --- a/Userland/Libraries/LibELF/Image.cpp +++ b/Userland/Libraries/LibELF/Image.cpp @@ -455,7 +455,7 @@ DeprecatedString Image::symbolicate(FlatPtr address, u32* out_offset) const } auto& demangled_name = symbol->demangled_name; - if (demangled_name.is_null()) + if (demangled_name.is_empty()) demangled_name = demangle(symbol->name); if (out_offset) { diff --git a/Userland/Libraries/LibFileSystemAccessClient/Client.cpp b/Userland/Libraries/LibFileSystemAccessClient/Client.cpp index 02c8667bcf3..d6a6ec9d9f1 100644 --- a/Userland/Libraries/LibFileSystemAccessClient/Client.cpp +++ b/Userland/Libraries/LibFileSystemAccessClient/Client.cpp @@ -98,7 +98,7 @@ Result Client::save_file(GUI::Window* parent_window, DeprecatedString const& nam GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id); }); - async_prompt_save_file(id, parent_window_server_client_id, parent_window_id, name.is_null() ? "Untitled" : name, ext.is_null() ? "txt" : ext, Core::StandardPaths::home_directory(), requested_access); + async_prompt_save_file(id, parent_window_server_client_id, parent_window_id, name.is_empty() ? "Untitled" : name, ext.is_empty() ? "txt" : ext, Core::StandardPaths::home_directory(), requested_access); return handle_promise(id); } diff --git a/Userland/Libraries/LibGUI/AbstractView.cpp b/Userland/Libraries/LibGUI/AbstractView.cpp index 030657b6a44..ab032bc5e15 100644 --- a/Userland/Libraries/LibGUI/AbstractView.cpp +++ b/Userland/Libraries/LibGUI/AbstractView.cpp @@ -89,9 +89,11 @@ void AbstractView::model_did_update(unsigned int flags) m_drop_candidate_index = {}; selection().remove_all_matching([this](auto& index) { return !model()->is_within_range(index); }); - auto index = find_next_search_match(m_highlighted_search.view()); - if (index.is_valid()) - highlight_search(index); + if (m_highlighted_search.has_value()) { + auto index = find_next_search_match(m_highlighted_search->view()); + if (index.is_valid()) + highlight_search(index); + } } m_selection_start_index = {}; } @@ -592,11 +594,11 @@ void AbstractView::keydown_event(KeyEvent& event) if (is_searchable()) { if (event.key() == KeyCode::Key_Backspace) { - if (!m_highlighted_search.is_null()) { + if (m_highlighted_search.has_value()) { // if (event.modifiers() == Mod_Ctrl) { // TODO: delete last word // } - Utf8View view(m_highlighted_search); + Utf8View view(*m_highlighted_search); size_t n_code_points = view.length(); if (n_code_points > 1) { n_code_points--; @@ -621,7 +623,7 @@ void AbstractView::keydown_event(KeyEvent& event) return; } } else if (event.key() == KeyCode::Key_Escape) { - if (!m_highlighted_search.is_null()) { + if (m_highlighted_search.has_value()) { stop_highlighted_search_timer(); event.accept(); @@ -629,7 +631,8 @@ void AbstractView::keydown_event(KeyEvent& event) } } else if (event.key() != KeyCode::Key_Tab && !event.ctrl() && !event.alt() && event.code_point() != 0) { StringBuilder sb; - sb.append(m_highlighted_search); + if (m_highlighted_search.has_value()) + sb.append(*m_highlighted_search); sb.append_code_point(event.code_point()); auto index = find_next_search_match(sb.string_view()); @@ -650,7 +653,7 @@ void AbstractView::keydown_event(KeyEvent& event) void AbstractView::stop_highlighted_search_timer() { - m_highlighted_search = nullptr; + m_highlighted_search.clear(); if (m_highlighted_search_timer) m_highlighted_search_timer->stop(); if (m_highlighted_search_index.is_valid()) { @@ -723,8 +726,8 @@ void AbstractView::draw_item_text(Gfx::Painter& painter, ModelIndex const& index text_color = index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); if (index == m_highlighted_search_index) { - auto const byte_offset = search_highlighting_offset < m_highlighted_search.length() ? 0 : item_text.length(); - auto const byte_length = min(item_text.length() - byte_offset, m_highlighted_search.length() - search_highlighting_offset); + auto const byte_offset = search_highlighting_offset < m_highlighted_search.value_or("").length() ? 0 : item_text.length(); + auto const byte_length = min(item_text.length() - byte_offset, m_highlighted_search.value_or("").length() - search_highlighting_offset); Utf8View const searching_text(item_text.substring_view(byte_offset, byte_length)); // Highlight the text background first diff --git a/Userland/Libraries/LibGUI/AbstractView.h b/Userland/Libraries/LibGUI/AbstractView.h index 1ff695f3f02..a1184f05cc8 100644 --- a/Userland/Libraries/LibGUI/AbstractView.h +++ b/Userland/Libraries/LibGUI/AbstractView.h @@ -199,7 +199,7 @@ private: RefPtr m_model; ModelSelection m_selection; - DeprecatedString m_highlighted_search; + Optional m_highlighted_search; RefPtr m_highlighted_search_timer; SelectionBehavior m_selection_behavior { SelectionBehavior::SelectItems }; SelectionMode m_selection_mode { SelectionMode::SingleSelection }; diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index 8b0514fd087..999024e3413 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -48,9 +48,10 @@ ErrorOr> FilePicker::get_filepath(Badgewindow_id()); if (picker->exec() == ExecResult::OK) { - auto file_path = TRY(String::from_deprecated_string(picker->selected_file())); - if (file_path.is_empty()) + auto file_path = TRY(picker->selected_file().map([](auto& v) { return String::from_deprecated_string(v); })); + if (file_path.has_value() && file_path->is_empty()) return Optional {}; + return file_path; } return Optional {}; @@ -60,17 +61,12 @@ Optional FilePicker::get_open_filepath(Window* parent_window, { auto picker = FilePicker::construct(parent_window, folder ? Mode::OpenFolder : Mode::Open, ""sv, path, screen_position, move(allowed_file_types)); - if (!window_title.is_null()) + if (!window_title.is_empty()) picker->set_title(window_title); - if (picker->exec() == ExecResult::OK) { - DeprecatedString file_path = picker->selected_file(); + if (picker->exec() == ExecResult::OK) + return picker->selected_file(); - if (file_path.is_null()) - return {}; - - return file_path; - } return {}; } @@ -78,14 +74,8 @@ Optional FilePicker::get_save_filepath(Window* parent_window, { auto picker = FilePicker::construct(parent_window, Mode::Save, DeprecatedString::formatted("{}.{}", title, extension), path, screen_position); - if (picker->exec() == ExecResult::OK) { - DeprecatedString file_path = picker->selected_file(); - - if (file_path.is_null()) - return {}; - - return file_path; - } + if (picker->exec() == ExecResult::OK) + return picker->selected_file(); return {}; } diff --git a/Userland/Libraries/LibGUI/FilePicker.h b/Userland/Libraries/LibGUI/FilePicker.h index e5763913f63..bef85a2c9bf 100644 --- a/Userland/Libraries/LibGUI/FilePicker.h +++ b/Userland/Libraries/LibGUI/FilePicker.h @@ -44,7 +44,7 @@ public: virtual ~FilePicker() override; - DeprecatedString const& selected_file() const { return m_selected_file; } + Optional const& selected_file() const { return m_selected_file; } private: void on_file_return(); @@ -77,7 +77,7 @@ private: RefPtr m_view; NonnullRefPtr m_model; - DeprecatedString m_selected_file; + Optional m_selected_file; Vector m_allowed_file_types_names; Optional> m_allowed_file_types; diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 78dbdc929bc..1d9dd4b1582 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -68,7 +68,7 @@ bool FileSystemModel::Node::fetch_data(DeprecatedString const& full_path, bool i perror("readlink"); else { symlink_target = sym_link_target_or_error.release_value().to_deprecated_string(); - if (symlink_target.is_null()) + if (symlink_target.is_empty()) perror("readlink"); } } @@ -364,7 +364,7 @@ void FileSystemModel::update_node_on_selection(ModelIndex const& index, bool con void FileSystemModel::set_root_path(DeprecatedString root_path) { - if (root_path.is_null()) + if (root_path.is_empty()) m_root_path = {}; else m_root_path = LexicalPath::canonicalized_path(move(root_path)); @@ -382,7 +382,7 @@ void FileSystemModel::invalidate() { m_root = adopt_own(*new Node(*this)); - if (m_root_path.is_null()) + if (m_root_path.is_empty()) m_root->m_parent_of_root = true; m_root->reify_if_needed(); diff --git a/Userland/Libraries/LibGUI/ModelEditingDelegate.h b/Userland/Libraries/LibGUI/ModelEditingDelegate.h index 09e6edf3f87..dc6e85af234 100644 --- a/Userland/Libraries/LibGUI/ModelEditingDelegate.h +++ b/Userland/Libraries/LibGUI/ModelEditingDelegate.h @@ -96,7 +96,10 @@ public: virtual void set_value(Variant const& value, SelectionBehavior selection_behavior) override { auto& textbox = static_cast(*widget()); - textbox.set_text(value.to_deprecated_string()); + if (value.is_valid()) + textbox.set_text(value.to_deprecated_string()); + else + textbox.clear(); if (selection_behavior == SelectionBehavior::SelectAll) textbox.select_all(); } diff --git a/Userland/Libraries/LibGUI/TableView.cpp b/Userland/Libraries/LibGUI/TableView.cpp index 050517ceeca..ee8da6c21c6 100644 --- a/Userland/Libraries/LibGUI/TableView.cpp +++ b/Userland/Libraries/LibGUI/TableView.cpp @@ -202,10 +202,10 @@ void TableView::keydown_event(KeyEvent& event) if (selection().size() > 1) { selection().for_each_index([&](GUI::ModelIndex& index) { begin_editing(index); - m_editing_delegate->set_value(DeprecatedString {}); + m_editing_delegate->set_value(GUI::Variant {}); }); } else { - m_editing_delegate->set_value(DeprecatedString {}); + m_editing_delegate->set_value(GUI::Variant {}); } } else if (is_backspace) { m_editing_delegate->set_value(DeprecatedString::empty()); diff --git a/Userland/Libraries/LibGUI/Variant.h b/Userland/Libraries/LibGUI/Variant.h index 7de0dda2676..feb97086f97 100644 --- a/Userland/Libraries/LibGUI/Variant.h +++ b/Userland/Libraries/LibGUI/Variant.h @@ -98,7 +98,6 @@ public: return visit( [](Empty) { return false; }, [](Detail::Boolean v) { return v.value; }, - [](DeprecatedString const& v) { return !v.is_null(); }, [](Integral auto v) { return v != 0; }, [](Gfx::IntPoint const& v) { return !v.is_zero(); }, [](OneOf auto const& v) { return !v.is_empty(); }, diff --git a/Userland/Libraries/LibGemini/Line.cpp b/Userland/Libraries/LibGemini/Line.cpp index 96ddbb51f1e..861690343cf 100644 --- a/Userland/Libraries/LibGemini/Line.cpp +++ b/Userland/Libraries/LibGemini/Line.cpp @@ -69,7 +69,7 @@ Link::Link(DeprecatedString text, Document const& document) m_name = url_string.substring_view(offset, url_string.length() - offset); } m_url = document.url().complete_url(url); - if (m_name.is_null()) + if (m_name.is_empty()) m_name = m_url.to_deprecated_string(); } diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index 052b0c8faf2..9d7852cfb7d 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -249,10 +249,6 @@ void Job::on_socket_connected() auto line = maybe_line.release_value(); dbgln_if(JOB_DEBUG, "Job {} read line of length {}", m_request.url(), line.length()); - if (line.is_null()) { - dbgln("Job: Expected HTTP status"); - return deferred_invoke([this] { did_fail(Core::NetworkJob::Error::TransmissionFailed); }); - } auto parts = line.split_view(' '); if (parts.size() < 2) { dbgln("Job: Expected 2-part or 3-part HTTP status line, got '{}'", line); @@ -302,16 +298,6 @@ void Job::on_socket_connected() } auto line = maybe_line.release_value(); - if (line.is_null()) { - if (m_state == State::Trailers) { - // Some servers like to send two ending chunks - // use this fact as an excuse to ignore anything after the last chunk - // that is not a valid trailing header. - return finish_up(); - } - dbgln("Job: Expected HTTP header"); - return did_fail(Core::NetworkJob::Error::ProtocolFailed); - } if (line.is_empty()) { if (m_state == State::Trailers) { return finish_up(); diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index 35fae5669a2..6c0e1690a2c 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -45,7 +45,7 @@ void JSONObject::initialize(Realm& realm) } // 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify -ThrowCompletionOr JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space) +ThrowCompletionOr> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space) { auto& realm = *vm.current_realm(); @@ -62,7 +62,7 @@ ThrowCompletionOr JSONObject::stringify_impl(VM& vm, Value val Vector list; for (size_t i = 0; i < replacer_length; ++i) { auto replacer_value = TRY(replacer_object.get(i)); - DeprecatedString item; + Optional item; if (replacer_value.is_string()) { item = replacer_value.as_string().deprecated_string(); } else if (replacer_value.is_number()) { @@ -72,8 +72,8 @@ ThrowCompletionOr JSONObject::stringify_impl(VM& vm, Value val if (is(value_object) || is(value_object)) item = TRY(replacer_value.to_deprecated_string(vm)); } - if (!item.is_null() && !list.contains_slow(item)) { - list.append(item); + if (item.has_value() && !list.contains_slow(*item)) { + list.append(*item); } } state.property_list = list; @@ -118,15 +118,15 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify) auto replacer = vm.argument(1); auto space = vm.argument(2); - auto string = TRY(stringify_impl(vm, value, replacer, space)); - if (string.is_null()) + auto maybe_string = TRY(stringify_impl(vm, value, replacer, space)); + if (!maybe_string.has_value()) return js_undefined(); - return PrimitiveString::create(vm, string); + return PrimitiveString::create(vm, maybe_string.release_value()); } // 25.5.2.1 SerializeJSONProperty ( state, key, holder ), https://tc39.es/ecma262/#sec-serializejsonproperty -ThrowCompletionOr JSONObject::serialize_json_property(VM& vm, StringifyState& state, PropertyKey const& key, Object* holder) +ThrowCompletionOr> JSONObject::serialize_json_property(VM& vm, StringifyState& state, PropertyKey const& key, Object* holder) { // 1. Let value be ? Get(holder, key). auto value = TRY(holder->get(key)); @@ -209,14 +209,14 @@ ThrowCompletionOr JSONObject::serialize_json_property(VM& vm, // b. If isArray is true, return ? SerializeJSONArray(state, value). if (is_array) - return serialize_json_array(vm, state, value.as_object()); + return TRY(serialize_json_array(vm, state, value.as_object())); // c. Return ? SerializeJSONObject(state, value). - return serialize_json_object(vm, state, value.as_object()); + return TRY(serialize_json_object(vm, state, value.as_object())); } // 12. Return undefined. - return DeprecatedString {}; + return Optional {}; } // 25.5.2.4 SerializeJSONObject ( state, value ), https://tc39.es/ecma262/#sec-serializejsonobject @@ -234,7 +234,7 @@ ThrowCompletionOr JSONObject::serialize_json_object(VM& vm, St if (key.is_symbol()) return {}; auto serialized_property_string = TRY(serialize_json_property(vm, state, key, &object)); - if (!serialized_property_string.is_null()) { + if (serialized_property_string.has_value()) { property_strings.append(DeprecatedString::formatted( "{}:{}{}", quote_json_string(key.to_string()), @@ -305,10 +305,10 @@ ThrowCompletionOr JSONObject::serialize_json_array(VM& vm, Str for (size_t i = 0; i < length; ++i) { auto serialized_property_string = TRY(serialize_json_property(vm, state, i, &object)); - if (serialized_property_string.is_null()) { + if (!serialized_property_string.has_value()) { property_strings.append("null"sv); } else { - property_strings.append(serialized_property_string); + property_strings.append(serialized_property_string.release_value()); } } diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.h b/Userland/Libraries/LibJS/Runtime/JSONObject.h index 490edac4c99..9a87b520aa5 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.h +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.h @@ -19,7 +19,7 @@ public: // The base implementation of stringify is exposed because it is used by // test-js to communicate between the JS tests and the C++ test runner. - static ThrowCompletionOr stringify_impl(VM&, Value value, Value replacer, Value space); + static ThrowCompletionOr> stringify_impl(VM&, Value value, Value replacer, Value space); static Value parse_json_value(VM&, JsonValue const&); @@ -35,7 +35,7 @@ private: }; // Stringify helpers - static ThrowCompletionOr serialize_json_property(VM&, StringifyState&, PropertyKey const& key, Object* holder); + static ThrowCompletionOr> serialize_json_property(VM&, StringifyState&, PropertyKey const& key, Object* holder); static ThrowCompletionOr serialize_json_object(VM&, StringifyState&, Object&); static ThrowCompletionOr serialize_json_array(VM&, StringifyState&, Object&); static DeprecatedString quote_json_string(DeprecatedString); diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp index 600ad31d721..cb0131347a2 100644 --- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp +++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp @@ -221,7 +221,7 @@ NonnullGCPtr PrimitiveString::create(VM& vm, DeprecatedString s NonnullGCPtr PrimitiveString::create(VM& vm, DeprecatedFlyString const& string) { - return create(vm, string.impl()); + return create(vm, *string.impl()); } NonnullGCPtr PrimitiveString::create(VM& vm, PrimitiveString& lhs, PrimitiveString& rhs) diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 4cf28cc2e4a..c292eff63b4 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -910,7 +910,7 @@ ThrowCompletionOr> VM::resolve_imported_module(ScriptOrModu VERIFY(module_request.assertions.is_empty() || (module_request.assertions.size() == 1 && module_request.assertions.first().key == "type")); auto module_type = module_request.assertions.is_empty() ? DeprecatedString {} : module_request.assertions.first().value; - dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] module at {} has type {} [is_null={}]", module_request.module_specifier, module_type, module_type.is_null()); + dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] module at {} has type {}", module_request.module_specifier, module_type); StringView base_filename = referencing_script_or_module.visit( [&](Empty) { diff --git a/Userland/Libraries/LibJS/Token.cpp b/Userland/Libraries/LibJS/Token.cpp index 0037cd11b12..42f0234fc8b 100644 --- a/Userland/Libraries/LibJS/Token.cpp +++ b/Userland/Libraries/LibJS/Token.cpp @@ -174,7 +174,7 @@ DeprecatedString Token::string_value(StringValueStatus& status) const // In non-strict mode LegacyOctalEscapeSequence is allowed in strings: // https://tc39.es/ecma262/#sec-additional-syntax-string-literals - DeprecatedString octal_str; + Optional octal_str; auto is_octal_digit = [](char ch) { return ch >= '0' && ch <= '7'; }; auto is_zero_to_three = [](char ch) { return ch >= '0' && ch <= '3'; }; @@ -193,9 +193,9 @@ DeprecatedString Token::string_value(StringValueStatus& status) const else if (is_zero_to_three(lexer.peek()) && is_octal_digit(lexer.peek(1)) && is_octal_digit(lexer.peek(2))) octal_str = lexer.consume(3); - if (!octal_str.is_null()) { + if (octal_str.has_value()) { status = StringValueStatus::LegacyOctalEscapeSequence; - auto code_point = strtoul(octal_str.characters(), nullptr, 8); + auto code_point = strtoul(octal_str->characters(), nullptr, 8); VERIFY(code_point <= 255); builder.append_code_point(code_point); continue; diff --git a/Userland/Libraries/LibPDF/Parser.cpp b/Userland/Libraries/LibPDF/Parser.cpp index bf66f103fe6..ebdc4c80023 100644 --- a/Userland/Libraries/LibPDF/Parser.cpp +++ b/Userland/Libraries/LibPDF/Parser.cpp @@ -256,8 +256,6 @@ NonnullRefPtr Parser::parse_string() is_binary_string = true; } - VERIFY(!string.is_null()); - auto string_object = make_object(string, is_binary_string); if (m_document->security_handler() && m_enable_encryption) diff --git a/Userland/Libraries/LibSQL/AST/AST.h b/Userland/Libraries/LibSQL/AST/AST.h index 047ff58b869..639609594a0 100644 --- a/Userland/Libraries/LibSQL/AST/AST.h +++ b/Userland/Libraries/LibSQL/AST/AST.h @@ -186,8 +186,8 @@ public: ResultType type() const { return m_type; } - bool select_from_table() const { return !m_table_name.is_null(); } - DeprecatedString const& table_name() const { return m_table_name; } + bool select_from_table() const { return m_table_name.has_value(); } + Optional const& table_name() const { return m_table_name; } bool select_from_expression() const { return !m_expression.is_null(); } RefPtr const& expression() const { return m_expression; } @@ -196,7 +196,7 @@ public: private: ResultType m_type { ResultType::All }; - DeprecatedString m_table_name {}; + Optional m_table_name {}; RefPtr m_expression {}; DeprecatedString m_column_alias {}; diff --git a/Userland/Libraries/LibSQL/AST/Parser.cpp b/Userland/Libraries/LibSQL/AST/Parser.cpp index 33f944a4037..5bcba3137ff 100644 --- a/Userland/Libraries/LibSQL/AST/Parser.cpp +++ b/Userland/Libraries/LibSQL/AST/Parser.cpp @@ -566,16 +566,16 @@ RefPtr Parser::parse_bind_parameter_expression() return {}; } -RefPtr Parser::parse_column_name_expression(DeprecatedString with_parsed_identifier, bool with_parsed_period) +RefPtr Parser::parse_column_name_expression(Optional with_parsed_identifier, bool with_parsed_period) { - if (with_parsed_identifier.is_null() && !match(TokenType::Identifier)) + if (!with_parsed_identifier.has_value() && !match(TokenType::Identifier)) return {}; DeprecatedString first_identifier; - if (with_parsed_identifier.is_null()) + if (!with_parsed_identifier.has_value()) first_identifier = consume(TokenType::Identifier).value(); else - first_identifier = move(with_parsed_identifier); + first_identifier = with_parsed_identifier.release_value(); DeprecatedString schema_name; DeprecatedString table_name; @@ -1010,17 +1010,17 @@ NonnullRefPtr Parser::parse_result_column() // If we match an identifier now, we don't know whether it is a table-name of the form "table-name.*", or if it is the start of a // column-name-expression, until we try to parse the asterisk. So if we consume an identifier and a period, but don't find an // asterisk, hold onto that information to form a column-name-expression later. - DeprecatedString table_name; + Optional table_name; bool parsed_period = false; if (match(TokenType::Identifier)) { table_name = consume().value(); parsed_period = consume_if(TokenType::Period); if (parsed_period && consume_if(TokenType::Asterisk)) - return create_ast_node(move(table_name)); + return create_ast_node(table_name.release_value()); } - auto expression = table_name.is_null() + auto expression = !table_name.has_value() ? parse_expression() : static_cast>(*parse_column_name_expression(move(table_name), parsed_period)); diff --git a/Userland/Libraries/LibSQL/AST/Parser.h b/Userland/Libraries/LibSQL/AST/Parser.h index 2721e45043e..3fbadf47253 100644 --- a/Userland/Libraries/LibSQL/AST/Parser.h +++ b/Userland/Libraries/LibSQL/AST/Parser.h @@ -74,7 +74,7 @@ private: bool match_secondary_expression() const; RefPtr parse_literal_value_expression(); RefPtr parse_bind_parameter_expression(); - RefPtr parse_column_name_expression(DeprecatedString with_parsed_identifier = {}, bool with_parsed_period = false); + RefPtr parse_column_name_expression(Optional with_parsed_identifier = {}, bool with_parsed_period = false); RefPtr parse_unary_operator_expression(); RefPtr parse_binary_operator_expression(NonnullRefPtr lhs); RefPtr parse_chained_expression(bool surrounded_by_parentheses = true); diff --git a/Userland/Libraries/LibTLS/Handshake.cpp b/Userland/Libraries/LibTLS/Handshake.cpp index d2a3933aab9..20b70f6e796 100644 --- a/Userland/Libraries/LibTLS/Handshake.cpp +++ b/Userland/Libraries/LibTLS/Handshake.cpp @@ -44,7 +44,7 @@ ByteBuffer TLSv12::build_hello() size_t alpn_negotiated_length = 0; // ALPN - if (!m_context.negotiated_alpn.is_null()) { + if (!m_context.negotiated_alpn.is_empty()) { alpn_negotiated_length = m_context.negotiated_alpn.length(); alpn_length = alpn_negotiated_length + 1; extension_length += alpn_length + 6; @@ -69,7 +69,7 @@ ByteBuffer TLSv12::build_hello() // set SNI if we have one, and the user hasn't explicitly asked us to omit it. auto sni_length = 0; - if (!m_context.extensions.SNI.is_null() && m_context.options.use_sni) + if (!m_context.extensions.SNI.is_empty() && m_context.options.use_sni) sni_length = m_context.extensions.SNI.length(); auto elliptic_curves_length = 2 * m_context.options.elliptic_curves.size(); diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h index 3e59b1cd840..8c6d43cf812 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -247,9 +247,10 @@ inline AK::Result, ParserError> parse_mod inline ErrorOr get_test_results(JS::Realm& realm) { auto results = MUST(realm.global_object().get("__TestResults__")); - auto json_string = MUST(JS::JSONObject::stringify_impl(*g_vm, results, JS::js_undefined(), JS::js_undefined())); - - return JsonValue::from_string(json_string); + auto maybe_json_string = MUST(JS::JSONObject::stringify_impl(*g_vm, results, JS::js_undefined(), JS::js_undefined())); + if (maybe_json_string.has_value()) + return JsonValue::from_string(*maybe_json_string); + return JsonValue(); } inline void TestRunner::do_run_single_test(DeprecatedString const& test_path, size_t, size_t) diff --git a/Userland/Libraries/LibVT/Attribute.h b/Userland/Libraries/LibVT/Attribute.h index b541c7395b1..bf73995c8a6 100644 --- a/Userland/Libraries/LibVT/Attribute.h +++ b/Userland/Libraries/LibVT/Attribute.h @@ -38,7 +38,7 @@ struct Attribute { #ifndef KERNEL DeprecatedString href; - DeprecatedString href_id; + Optional href_id; #endif enum class Flags : u8 { diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index 69a0ecccaa3..b1cbbfcc98f 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -292,7 +292,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event) // Pass: Compute the rect(s) of the currently hovered link, if any. Vector hovered_href_rects; - if (!m_hovered_href_id.is_null()) { + if (m_hovered_href_id.has_value()) { for (u16 visual_row = 0; visual_row < m_terminal.rows(); ++visual_row) { auto& line = m_terminal.line(first_row_from_history + visual_row); for (size_t column = 0; column < line.length(); ++column) { @@ -415,7 +415,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event) auto character_rect = glyph_rect(visual_row, column); - if (!m_hovered_href_id.is_null() && attribute.href_id == m_hovered_href_id) { + if (m_hovered_href_id.has_value() && attribute.href_id == m_hovered_href_id) { text_color = palette().base_text(); } @@ -754,7 +754,7 @@ void TerminalWidget::doubleclick_event(GUI::MouseEvent& event) { if (event.button() == GUI::MouseButton::Primary) { auto attribute = m_terminal.attribute_at(buffer_position_at(event.position())); - if (!attribute.href_id.is_null()) { + if (attribute.href_id.has_value()) { dbgln("Open hyperlinked URL: '{}'", attribute.href); Desktop::Launcher::open(attribute.href); return; @@ -806,7 +806,7 @@ void TerminalWidget::copy() void TerminalWidget::mouseup_event(GUI::MouseEvent& event) { if (event.button() == GUI::MouseButton::Primary) { - if (!m_active_href_id.is_null()) { + if (m_active_href_id.has_value()) { m_active_href = {}; m_active_href_id = {}; update(); @@ -862,7 +862,7 @@ void TerminalWidget::mousemove_event(GUI::MouseEvent& event) auto attribute = m_terminal.attribute_at(position); if (attribute.href_id != m_hovered_href_id) { - if (!attribute.href_id.is_null()) { + if (attribute.href_id.has_value()) { m_hovered_href_id = attribute.href_id; m_hovered_href = attribute.href; @@ -902,7 +902,7 @@ void TerminalWidget::mousemove_event(GUI::MouseEvent& event) if (!(event.buttons() & GUI::MouseButton::Primary)) return; - if (!m_active_href_id.is_null()) { + if (m_active_href_id.has_value()) { auto diff = event.position() - m_left_mousedown_position; auto distance_travelled_squared = diff.x() * diff.x() + diff.y() * diff.y(); constexpr int drag_distance_threshold = 5; @@ -1111,7 +1111,7 @@ void TerminalWidget::set_cursor_shape(CursorShape shape) void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event) { - if (m_hovered_href_id.is_null()) { + if (!m_hovered_href_id.has_value()) { m_context_menu->popup(event.screen_position()); } else { m_context_menu_href = m_hovered_href; diff --git a/Userland/Libraries/LibVT/TerminalWidget.h b/Userland/Libraries/LibVT/TerminalWidget.h index 0b50c924b23..6f85565d579 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.h +++ b/Userland/Libraries/LibVT/TerminalWidget.h @@ -168,10 +168,10 @@ private: VT::Range m_selection; DeprecatedString m_hovered_href; - DeprecatedString m_hovered_href_id; + Optional m_hovered_href_id; DeprecatedString m_active_href; - DeprecatedString m_active_href_id; + Optional m_active_href_id; // Snapshot of m_hovered_href when opening a context menu for a hyperlink. DeprecatedString m_context_menu_href; diff --git a/Userland/Libraries/LibWeb/CSS/CSSNamespaceRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSNamespaceRule.cpp index 4f4b287d6e8..2eb38d5267f 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSNamespaceRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSNamespaceRule.cpp @@ -40,7 +40,7 @@ DeprecatedString CSSNamespaceRule::serialized() const builder.append("@namespace "sv); // followed by the serialization as an identifier of the prefix attribute (if any), - if (!m_prefix.is_empty() && !m_prefix.is_null()) { + if (!m_prefix.is_empty()) { serialize_an_identifier(builder, m_prefix); // followed by a single SPACE (U+0020) if there is a prefix, builder.append(" "sv); diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp index 925adb7a4a7..ca57886c8f0 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp @@ -53,23 +53,23 @@ DeprecatedString CSSStyleRule::serialized() const builder.append(" {"sv); // 2. Let decls be the result of performing serialize a CSS declaration block on the rule’s associated declarations, or null if there are no such declarations. - auto decls = declaration().serialized(); + auto decls = declaration().length() > 0 ? declaration().serialized() : Optional(); // FIXME: 3. Let rules be the result of performing serialize a CSS rule on each rule in the rule’s cssRules list, or null if there are no such rules. - DeprecatedString rules; + Optional rules; // 4. If decls and rules are both null, append " }" to s (i.e. a single SPACE (U+0020) followed by RIGHT CURLY BRACKET (U+007D)) and return s. - if (decls.is_null() && rules.is_null()) { + if (!decls.has_value() && !rules.has_value()) { builder.append(" }"sv); return builder.to_deprecated_string(); } // 5. If rules is null: - if (rules.is_null()) { + if (!rules.has_value()) { // 1. Append a single SPACE (U+0020) to s builder.append(' '); // 2. Append decls to s - builder.append(decls); + builder.append(*decls); // 3. Append " }" to s (i.e. a single SPACE (U+0020) followed by RIGHT CURLY BRACKET (U+007D)). builder.append(" }"sv); // 4. Return s. diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp index 5027ef3181b..09f8dde7062 100644 --- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -36,9 +36,9 @@ static inline bool matches_lang_pseudo_class(DOM::Element const& element, Vector { FlyString element_language; for (auto const* e = &element; e; e = e->parent_element()) { - auto lang = e->deprecated_attribute(HTML::AttributeNames::lang); - if (!lang.is_null()) { - element_language = FlyString::from_deprecated_fly_string(lang).release_value_but_fixme_should_propagate_errors(); + auto lang = e->attribute(HTML::AttributeNames::lang); + if (lang.has_value()) { + element_language = lang.release_value(); break; } } diff --git a/Userland/Libraries/LibWeb/DOM/Attr.cpp b/Userland/Libraries/LibWeb/DOM/Attr.cpp index d7625dda036..8888d02532d 100644 --- a/Userland/Libraries/LibWeb/DOM/Attr.cpp +++ b/Userland/Libraries/LibWeb/DOM/Attr.cpp @@ -92,7 +92,7 @@ void Attr::change_attribute(String value) } // https://dom.spec.whatwg.org/#handle-attribute-changes -void Attr::handle_attribute_changes(Element& element, DeprecatedString const& old_value, DeprecatedString const& new_value) +void Attr::handle_attribute_changes(Element& element, Optional old_value, Optional new_value) { DeprecatedString deprecated_namespace_uri; if (namespace_uri().has_value()) @@ -107,8 +107,8 @@ void Attr::handle_attribute_changes(Element& element, DeprecatedString const& ol JS::MarkedVector arguments { vm.heap() }; arguments.append(JS::PrimitiveString::create(vm, local_name())); - arguments.append(old_value.is_null() ? JS::js_null() : JS::PrimitiveString::create(vm, old_value)); - arguments.append(new_value.is_null() ? JS::js_null() : JS::PrimitiveString::create(vm, new_value)); + arguments.append(!old_value.has_value() ? JS::js_null() : JS::PrimitiveString::create(vm, old_value.release_value())); + arguments.append(!new_value.has_value() ? JS::js_null() : JS::PrimitiveString::create(vm, new_value.release_value())); arguments.append(!namespace_uri().has_value() ? JS::js_null() : JS::PrimitiveString::create(vm, namespace_uri().value())); element.enqueue_a_custom_element_callback_reaction(HTML::CustomElementReactionNames::attributeChangedCallback, move(arguments)); diff --git a/Userland/Libraries/LibWeb/DOM/Attr.h b/Userland/Libraries/LibWeb/DOM/Attr.h index 1674d7f72e2..104e55fa2cd 100644 --- a/Userland/Libraries/LibWeb/DOM/Attr.h +++ b/Userland/Libraries/LibWeb/DOM/Attr.h @@ -41,7 +41,7 @@ public: // Always returns true: https://dom.spec.whatwg.org/#dom-attr-specified constexpr bool specified() const { return true; } - void handle_attribute_changes(Element&, DeprecatedString const& old_value, DeprecatedString const& new_value); + void handle_attribute_changes(Element&, Optional old_value, Optional new_value); private: Attr(Document&, QualifiedName, String value, Element*); diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 57530130288..0580e268c31 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -82,19 +82,19 @@ Element::Element(Document& document, DOM::QualifiedName qualified_name) return; // 2. If value is null and oldValue is the empty string, then return. - if (value.is_null() && old_value == DeprecatedString::empty()) + if (!value.has_value() && old_value == DeprecatedString::empty()) return; // 3. If value is the empty string and oldValue is null, then return. - if (value == DeprecatedString::empty() && old_value.is_null()) + if (value == DeprecatedString::empty() && !old_value.has_value()) return; // 4. If value is null or the empty string, then set element’s name to the empty string. - if (value.is_empty()) + if (!value.has_value() || value->is_empty()) set_slottable_name({}); // 5. Otherwise, set element’s name to value. else - set_slottable_name(MUST(String::from_deprecated_string(value))); + set_slottable_name(MUST(String::from_deprecated_string(*value))); // 6. If element is assigned, then run assign slottables for element’s assigned slot. if (auto assigned_slot = assigned_slot_internal()) @@ -468,7 +468,7 @@ void Element::add_attribute_change_steps(AttributeChangeSteps steps) m_attribute_change_steps.append(move(steps)); } -void Element::run_attribute_change_steps(FlyString const& local_name, DeprecatedString const& old_value, DeprecatedString const& value, DeprecatedFlyString const& namespace_) +void Element::run_attribute_change_steps(FlyString const& local_name, Optional const& old_value, Optional const& value, DeprecatedFlyString const& namespace_) { for (auto const& attribute_change_steps : m_attribute_change_steps) attribute_change_steps(local_name, old_value, value, namespace_); @@ -478,19 +478,21 @@ void Element::run_attribute_change_steps(FlyString const& local_name, Deprecated invalidate_style_after_attribute_change(local_name); } -void Element::attribute_changed(FlyString const& name, DeprecatedString const& value) +void Element::attribute_changed(FlyString const& name, Optional const& value) { + auto value_or_empty = value.value_or(""); + if (name == HTML::AttributeNames::class_) { - auto new_classes = value.split_view(Infra::is_ascii_whitespace); + auto new_classes = value_or_empty.split_view(Infra::is_ascii_whitespace); m_classes.clear(); m_classes.ensure_capacity(new_classes.size()); for (auto& new_class : new_classes) { m_classes.unchecked_append(FlyString::from_utf8(new_class).release_value_but_fixme_should_propagate_errors()); } if (m_class_list) - m_class_list->associated_attribute_changed(value); + m_class_list->associated_attribute_changed(value_or_empty); } else if (name == HTML::AttributeNames::style) { - if (value.is_null()) { + if (!value.has_value()) { if (!m_inline_style) { m_inline_style = nullptr; set_needs_style_update(true); @@ -499,16 +501,16 @@ void Element::attribute_changed(FlyString const& name, DeprecatedString const& v // https://drafts.csswg.org/cssom/#ref-for-cssstyledeclaration-updating-flag if (m_inline_style && m_inline_style->is_updating()) return; - m_inline_style = parse_css_style_attribute(CSS::Parser::ParsingContext(document()), value, *this); + m_inline_style = parse_css_style_attribute(CSS::Parser::ParsingContext(document()), *value, *this); set_needs_style_update(true); } } else if (name == HTML::AttributeNames::dir) { // https://html.spec.whatwg.org/multipage/dom.html#attr-dir - if (value.equals_ignoring_ascii_case("ltr"sv)) + if (value_or_empty.equals_ignoring_ascii_case("ltr"sv)) m_dir = Dir::Ltr; - else if (value.equals_ignoring_ascii_case("rtl"sv)) + else if (value_or_empty.equals_ignoring_ascii_case("rtl"sv)) m_dir = Dir::Rtl; - else if (value.equals_ignoring_ascii_case("auto"sv)) + else if (value_or_empty.equals_ignoring_ascii_case("auto"sv)) m_dir = Dir::Auto; else m_dir = {}; diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 960a7ea8271..d41563d7619 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -153,11 +153,11 @@ public: virtual void apply_presentational_hints(CSS::StyleProperties&) const { } // https://dom.spec.whatwg.org/#concept-element-attributes-change-ext - using AttributeChangeSteps = Function; + using AttributeChangeSteps = Function const& /*old_value*/, Optional const& /*value*/, DeprecatedFlyString const& /*namespace_*/)>; void add_attribute_change_steps(AttributeChangeSteps steps); - void run_attribute_change_steps(FlyString const& local_name, DeprecatedString const& old_value, DeprecatedString const& value, DeprecatedFlyString const& namespace_); - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value); + void run_attribute_change_steps(FlyString const& local_name, Optional const& old_value, Optional const& value, DeprecatedFlyString const& namespace_); + virtual void attribute_changed(FlyString const& name, Optional const& value); struct [[nodiscard]] RequiredInvalidationAfterStyleChange { bool repaint { false }; diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index c60af7f90bb..63c9234a529 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -1533,7 +1533,7 @@ Painting::PaintableBox* Node::paintable_box() } // https://dom.spec.whatwg.org/#queue-a-mutation-record -void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribute_name, DeprecatedString attribute_namespace, DeprecatedString old_value, Vector> added_nodes, Vector> removed_nodes, Node* previous_sibling, Node* next_sibling) const +void Node::queue_mutation_record(FlyString const& type, Optional attribute_name, Optional attribute_namespace, Optional old_value, Vector> added_nodes, Vector> removed_nodes, Node* previous_sibling, Node* next_sibling) const { // NOTE: We defer garbage collection until the end of the scope, since we can't safely use MutationObserver* as a hashmap key otherwise. // FIXME: This is a total hack. @@ -1541,7 +1541,7 @@ void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribu // 1. Let interestedObservers be an empty map. // mutationObserver -> mappedOldValue - OrderedHashMap interested_observers; + OrderedHashMap> interested_observers; // 2. Let nodes be the inclusive ancestors of target. Vector> nodes; @@ -1565,7 +1565,7 @@ void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribu // then: if (!(node.ptr() != this && !options.subtree) && !(type == MutationType::attributes && (!options.attributes.has_value() || !options.attributes.value())) - && !(type == MutationType::attributes && options.attribute_filter.has_value() && (!attribute_namespace.is_null() || !options.attribute_filter->contains_slow(attribute_name.view()))) + && !(type == MutationType::attributes && options.attribute_filter.has_value() && (attribute_namespace.has_value() || !options.attribute_filter->contains_slow(attribute_name.value_or("").view()))) && !(type == MutationType::characterData && (!options.character_data.has_value() || !options.character_data.value())) && !(type == MutationType::childList && !options.child_list)) { // 1. Let mo be registered’s observer. @@ -1593,17 +1593,9 @@ void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribu for (auto& interested_observer : interested_observers) { // 1. Let record be a new MutationRecord object with its type set to type, target set to target, attributeName set to name, attributeNamespace set to namespace, oldValue set to mappedOldValue, // addedNodes set to addedNodes, removedNodes set to removedNodes, previousSibling set to previousSibling, and nextSibling set to nextSibling. - Optional maybe_attribute_name; - if (!attribute_name.is_null()) - maybe_attribute_name = MUST(String::from_deprecated_string(attribute_name)); - - Optional maybe_attribute_namespace; - if (!attribute_namespace.is_null()) - maybe_attribute_namespace = MUST(String::from_deprecated_string(attribute_namespace)); - - Optional maybe_interested_observer; - if (!interested_observer.value.is_null()) - maybe_interested_observer = MUST(String::from_deprecated_string(interested_observer.value)); + auto maybe_attribute_name = attribute_name.map([](auto& name) { return MUST(String::from_deprecated_string(name)); }); + auto maybe_attribute_namespace = attribute_namespace.map([](auto& ns) { return MUST(String::from_deprecated_string(ns)); }); + auto maybe_interested_observer = interested_observer.value.map([](auto& value) { return MUST(String::from_deprecated_string(value)); }); auto record = MutationRecord::create(realm(), type, *this, added_nodes_list, removed_nodes_list, previous_sibling, next_sibling, maybe_attribute_name, maybe_attribute_namespace, /* mappedOldValue */ maybe_interested_observer); @@ -1888,8 +1880,8 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con if (is(this)) { auto const* element = static_cast(this); auto tooltip = element->title(); - if (!tooltip.is_empty() && !tooltip.is_null()) - return String::from_deprecated_string(tooltip); + if (!tooltip.has_value() && !tooltip->is_empty()) + return tooltip.release_value(); } // Append the result of each step above, with a space, to the total accumulated text. // diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index b2bd6bcea9e..18073eb2369 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -259,7 +259,7 @@ public: void add_registered_observer(RegisteredObserver& registered_observer) { m_registered_observer_list.append(registered_observer); } - void queue_mutation_record(FlyString const& type, DeprecatedString attribute_name, DeprecatedString attribute_namespace, DeprecatedString old_value, Vector> added_nodes, Vector> removed_nodes, Node* previous_sibling, Node* next_sibling) const; + void queue_mutation_record(FlyString const& type, Optional attribute_name, Optional attribute_namespace, Optional old_value, Vector> added_nodes, Vector> removed_nodes, Node* previous_sibling, Node* next_sibling) const; // https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-descendant template diff --git a/Userland/Libraries/LibWeb/DOM/StyleElementUtils.cpp b/Userland/Libraries/LibWeb/DOM/StyleElementUtils.cpp index f9842dfcfd0..2b23f5c1188 100644 --- a/Userland/Libraries/LibWeb/DOM/StyleElementUtils.cpp +++ b/Userland/Libraries/LibWeb/DOM/StyleElementUtils.cpp @@ -43,8 +43,8 @@ void StyleElementUtils::update_a_style_block(DOM::Element& style_element) return; // 4. If element's type attribute is present and its value is neither the empty string nor an ASCII case-insensitive match for "text/css", then return. - auto type_attribute = style_element.deprecated_attribute(HTML::AttributeNames::type); - if (!type_attribute.is_null() && !type_attribute.is_empty() && !Infra::is_ascii_case_insensitive_match(type_attribute, "text/css"sv)) + auto type_attribute = style_element.attribute(HTML::AttributeNames::type); + if (type_attribute.has_value() && !type_attribute->is_empty() && !Infra::is_ascii_case_insensitive_match(type_attribute->bytes_as_string_view(), "text/css"sv)) return; // FIXME: 5. If the Should element's inline behavior be blocked by Content Security Policy? algorithm returns "Blocked" when executed upon the style element, "style", and the style element's child text content, then return. [CSP] @@ -86,7 +86,7 @@ void StyleElementUtils::remove_a_css_style_sheet(DOM::Document& document, CSS::C } // https://www.w3.org/TR/cssom/#create-a-css-style-sheet -void StyleElementUtils::create_a_css_style_sheet(DOM::Document& document, DeprecatedString type, DOM::Element* owner_node, DeprecatedString media, DeprecatedString title, bool alternate, bool origin_clean, DeprecatedString location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet) +void StyleElementUtils::create_a_css_style_sheet(DOM::Document& document, DeprecatedString type, DOM::Element* owner_node, DeprecatedString media, DeprecatedString title, bool alternate, bool origin_clean, Optional location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet) { // 1. Create a new CSS style sheet object and set its properties as specified. // FIXME: We receive `sheet` from the caller already. This is weird. @@ -96,16 +96,13 @@ void StyleElementUtils::create_a_css_style_sheet(DOM::Document& document, Deprec sheet.set_owner_node(owner_node); sheet.set_type(MUST(String::from_deprecated_string(type))); sheet.set_media(move(media)); - if (title.is_null()) - sheet.set_title({}); - else - sheet.set_title(MUST(String::from_deprecated_string(title))); + sheet.set_title(MUST(String::from_deprecated_string(title))); sheet.set_alternate(alternate); sheet.set_origin_clean(origin_clean); - if (location.is_null()) + if (!location.has_value()) sheet.set_location({}); else - sheet.set_location(MUST(String::from_deprecated_string(location))); + sheet.set_location(MUST(String::from_deprecated_string(*location))); // 2. Then run the add a CSS style sheet steps for the newly created CSS style sheet. add_a_css_style_sheet(document, sheet); diff --git a/Userland/Libraries/LibWeb/DOM/StyleElementUtils.h b/Userland/Libraries/LibWeb/DOM/StyleElementUtils.h index 1147c5314b6..6119683ba4c 100644 --- a/Userland/Libraries/LibWeb/DOM/StyleElementUtils.h +++ b/Userland/Libraries/LibWeb/DOM/StyleElementUtils.h @@ -20,7 +20,7 @@ public: private: void remove_a_css_style_sheet(DOM::Document& document, CSS::CSSStyleSheet& sheet); - void create_a_css_style_sheet(DOM::Document& document, DeprecatedString type, DOM::Element* owner_node, DeprecatedString media, DeprecatedString title, bool alternate, bool origin_clean, DeprecatedString location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet); + void create_a_css_style_sheet(DOM::Document& document, DeprecatedString type, DOM::Element* owner_node, DeprecatedString media, DeprecatedString title, bool alternate, bool origin_clean, Optional location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet); void add_a_css_style_sheet(DOM::Document& document, CSS::CSSStyleSheet& sheet); // https://www.w3.org/TR/cssom/#associated-css-style-sheet diff --git a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp index 4b3599321ac..df3a78a801e 100644 --- a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp +++ b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp @@ -257,14 +257,14 @@ static Optional record_namespace_information(DOM::Element cons auto const& prefix_definition = attribute->local_name().to_deprecated_fly_string(); // 2. Let namespace definition be the value of attr's value. - auto namespace_definition = attribute->value().to_deprecated_string(); + DeprecatedFlyString namespace_definition = attribute->value().to_deprecated_string(); // 3. If namespace definition is the XML namespace, then stop running these steps, and return to Main to visit the next attribute. if (namespace_definition == Namespace::XML) continue; // 4. If namespace definition is the empty string (the declarative form of having no namespace), then let namespace definition be null instead. - if (namespace_definition.is_empty()) + if (namespace_definition == ""sv) namespace_definition = {}; // 5. If prefix definition is found in map given the namespace namespace definition, then stop running these steps, and return to Main to visit the next attribute. @@ -284,17 +284,19 @@ static Optional record_namespace_information(DOM::Element cons } // https://w3c.github.io/DOM-Parsing/#dfn-serializing-an-attribute-value -static WebIDL::ExceptionOr serialize_an_attribute_value(DeprecatedString const& attribute_value, [[maybe_unused]] RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_an_attribute_value(OneOf auto const& attribute_value, [[maybe_unused]] RequireWellFormed require_well_formed) { // FIXME: 1. If the require well-formed flag is set (its value is true), and attribute value contains characters that are not matched by the XML Char production, // then throw an exception; the serialization of this attribute value would fail to produce a well-formed element serialization. // 2. If attribute value is null, then return the empty string. - if (attribute_value.is_null()) - return DeprecatedString::empty(); + if constexpr (requires { attribute_value.is_null(); }) { + if (attribute_value.is_null()) + return DeprecatedString::empty(); + } // 3. Otherwise, attribute value is a string. Return the value of attribute value, first replacing any occurrences of the following: - auto final_attribute_value = attribute_value; + DeprecatedString final_attribute_value = attribute_value; // 1. "&" with "&" final_attribute_value = final_attribute_value.replace("&"sv, "&"sv, ReplaceMode::All); diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 9ef37de72fe..dd780b318eb 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -821,7 +821,7 @@ ErrorOr dump_namespace_rule(StringBuilder& builder, CSS::CSSNamespaceRule { indent(builder, indent_levels); TRY(builder.try_appendff(" Namespace: {}\n", namespace_.namespace_uri())); - if (!namespace_.prefix().is_null() && !namespace_.prefix().is_empty()) + if (!namespace_.prefix().is_empty()) TRY(builder.try_appendff(" Prefix: {}\n", namespace_.prefix())); return {}; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp index ba04654c1e0..2054a02ebf6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp @@ -27,7 +27,7 @@ void HTMLAnchorElement::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLAnchorElement")); } -void HTMLAnchorElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLAnchorElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); if (name == HTML::AttributeNames::href) { @@ -35,9 +35,9 @@ void HTMLAnchorElement::attribute_changed(FlyString const& name, DeprecatedStrin } } -DeprecatedString HTMLAnchorElement::hyperlink_element_utils_href() const +Optional HTMLAnchorElement::hyperlink_element_utils_href() const { - return deprecated_attribute(HTML::AttributeNames::href); + return attribute(HTML::AttributeNames::href); } WebIDL::ExceptionOr HTMLAnchorElement::set_hyperlink_element_utils_href(String href) @@ -98,7 +98,7 @@ i32 HTMLAnchorElement::default_tab_index_value() const Optional HTMLAnchorElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-a-no-href - if (!href().is_null()) + if (!href().is_empty()) return ARIA::Role::link; // https://www.w3.org/TR/html-aria/#el-a return ARIA::Role::generic; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h index 2573d9d5ca8..2cf76f8c5c8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h @@ -43,12 +43,12 @@ private: void run_activation_behavior(Web::DOM::Event const&); // ^DOM::Element - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; virtual i32 default_tab_index_value() const override; // ^HTML::HTMLHyperlinkElementUtils virtual DOM::Document& hyperlink_element_utils_document() override { return document(); } - virtual DeprecatedString hyperlink_element_utils_href() const override; + virtual Optional hyperlink_element_utils_href() const override; virtual WebIDL::ExceptionOr set_hyperlink_element_utils_href(String) override; virtual bool hyperlink_element_utils_is_html_anchor_element() const final { return true; } virtual bool hyperlink_element_utils_is_connected() const final { return is_connected(); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp index e871d979854..d909e197866 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp @@ -23,7 +23,7 @@ void HTMLAreaElement::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLAreaElement")); } -void HTMLAreaElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLAreaElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); if (name == HTML::AttributeNames::href) { @@ -31,9 +31,9 @@ void HTMLAreaElement::attribute_changed(FlyString const& name, DeprecatedString } } -DeprecatedString HTMLAreaElement::hyperlink_element_utils_href() const +Optional HTMLAreaElement::hyperlink_element_utils_href() const { - return deprecated_attribute(HTML::AttributeNames::href); + return attribute(HTML::AttributeNames::href); } WebIDL::ExceptionOr HTMLAreaElement::set_hyperlink_element_utils_href(String href) @@ -51,7 +51,7 @@ i32 HTMLAreaElement::default_tab_index_value() const Optional HTMLAreaElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-area-no-href - if (!href().is_null()) + if (!href().is_empty()) return ARIA::Role::link; // https://www.w3.org/TR/html-aria/#el-area return ARIA::Role::generic; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.h index 3c407c2d21b..6cf5f42ba7c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.h @@ -26,12 +26,12 @@ private: virtual void initialize(JS::Realm&) override; // ^DOM::Element - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; virtual i32 default_tab_index_value() const override; // ^HTML::HTMLHyperlinkElementUtils virtual DOM::Document& hyperlink_element_utils_document() override { return document(); } - virtual DeprecatedString hyperlink_element_utils_href() const override; + virtual Optional hyperlink_element_utils_href() const override; virtual WebIDL::ExceptionOr set_hyperlink_element_utils_href(String) override; virtual bool hyperlink_element_utils_is_html_anchor_element() const override { return false; } virtual bool hyperlink_element_utils_is_connected() const override { return is_connected(); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp index 9730235c4fd..53cb75100db 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp @@ -43,7 +43,7 @@ void HTMLBaseElement::removed_from(Node* parent) document().update_base_element({}); } -void HTMLBaseElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLBaseElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.h b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.h index 975bea911ef..1e6c2cbf9d3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.h @@ -23,7 +23,7 @@ public: virtual void inserted() override; virtual void removed_from(Node*) override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; private: HTMLBaseElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp index 6460ca89b48..37fd5d3ea14 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp @@ -55,26 +55,26 @@ void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) co }); } -void HTMLBodyElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLBodyElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); if (name.equals_ignoring_ascii_case("link"sv)) { // https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-3 - auto color = parse_legacy_color_value(value); + auto color = parse_legacy_color_value(value.value_or("")); if (color.has_value()) document().set_link_color(color.value()); } else if (name.equals_ignoring_ascii_case("alink"sv)) { // https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-5 - auto color = parse_legacy_color_value(value); + auto color = parse_legacy_color_value(value.value_or("")); if (color.has_value()) document().set_active_link_color(color.value()); } else if (name.equals_ignoring_ascii_case("vlink"sv)) { // https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-4 - auto color = parse_legacy_color_value(value); + auto color = parse_legacy_color_value(value.value_or("")); if (color.has_value()) document().set_visited_link_color(color.value()); } else if (name.equals_ignoring_ascii_case("background"sv)) { - m_background_style_value = CSS::ImageStyleValue::create(document().parse_url(value)); + m_background_style_value = CSS::ImageStyleValue::create(document().parse_url(value.value_or(""))); m_background_style_value->on_animate = [this] { if (layout_node()) { layout_node()->set_needs_display(); @@ -83,9 +83,9 @@ void HTMLBodyElement::attribute_changed(FlyString const& name, DeprecatedString } #undef __ENUMERATE -#define __ENUMERATE(attribute_name, event_name) \ - if (name == HTML::AttributeNames::attribute_name) { \ - element_event_handler_attribute_changed(event_name, String::from_deprecated_string(value).release_value()); \ +#define __ENUMERATE(attribute_name, event_name) \ + if (name == HTML::AttributeNames::attribute_name) { \ + element_event_handler_attribute_changed(event_name, value.map([](auto& v) { return MUST(String::from_deprecated_string(v)); })); \ } ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE) #undef __ENUMERATE diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.h b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.h index 921aeff1bec..0d60c9327f9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.h @@ -20,7 +20,7 @@ class HTMLBodyElement final public: virtual ~HTMLBodyElement() override; - virtual void attribute_changed(FlyString const&, DeprecatedString const&) override; + virtual void attribute_changed(FlyString const&, Optional const&) override; virtual void apply_presentational_hints(CSS::StyleProperties&) const override; // https://www.w3.org/TR/html-aria/#el-body diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp index 08fabf8f6ce..653df30042e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp @@ -41,14 +41,14 @@ void HTMLDetailsElement::initialize(JS::Realm& realm) create_shadow_tree(realm).release_value_but_fixme_should_propagate_errors(); } -void HTMLDetailsElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLDetailsElement::attribute_changed(FlyString const& name, Optional const& value) { Base::attribute_changed(name, value); // https://html.spec.whatwg.org/multipage/interactive-elements.html#details-notification-task-steps if (name == HTML::AttributeNames::open) { // 1. If the open attribute is added, queue a details toggle event task given the details element, "closed", and "open". - if (!value.is_null()) { + if (value.has_value()) { queue_a_details_toggle_event_task("closed"_string, "open"_string); } // 2. Otherwise, queue a details toggle event task given the details element, "open", and "closed". diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.h b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.h index 12c051c30cb..d9d6f6c3bbb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.h @@ -31,7 +31,7 @@ private: virtual void visit_edges(Cell::Visitor&) override; virtual void children_changed() override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; void queue_a_details_toggle_event_task(String old_state, String new_state); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index e3da52de824..bdd0debbf19 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -224,18 +224,18 @@ bool HTMLElement::cannot_navigate() const return !is(this) && !is_connected(); } -void HTMLElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLElement::attribute_changed(FlyString const& name, Optional const& value) { Element::attribute_changed(name, value); if (name == HTML::AttributeNames::contenteditable) { - if (value.is_null()) { + if (!value.has_value()) { m_content_editable_state = ContentEditableState::Inherit; } else { - if (value.is_empty() || value.equals_ignoring_ascii_case("true"sv)) { + if (value->is_empty() || value->equals_ignoring_ascii_case("true"sv)) { // "true", an empty string or a missing value map to the "true" state. m_content_editable_state = ContentEditableState::True; - } else if (value.equals_ignoring_ascii_case("false"sv)) { + } else if (value->equals_ignoring_ascii_case("false"sv)) { // "false" maps to the "false" state. m_content_editable_state = ContentEditableState::False; } else { @@ -248,9 +248,9 @@ void HTMLElement::attribute_changed(FlyString const& name, DeprecatedString cons // 1. If namespace is not null, or localName is not the name of an event handler content attribute on element, then return. // FIXME: Add the namespace part once we support attribute namespaces. #undef __ENUMERATE -#define __ENUMERATE(attribute_name, event_name) \ - if (name == HTML::AttributeNames::attribute_name) { \ - element_event_handler_attribute_changed(event_name, String::from_deprecated_string(value).release_value()); \ +#define __ENUMERATE(attribute_name, event_name) \ + if (name == HTML::AttributeNames::attribute_name) { \ + element_event_handler_attribute_changed(event_name, value.map([](auto& v) { return MUST(String::from_deprecated_string(v)); })); \ } ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE) #undef __ENUMERATE diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.h b/Userland/Libraries/LibWeb/HTML/HTMLElement.h index 77dfddc4a37..37f0ec78e2e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.h @@ -27,7 +27,7 @@ class HTMLElement public: virtual ~HTMLElement() override; - DeprecatedString title() const { return deprecated_attribute(HTML::AttributeNames::title); } + Optional title() const { return attribute(HTML::AttributeNames::title); } StringView dir() const; void set_dir(String const&); @@ -70,7 +70,7 @@ protected: virtual void initialize(JS::Realm&) override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp index a1c85dee786..f56bc9ae424 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp @@ -23,14 +23,14 @@ void HTMLFrameSetElement::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLFrameSetElement")); } -void HTMLFrameSetElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLFrameSetElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); #undef __ENUMERATE -#define __ENUMERATE(attribute_name, event_name) \ - if (name == HTML::AttributeNames::attribute_name) { \ - element_event_handler_attribute_changed(event_name, String::from_deprecated_string(value).release_value()); \ +#define __ENUMERATE(attribute_name, event_name) \ + if (name == HTML::AttributeNames::attribute_name) { \ + element_event_handler_attribute_changed(event_name, value.map([](auto& v) { return MUST(String::from_deprecated_string(v)); })); \ } ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE) #undef __ENUMERATE diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.h index d19dade9576..be77d235fca 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.h @@ -24,7 +24,7 @@ private: HTMLFrameSetElement(DOM::Document&, DOM::QualifiedName); virtual void initialize(JS::Realm&) override; - virtual void attribute_changed(FlyString const&, DeprecatedString const&) override; + virtual void attribute_changed(FlyString const&, Optional const&) override; // ^HTML::GlobalEventHandlers virtual EventTarget& global_event_handlers_to_event_target(FlyString const& event_name) override; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp b/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp index 353860d18a0..49c0f61ae4f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp @@ -29,14 +29,14 @@ void HTMLHyperlinkElementUtils::set_the_url() { // 1. If this element's href content attribute is absent, set this element's url to null. auto href_content_attribute = hyperlink_element_utils_href(); - if (href_content_attribute.is_null()) { + if (!href_content_attribute.has_value()) { m_url = {}; return; } // 2. Otherwise, parse this element's href content attribute value relative to this element's node document. // If parsing is successful, set this element's url to the result; otherwise, set this element's url to null. - m_url = hyperlink_element_utils_document().parse_url(href_content_attribute); + m_url = hyperlink_element_utils_document().parse_url(*href_content_attribute); } // https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-origin @@ -429,12 +429,12 @@ DeprecatedString HTMLHyperlinkElementUtils::href() const // 3. If url is null and this element has no href content attribute, return the empty string. auto href_content_attribute = hyperlink_element_utils_href(); - if (!url.has_value() && href_content_attribute.is_null()) + if (!url.has_value() && !href_content_attribute.has_value()) return DeprecatedString::empty(); // 4. Otherwise, if url is null, return this element's href content attribute's value. if (!url->is_valid()) - return href_content_attribute; + return href_content_attribute->to_deprecated_string(); // 5. Return url, serialized. return url->serialize(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.h b/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.h index 10c602e6bfc..39739eebd2d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.h @@ -51,7 +51,7 @@ public: protected: virtual DOM::Document& hyperlink_element_utils_document() = 0; - virtual DeprecatedString hyperlink_element_utils_href() const = 0; + virtual Optional hyperlink_element_utils_href() const = 0; virtual WebIDL::ExceptionOr set_hyperlink_element_utils_href(String) = 0; virtual bool hyperlink_element_utils_is_html_anchor_element() const = 0; virtual bool hyperlink_element_utils_is_connected() const = 0; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 5d5eb7e18ad..7488390a553 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -33,7 +33,7 @@ JS::GCPtr HTMLIFrameElement::create_layout_node(NonnullRefPtr(document(), *this, move(style)); } -void HTMLIFrameElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLIFrameElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); if (m_content_navigable) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h index 6039dd70112..4cd0b915af9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h @@ -36,7 +36,7 @@ private: // ^DOM::Element virtual void inserted() override; virtual void removed_from(Node*) override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; virtual i32 default_tab_index_value() const override; // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index a3beb65306f..c835fe760b7 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -95,15 +95,15 @@ void HTMLImageElement::apply_presentational_hints(CSS::StyleProperties& style) c }); } -void HTMLImageElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLImageElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); if (name == HTML::AttributeNames::crossorigin) { - if (value.is_null()) { + if (!value.has_value()) { m_cors_setting = CORSSettingAttribute::NoCORS; } else { - m_cors_setting = cors_setting_attribute_from_keyword(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors()); + m_cors_setting = cors_setting_attribute_from_keyword(String::from_deprecated_string(*value).release_value_but_fixme_should_propagate_errors()); } } @@ -255,7 +255,7 @@ bool HTMLImageElement::complete() const return true; // - The srcset attribute is omitted and the src attribute's value is the empty string. - if (!has_attribute(HTML::AttributeNames::srcset) && deprecated_attribute(HTML::AttributeNames::src) == ""sv) + if (!has_attribute(HTML::AttributeNames::srcset) && attribute(HTML::AttributeNames::src).value().is_empty()) return true; // - The img element's current request's state is completely available and its pending request is null. @@ -273,7 +273,7 @@ Optional HTMLImageElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-img // https://www.w3.org/TR/html-aria/#el-img-no-alt - if (alt().is_null() || !alt().is_empty()) + if (!alt().is_empty()) return ARIA::Role::img; // https://www.w3.org/TR/html-aria/#el-img-empty-alt return ARIA::Role::presentation; @@ -870,38 +870,38 @@ static void update_the_source_set(DOM::Element& element) // 4. If el is an img element that has a srcset attribute, then set srcset to that attribute's value. if (is(element)) { - if (auto srcset_value = element.deprecated_attribute(HTML::AttributeNames::srcset); !srcset_value.is_null()) - srcset = String::from_deprecated_string(srcset_value).release_value_but_fixme_should_propagate_errors(); + if (auto srcset_value = element.attribute(HTML::AttributeNames::srcset); srcset_value.has_value()) + srcset = srcset_value.release_value(); } // 5. Otherwise, if el is a link element that has an imagesrcset attribute, then set srcset to that attribute's value. else if (is(element)) { - if (auto imagesrcset_value = element.deprecated_attribute(HTML::AttributeNames::imagesrcset); !imagesrcset_value.is_null()) - srcset = String::from_deprecated_string(imagesrcset_value).release_value_but_fixme_should_propagate_errors(); + if (auto imagesrcset_value = element.attribute(HTML::AttributeNames::imagesrcset); imagesrcset_value.has_value()) + srcset = imagesrcset_value.release_value(); } // 6. If el is an img element that has a sizes attribute, then set sizes to that attribute's value. if (is(element)) { - if (auto sizes_value = element.deprecated_attribute(HTML::AttributeNames::sizes); !sizes_value.is_null()) - sizes = String::from_deprecated_string(sizes_value).release_value_but_fixme_should_propagate_errors(); + if (auto sizes_value = element.attribute(HTML::AttributeNames::sizes); sizes_value.has_value()) + sizes = sizes_value.release_value(); } // 7. Otherwise, if el is a link element that has an imagesizes attribute, then set sizes to that attribute's value. else if (is(element)) { - if (auto imagesizes_value = element.deprecated_attribute(HTML::AttributeNames::imagesizes); !imagesizes_value.is_null()) - sizes = String::from_deprecated_string(imagesizes_value).release_value_but_fixme_should_propagate_errors(); + if (auto imagesizes_value = element.attribute(HTML::AttributeNames::imagesizes); imagesizes_value.has_value()) + sizes = imagesizes_value.release_value(); } // 8. If el is an img element that has a src attribute, then set default source to that attribute's value. if (is(element)) { - if (auto src_value = element.deprecated_attribute(HTML::AttributeNames::src); !src_value.is_null()) - default_source = String::from_deprecated_string(src_value).release_value_but_fixme_should_propagate_errors(); + if (auto src_value = element.attribute(HTML::AttributeNames::src); src_value.has_value()) + default_source = src_value.release_value(); } // 9. Otherwise, if el is a link element that has an href attribute, then set default source to that attribute's value. else if (is(element)) { - if (auto href_value = element.deprecated_attribute(HTML::AttributeNames::href); !href_value.is_null()) - default_source = String::from_deprecated_string(href_value).release_value_but_fixme_should_propagate_errors(); + if (auto href_value = element.attribute(HTML::AttributeNames::href); href_value.has_value()) + default_source = href_value.release_value(); } // 10. Let el's source set be the result of creating a source set given default source, srcset, and sizes. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h index 5bab4f6a978..62119296170 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -32,7 +32,7 @@ class HTMLImageElement final public: virtual ~HTMLImageElement() override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; DeprecatedString alt() const { return deprecated_attribute(HTML::AttributeNames::alt); } DeprecatedString src() const { return deprecated_attribute(HTML::AttributeNames::src); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index e1274fbaf87..5d495b1c1ef 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -523,8 +523,6 @@ void HTMLInputElement::create_shadow_tree_if_needed() auto shadow_root = heap().allocate(realm(), document(), *this, Bindings::ShadowRootMode::Closed); auto initial_value = m_value; - if (initial_value.is_null()) - initial_value = DeprecatedString::empty(); auto element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors(); MUST(element->set_attribute(HTML::AttributeNames::style, R"~~~( display: flex; @@ -552,7 +550,11 @@ void HTMLInputElement::create_shadow_tree_if_needed() // NOTE: file upload state is mutable, but we don't allow the text node to be modifed m_text_node->set_always_editable(false); } else { - handle_readonly_attribute(deprecated_attribute(HTML::AttributeNames::readonly)); + auto readonly = attribute(HTML::AttributeNames::readonly); + if (readonly.has_value()) + handle_readonly_attribute(readonly->to_deprecated_string()); + else + handle_readonly_attribute({}); } m_text_node->set_editable_text_node_owner(Badge {}, *this); @@ -587,11 +589,11 @@ void HTMLInputElement::did_lose_focus() }); } -void HTMLInputElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLInputElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); if (name == HTML::AttributeNames::checked) { - if (value.is_null()) { + if (!value.has_value()) { // When the checked content attribute is removed, if the control does not have dirty checkedness, // the user agent must set the checkedness of the element to false. if (!m_dirty_checkedness) @@ -603,24 +605,27 @@ void HTMLInputElement::attribute_changed(FlyString const& name, DeprecatedString set_checked(true, ChangeSource::Programmatic); } } else if (name == HTML::AttributeNames::type) { - m_type = parse_type_attribute(value); + m_type = parse_type_attribute(value.value_or("")); } else if (name == HTML::AttributeNames::value) { - if (value.is_null()) { + if (!value.has_value()) { if (!m_dirty_value) { m_value = DeprecatedString::empty(); update_placeholder_visibility(); } } else { if (!m_dirty_value) { - m_value = value_sanitization_algorithm(value); + m_value = value_sanitization_algorithm(*value); update_placeholder_visibility(); } } } else if (name == HTML::AttributeNames::placeholder) { if (m_placeholder_text_node) - m_placeholder_text_node->set_data(MUST(String::from_deprecated_string(value))); + m_placeholder_text_node->set_data(MUST(String::from_deprecated_string(value.value_or("")))); } else if (name == HTML::AttributeNames::readonly) { - handle_readonly_attribute(value); + if (value.has_value()) + handle_readonly_attribute(*value); + else + handle_readonly_attribute({}); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index 7afb67506e8..749d79f35b8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -111,7 +111,7 @@ public: virtual bool is_focusable() const override { return m_type != TypeAttributeState::Hidden; } // ^HTMLElement - virtual void attribute_changed(FlyString const&, DeprecatedString const&) override; + virtual void attribute_changed(FlyString const&, Optional const&) override; // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.h index b4e539d1860..41e018d3119 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.h @@ -18,7 +18,7 @@ public: virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; - DeprecatedString for_() const { return deprecated_attribute(HTML::AttributeNames::for_); } + Optional for_() const { return attribute(HTML::AttributeNames::for_); } private: HTMLLabelElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 9ea9ee425b1..6a793093aac 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -77,7 +77,7 @@ bool HTMLLinkElement::has_loaded_icon() const return m_relationship & Relationship::Icon && resource() && resource()->is_loaded() && resource()->has_encoded_data(); } -void HTMLLinkElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLLinkElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); @@ -85,7 +85,7 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, DeprecatedString if (name == HTML::AttributeNames::rel) { m_relationship = 0; // Keywords are always ASCII case-insensitive, and must be compared as such. - auto lowercased_value = value.to_lowercase(); + auto lowercased_value = value.value_or("").to_lowercase(); // To determine which link types apply to a link, a, area, or form element, // the element's rel attribute must be split on ASCII whitespace. // The resulting tokens are the keywords for the link types that apply to that element. @@ -341,13 +341,14 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru // 1. If the element has a charset attribute, get an encoding from that attribute's value. If that succeeds, return the resulting encoding. [ENCODING] // 2. Otherwise, return the document's character encoding. [DOM] - DeprecatedString encoding; - if (auto charset = deprecated_attribute(HTML::AttributeNames::charset); !charset.is_null()) - encoding = charset; - else - encoding = document().encoding_or_default().to_deprecated_string(); + Optional encoding; + if (auto charset = attribute(HTML::AttributeNames::charset); charset.has_value()) + encoding = charset.release_value(); - auto decoder = TextCodec::decoder_for(encoding); + if (!encoding.has_value()) + encoding = document().encoding_or_default(); + + auto decoder = TextCodec::decoder_for(*encoding); if (!decoder.has_value()) { // If we don't support the encoding yet, let's error out instead of trying to decode it as something it's most likely not. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h index 4d0bfa32bc4..719df10c024 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h @@ -39,7 +39,7 @@ private: HTMLLinkElement(DOM::Document&, DOM::QualifiedName); virtual void initialize(JS::Realm&) override; - void attribute_changed(FlyString const&, DeprecatedString const&) override; + void attribute_changed(FlyString const&, Optional const&) override; // ^ResourceClient virtual void resource_did_fail() override; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index 99311e276c3..2ea83a3adc1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -83,17 +83,17 @@ void HTMLMediaElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_fetch_controller); } -void HTMLMediaElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLMediaElement::attribute_changed(FlyString const& name, Optional const& value) { Base::attribute_changed(name, value); if (name == HTML::AttributeNames::src) { load_element().release_value_but_fixme_should_propagate_errors(); } else if (name == HTML::AttributeNames::crossorigin) { - if (value.is_null()) + if (!value.has_value()) m_crossorigin = cors_setting_attribute_from_keyword({}); else - m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors()); + m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(*value).release_value_but_fixme_should_propagate_errors()); } else if (name == HTML::AttributeNames::muted) { set_muted(true); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h index b3fd2797124..573b08d9b79 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h @@ -134,7 +134,7 @@ protected: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; virtual void removed_from(DOM::Node*) override; virtual void children_changed() override; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index 135e740604a..e3163b1134e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -45,7 +45,7 @@ void HTMLObjectElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_image_request); } -void HTMLObjectElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLObjectElement::attribute_changed(FlyString const& name, Optional const& value) { NavigableContainer::attribute_changed(name, value); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h index 8d7c0e27682..44e591bd7fb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h @@ -34,7 +34,7 @@ class HTMLObjectElement final public: virtual ~HTMLObjectElement() override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; String data() const; void set_data(String const& data) { MUST(set_attribute(HTML::AttributeNames::data, data)); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp index b928d9604f2..407dd26b374 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp @@ -31,12 +31,12 @@ void HTMLOptionElement::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLOptionElement")); } -void HTMLOptionElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLOptionElement::attribute_changed(FlyString const& name, Optional const& value) { HTMLElement::attribute_changed(name, value); if (name == HTML::AttributeNames::selected) { - if (value.is_null()) { + if (!value.has_value()) { // Whenever an option element's selected attribute is removed, if its dirtiness is false, its selectedness must be set to false. if (!m_dirty) m_selected = false; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.h b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.h index 4cda4810b2e..8205e16e59f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.h @@ -40,7 +40,7 @@ private: virtual void initialize(JS::Realm&) override; - void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + void attribute_changed(FlyString const& name, Optional const& value) override; void ask_for_a_reset(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index f2a7dd0d7f2..daaedacb924 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -45,20 +45,20 @@ void HTMLScriptElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_preparation_time_document.ptr()); } -void HTMLScriptElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLScriptElement::attribute_changed(FlyString const& name, Optional const& value) { Base::attribute_changed(name, value); if (name == HTML::AttributeNames::crossorigin) { - if (value.is_null()) + if (!value.has_value()) m_crossorigin = cors_setting_attribute_from_keyword({}); else - m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors()); + m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(*value).release_value_but_fixme_should_propagate_errors()); } else if (name == HTML::AttributeNames::referrerpolicy) { - if (value.is_null()) + if (!value.has_value()) m_referrer_policy.clear(); else - m_referrer_policy = ReferrerPolicy::from_string(value); + m_referrer_policy = ReferrerPolicy::from_string(*value); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h index 506c00d467f..fcd1b7953d5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h @@ -62,7 +62,7 @@ private: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; // https://html.spec.whatwg.org/multipage/scripting.html#prepare-the-script-element void prepare_script(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp index a33fabe86b3..1a87d4c741f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp @@ -24,19 +24,19 @@ HTMLSlotElement::HTMLSlotElement(DOM::Document& document, DOM::QualifiedName qua return; // 2. If value is null and oldValue is the empty string, then return. - if (value.is_null() && old_value == DeprecatedString::empty()) + if (!value.has_value() && old_value == DeprecatedString::empty()) return; // 3. If value is the empty string and oldValue is null, then return. - if (value == DeprecatedString::empty() && old_value.is_null()) + if (value == DeprecatedString::empty() && !old_value.has_value()) return; // 4. If value is null or the empty string, then set element’s name to the empty string. - if (value.is_empty()) + if (!value.has_value()) set_slot_name({}); // 5. Otherwise, set element’s name to value. else - set_slot_name(MUST(String::from_deprecated_string(value))); + set_slot_name(MUST(String::from_deprecated_string(*value))); // 6. Run assign slottables for a tree with element’s root. DOM::assign_slottables_for_a_tree(root()); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp index e74db69cf1d..e3bb7ae090a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp @@ -40,15 +40,15 @@ void HTMLVideoElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_fetch_controller); } -void HTMLVideoElement::attribute_changed(FlyString const& name, DeprecatedString const& value) +void HTMLVideoElement::attribute_changed(FlyString const& name, Optional const& value) { Base::attribute_changed(name, value); if (name == HTML::AttributeNames::poster) { - if (value.is_null()) + if (!value.has_value()) determine_element_poster_frame({}).release_value_but_fixme_should_propagate_errors(); else - determine_element_poster_frame(value).release_value_but_fixme_should_propagate_errors(); + determine_element_poster_frame(*value).release_value_but_fixme_should_propagate_errors(); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h index de2dae0233d..ce22d3f3a27 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h @@ -47,7 +47,7 @@ private: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; - virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override; + virtual void attribute_changed(FlyString const& name, Optional const& value) override; virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; diff --git a/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp index cee0ec0562e..39d5e3520f1 100644 --- a/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp +++ b/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp @@ -76,8 +76,8 @@ WebIDL::ExceptionOr NavigableContainer::create_new_child_navigable() Optional target_name; // 5. If element has a name content attribute, then set targetName to the value of that attribute. - if (auto value = deprecated_attribute(HTML::AttributeNames::name); !value.is_null()) - target_name = String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors(); + if (auto value = attribute(HTML::AttributeNames::name); value.has_value()) + target_name = move(value); // 6. Let documentState be a new document state, with // - document: document @@ -195,7 +195,7 @@ Optional NavigableContainer::shared_attribute_processing_steps_for_ifra // then parse the value of that attribute relative to element's node document. // If this is successful, then set url to the resulting URL record. auto src_attribute_value = deprecated_attribute(HTML::AttributeNames::src); - if (!src_attribute_value.is_null() && !src_attribute_value.is_empty()) { + if (!src_attribute_value.is_empty()) { auto parsed_src = document().parse_url(src_attribute_value); if (parsed_src.is_valid()) url = parsed_src; diff --git a/Userland/Libraries/LibWeb/HTML/Origin.h b/Userland/Libraries/LibWeb/HTML/Origin.h index b93ec8bcf7f..e7b252eddb2 100644 --- a/Userland/Libraries/LibWeb/HTML/Origin.h +++ b/Userland/Libraries/LibWeb/HTML/Origin.h @@ -16,7 +16,7 @@ namespace Web::HTML { class Origin { public: Origin() = default; - Origin(DeprecatedString const& scheme, AK::URL::Host const& host, u16 port) + Origin(Optional const& scheme, AK::URL::Host const& host, u16 port) : m_scheme(scheme) , m_host(host) , m_port(port) @@ -24,9 +24,12 @@ public: } // https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque - bool is_opaque() const { return m_scheme.is_null() && m_host.has() && m_port == 0; } + bool is_opaque() const { return !m_scheme.has_value() && m_host.has() && m_port == 0; } - DeprecatedString const& scheme() const { return m_scheme; } + StringView scheme() const + { + return m_scheme.map([](auto& str) { return str.view(); }).value_or(StringView {}); + } AK::URL::Host const& host() const { return m_host; } u16 port() const { return m_port; } @@ -110,7 +113,7 @@ public: bool operator==(Origin const& other) const { return is_same_origin(other); } private: - DeprecatedString m_scheme; + Optional m_scheme; AK::URL::Host m_host; u16 m_port { 0 }; }; diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index ff101f941ec..c568c84ea3e 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -1092,10 +1092,11 @@ void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_ite CSSPixels default_marker_width = max(4, marker.font().pixel_size_rounded_up() - 4); - if (marker.text().is_empty()) { + auto marker_text = marker.text().value_or(""); + if (marker_text.is_empty()) { marker_state.set_content_width(image_width + default_marker_width); } else { - auto text_width = marker.font().width(marker.text()); + auto text_width = marker.font().width(marker_text); marker_state.set_content_width(image_width + CSSPixels::nearest_value_for(text_width)); } diff --git a/Userland/Libraries/LibWeb/Layout/Label.cpp b/Userland/Libraries/LibWeb/Layout/Label.cpp index 519f5113525..74a83a99173 100644 --- a/Userland/Libraries/LibWeb/Layout/Label.cpp +++ b/Userland/Libraries/LibWeb/Layout/Label.cpp @@ -93,7 +93,7 @@ Label const* Label::label_for_control_node(LabelableNode const& control) // same tree as the label element. If the attribute is specified and there is an element in the tree // whose ID is equal to the value of the for attribute, and the first such element in tree order is // a labelable element, then that element is the label element's labeled control. - if (auto id = control.dom_node().deprecated_attribute(HTML::AttributeNames::id); !id.is_empty()) { + if (auto id = control.dom_node().attribute(HTML::AttributeNames::id); id.has_value() && !id->is_empty()) { Label const* label = nullptr; control.document().layout_node()->for_each_in_inclusive_subtree_of_type