瀏覽代碼

LibURL+LibWeb: Make URL::serialize return a String

Simplifying a bunch of uneeded error handling around the place.
Shannon Booth 8 月之前
父節點
當前提交
0fa54c2327
共有 52 個文件被更改,包括 88 次插入103 次删除
  1. 2 9
      Libraries/LibURL/URL.cpp
  2. 4 4
      Libraries/LibURL/URL.h
  3. 1 1
      Libraries/LibWeb/CSS/CSSFontFaceRule.cpp
  4. 1 1
      Libraries/LibWeb/CSS/CSSImportRule.cpp
  5. 1 1
      Libraries/LibWeb/CSS/CSSImportRule.h
  6. 2 2
      Libraries/LibWeb/CSS/CSSStyleSheet.cpp
  7. 1 1
      Libraries/LibWeb/CSS/Parser/RuleParsing.cpp
  8. 2 2
      Libraries/LibWeb/CSS/StyleComputer.cpp
  9. 1 1
      Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp
  10. 1 1
      Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
  11. 3 3
      Libraries/LibWeb/DOM/Document.cpp
  12. 1 1
      Libraries/LibWeb/DOM/Document.h
  13. 1 1
      Libraries/LibWeb/DOM/Node.cpp
  14. 8 13
      Libraries/LibWeb/DOMURL/DOMURL.cpp
  15. 3 3
      Libraries/LibWeb/DOMURL/DOMURL.h
  16. 2 2
      Libraries/LibWeb/Fetch/Request.cpp
  17. 1 1
      Libraries/LibWeb/Fetch/Response.cpp
  18. 3 4
      Libraries/LibWeb/FileAPI/BlobURLStore.cpp
  19. 1 1
      Libraries/LibWeb/FileAPI/BlobURLStore.h
  20. 1 1
      Libraries/LibWeb/FileAPI/FileReader.cpp
  21. 1 1
      Libraries/LibWeb/HTML/BrowsingContext.cpp
  22. 1 1
      Libraries/LibWeb/HTML/EventSource.h
  23. 1 1
      Libraries/LibWeb/HTML/FormAssociatedElement.cpp
  24. 1 1
      Libraries/LibWeb/HTML/HTMLBaseElement.cpp
  25. 1 1
      Libraries/LibWeb/HTML/HTMLCanvasElement.cpp
  26. 1 1
      Libraries/LibWeb/HTML/HTMLFormElement.cpp
  27. 3 3
      Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp
  28. 1 1
      Libraries/LibWeb/HTML/HTMLImageElement.cpp
  29. 1 1
      Libraries/LibWeb/HTML/HTMLLinkElement.cpp
  30. 2 2
      Libraries/LibWeb/HTML/HTMLMediaElement.cpp
  31. 1 1
      Libraries/LibWeb/HTML/HTMLObjectElement.cpp
  32. 1 3
      Libraries/LibWeb/HTML/Location.cpp
  33. 1 1
      Libraries/LibWeb/HTML/Navigable.cpp
  34. 2 2
      Libraries/LibWeb/HTML/NavigationDestination.cpp
  35. 1 1
      Libraries/LibWeb/HTML/NavigationDestination.h
  36. 2 2
      Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp
  37. 1 1
      Libraries/LibWeb/HTML/NavigationHistoryEntry.h
  38. 3 3
      Libraries/LibWeb/HTML/Scripting/Fetching.cpp
  39. 2 2
      Libraries/LibWeb/HTML/Scripting/ImportMap.cpp
  40. 1 1
      Libraries/LibWeb/HTML/WorkerLocation.cpp
  41. 2 2
      Libraries/LibWeb/MixedContent/AbstractOperations.cpp
  42. 1 1
      Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp
  43. 1 1
      Libraries/LibWeb/ServiceWorker/Job.cpp
  44. 4 4
      Libraries/LibWeb/ServiceWorker/Registration.cpp
  45. 3 3
      Libraries/LibWeb/WebSockets/WebSocket.cpp
  46. 1 1
      Libraries/LibWeb/WebSockets/WebSocket.h
  47. 1 1
      Libraries/LibWebView/URL.cpp
  48. 1 1
      Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp
  49. 3 3
      Services/RequestServer/ConnectionFromClient.cpp
  50. 1 1
      Services/WebContent/PageClient.cpp
  51. 1 1
      Tests/LibWebView/TestWebViewURL.cpp
  52. 1 1
      UI/Android/src/main/cpp/WebViewImplementationNative.cpp

+ 2 - 9
Libraries/LibURL/URL.cpp

@@ -245,7 +245,7 @@ String URL::serialize_path() const
 }
 
 // https://url.spec.whatwg.org/#concept-url-serializer
-ByteString URL::serialize(ExcludeFragment exclude_fragment) const
+String URL::serialize(ExcludeFragment exclude_fragment) const
 {
     // 1. Let output be url’s scheme and U+003A (:) concatenated.
     StringBuilder output;
@@ -307,7 +307,7 @@ ByteString URL::serialize(ExcludeFragment exclude_fragment) const
     }
 
     // 7. Return output.
-    return output.to_byte_string();
+    return output.to_string_without_validation();
 }
 
 // https://url.spec.whatwg.org/#url-rendering
@@ -353,19 +353,12 @@ ByteString URL::serialize_for_display() const
     return builder.to_byte_string();
 }
 
-ErrorOr<String> URL::to_string() const
-{
-    return String::from_byte_string(serialize());
-}
-
 // https://url.spec.whatwg.org/#concept-url-origin
 Origin URL::origin() const
 {
     // The origin of a URL url is the origin returned by running these steps, switching on url’s scheme:
     // -> "blob"
     if (scheme() == "blob"sv) {
-        auto url_string = to_string().release_value_but_fixme_should_propagate_errors();
-
         // 1. If url’s blob URL entry is non-null, then return url’s blob URL entry’s environment’s origin.
         if (blob_url_entry().has_value())
             return blob_url_entry()->environment_origin;

+ 4 - 4
Libraries/LibURL/URL.h

@@ -117,10 +117,10 @@ public:
     }
 
     String serialize_path() const;
-    ByteString serialize(ExcludeFragment = ExcludeFragment::No) const;
+    String serialize(ExcludeFragment = ExcludeFragment::No) const;
     ByteString serialize_for_display() const;
-    ByteString to_byte_string() const { return serialize(); }
-    ErrorOr<String> to_string() const;
+    ByteString to_byte_string() const { return serialize().to_byte_string(); }
+    String to_string() const { return serialize(); }
 
     Origin origin() const;
 
@@ -214,5 +214,5 @@ struct AK::Formatter<URL::URL> : AK::Formatter<StringView> {
 
 template<>
 struct AK::Traits<URL::URL> : public AK::DefaultTraits<URL::URL> {
-    static unsigned hash(URL::URL const& url) { return url.to_byte_string().hash(); }
+    static unsigned hash(URL::URL const& url) { return url.to_string().hash(); }
 };

+ 1 - 1
Libraries/LibWeb/CSS/CSSFontFaceRule.cpp

@@ -66,7 +66,7 @@ String CSSFontFaceRule::serialized() const
         // 2. The result of invoking serialize a comma-separated list on performing serialize a URL or serialize a LOCAL for each source on the source list.
         serialize_a_comma_separated_list(builder, m_font_face.sources(), [&](StringBuilder& builder, ParsedFontFace::Source source) -> void {
             if (source.local_or_url.has<URL::URL>()) {
-                serialize_a_url(builder, MUST(source.local_or_url.get<URL::URL>().to_string()));
+                serialize_a_url(builder, source.local_or_url.get<URL::URL>().to_string());
             } else {
                 builder.appendff("local({})", source.local_or_url.get<String>());
             }

+ 1 - 1
Libraries/LibWeb/CSS/CSSImportRule.cpp

@@ -66,7 +66,7 @@ String CSSImportRule::serialized() const
     builder.append("@import "sv);
 
     // 2. The result of performing serialize a URL on the rule’s location.
-    serialize_a_url(builder, MUST(m_url.to_string()));
+    serialize_a_url(builder, m_url.to_string());
 
     // FIXME: 3. If the rule’s associated media list is not empty, a single SPACE (U+0020) followed by the result of performing serialize a media query list on the media list.
 

+ 1 - 1
Libraries/LibWeb/CSS/CSSImportRule.h

@@ -29,7 +29,7 @@ public:
 
     URL::URL const& url() const { return m_url; }
     // FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css".
-    String href() const { return MUST(m_url.to_string()); }
+    String href() const { return m_url.to_string(); }
 
     CSSStyleSheet* loaded_style_sheet() { return m_style_sheet; }
     CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; }

+ 2 - 2
Libraries/LibWeb/CSS/CSSStyleSheet.cpp

@@ -36,7 +36,7 @@ WebIDL::ExceptionOr<GC::Ref<CSSStyleSheet>> CSSStyleSheet::construct_impl(JS::Re
 
     // 2. Set sheet’s location to the base URL of the associated Document for the current principal global object.
     auto associated_document = verify_cast<HTML::Window>(HTML::current_principal_global_object()).document();
-    sheet->set_location(MUST(associated_document->base_url().to_string()));
+    sheet->set_location(associated_document->base_url().to_string());
 
     // 3. Set sheet’s stylesheet base URL to the baseURL attribute value from options.
     if (options.has_value() && options->base_url.has_value()) {
@@ -99,7 +99,7 @@ CSSStyleSheet::CSSStyleSheet(JS::Realm& realm, CSSRuleList& rules, MediaList& me
     , m_rules(&rules)
 {
     if (location.has_value())
-        set_location(MUST(location->to_string()));
+        set_location(location->to_string());
 
     for (auto& rule : *m_rules)
         rule->set_parent_style_sheet(this);

+ 1 - 1
Libraries/LibWeb/CSS/Parser/RuleParsing.cpp

@@ -426,7 +426,7 @@ GC::Ptr<CSSNamespaceRule> Parser::convert_to_namespace_rule(AtRule const& rule)
 
     FlyString namespace_uri;
     if (auto url = parse_url_function(tokens); url.has_value()) {
-        namespace_uri = MUST(url.value().to_string());
+        namespace_uri = url.value().to_string();
     } else if (auto& url_token = tokens.consume_a_token(); url_token.is(Token::Type::String)) {
         namespace_uri = url_token.token().string();
     } else {

+ 2 - 2
Libraries/LibWeb/CSS/StyleComputer.cpp

@@ -247,7 +247,7 @@ void FontLoader::start_loading_next_url()
     //       request until fetch infrastructure is used here.
     auto referrer_url = ReferrerPolicy::strip_url_for_use_as_referrer(m_style_computer.document().url());
     if (referrer_url.has_value() && !request.headers().contains("Referer"))
-        request.set_header("Referer", referrer_url->serialize());
+        request.set_header("Referer", referrer_url->serialize().to_byte_string());
 
     set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
 }
@@ -2836,7 +2836,7 @@ Optional<FontLoader&> StyleComputer::load_font_face(ParsedFontFace const& font_f
     for (auto const& source : font_face.sources()) {
         // FIXME: These should be loaded relative to the stylesheet URL instead of the document URL.
         if (source.local_or_url.has<URL::URL>())
-            urls.append(m_document->parse_url(MUST(source.local_or_url.get<URL::URL>().to_string())));
+            urls.append(m_document->parse_url(source.local_or_url.get<URL::URL>().to_string()));
         // FIXME: Handle local()
     }
 

+ 1 - 1
Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp

@@ -114,7 +114,7 @@ Gfx::ImmutableBitmap const* ImageStyleValue::bitmap(size_t frame_index, Gfx::Int
 
 String ImageStyleValue::to_string() const
 {
-    return serialize_a_url(MUST(m_url.to_string()));
+    return serialize_a_url(m_url.to_string());
 }
 
 bool ImageStyleValue::equals(CSSStyleValue const& other) const

+ 1 - 1
Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h

@@ -27,7 +27,7 @@ public:
 
     virtual String to_string() const override
     {
-        return serialize_a_url(MUST(m_url.to_string()));
+        return serialize_a_url(m_url.to_string());
     }
 
 private:

+ 3 - 3
Libraries/LibWeb/DOM/Document.cpp

@@ -344,7 +344,7 @@ WebIDL::ExceptionOr<GC::Ref<Document>> Document::create_and_initialize(Type type
 
         // 3. If referrer is a URL record, then set document's referrer to the serialization of referrer.
         if (referrer.has<URL::URL>()) {
-            document->m_referrer = MUST(String::from_byte_string(referrer.get<URL::URL>().serialize()));
+            document->m_referrer = referrer.get<URL::URL>().serialize();
         }
     }
 
@@ -4468,8 +4468,8 @@ void Document::update_for_history_step_application(GC::Ref<HTML::SessionHistoryE
             //    initialized to the serialization of entry's URL.
             if (old_url.fragment() != entry->url().fragment()) {
                 HTML::HashChangeEventInit hashchange_event_init;
-                hashchange_event_init.old_url = MUST(String::from_byte_string(old_url.serialize()));
-                hashchange_event_init.new_url = MUST(String::from_byte_string(entry->url().serialize()));
+                hashchange_event_init.old_url = old_url.serialize();
+                hashchange_event_init.new_url = entry->url().serialize();
                 auto hashchange_event = HTML::HashChangeEvent::create(realm(), "hashchange"_fly_string, hashchange_event_init);
                 HTML::queue_global_task(HTML::Task::Source::DOMManipulation, relevant_global_object, GC::create_function(heap(), [hashchange_event, &relevant_global_object]() {
                     relevant_global_object.dispatch_event(hashchange_event);

+ 1 - 1
Libraries/LibWeb/DOM/Document.h

@@ -147,7 +147,7 @@ public:
     void update_base_element(Badge<HTML::HTMLBaseElement>);
     GC::Ptr<HTML::HTMLBaseElement const> first_base_element_with_href_in_tree_order() const;
 
-    String url_string() const { return MUST(m_url.to_string()); }
+    String url_string() const { return m_url.to_string(); }
     String document_uri() const { return url_string(); }
 
     URL::Origin origin() const;

+ 1 - 1
Libraries/LibWeb/DOM/Node.cpp

@@ -125,7 +125,7 @@ void Node::visit_edges(Cell::Visitor& visitor)
 String Node::base_uri() const
 {
     // Return this’s node document’s document base URL, serialized.
-    return MUST(document().base_url().to_string());
+    return document().base_url().to_string();
 }
 
 const HTML::HTMLAnchorElement* Node::enclosing_link_element() const

+ 8 - 13
Libraries/LibWeb/DOMURL/DOMURL.cpp

@@ -131,14 +131,14 @@ WebIDL::ExceptionOr<String> DOMURL::create_object_url(JS::VM& vm, GC::Ref<FileAP
 }
 
 // https://w3c.github.io/FileAPI/#dfn-revokeObjectURL
-WebIDL::ExceptionOr<void> DOMURL::revoke_object_url(JS::VM& vm, StringView url)
+void DOMURL::revoke_object_url(JS::VM&, StringView url)
 {
     // 1. Let url record be the result of parsing url.
     auto url_record = parse(url);
 
     // 2. If url record’s scheme is not "blob", return.
     if (url_record.scheme() != "blob"sv)
-        return {};
+        return;
 
     // 3. Let origin be the origin of url record.
     auto origin = url_record.origin();
@@ -148,11 +148,10 @@ WebIDL::ExceptionOr<void> DOMURL::revoke_object_url(JS::VM& vm, StringView url)
 
     // 5. If origin is not same origin with settings’s origin, return.
     if (!origin.is_same_origin(settings.origin()))
-        return {};
+        return;
 
     // 6. Remove an entry from the Blob URL Store for url.
-    TRY_OR_THROW_OOM(vm, FileAPI::remove_entry_from_blob_url_store(url));
-    return {};
+    FileAPI::remove_entry_from_blob_url_store(url);
 }
 
 // https://url.spec.whatwg.org/#dom-url-canparse
@@ -170,21 +169,17 @@ bool DOMURL::can_parse(JS::VM&, String const& url, Optional<String> const& base)
 }
 
 // https://url.spec.whatwg.org/#dom-url-href
-WebIDL::ExceptionOr<String> DOMURL::href() const
+String DOMURL::href() const
 {
-    auto& vm = realm().vm();
-
     // The href getter steps and the toJSON() method steps are to return the serialization of this’s URL.
-    return TRY_OR_THROW_OOM(vm, String::from_byte_string(m_url.serialize()));
+    return m_url.serialize();
 }
 
 // https://url.spec.whatwg.org/#dom-url-tojson
-WebIDL::ExceptionOr<String> DOMURL::to_json() const
+String DOMURL::to_json() const
 {
-    auto& vm = realm().vm();
-
     // The href getter steps and the toJSON() method steps are to return the serialization of this’s URL.
-    return TRY_OR_THROW_OOM(vm, String::from_byte_string(m_url.serialize()));
+    return m_url.serialize();
 }
 
 // https://url.spec.whatwg.org/#ref-for-dom-url-href②

+ 3 - 3
Libraries/LibWeb/DOMURL/DOMURL.h

@@ -27,12 +27,12 @@ public:
     virtual ~DOMURL() override;
 
     static WebIDL::ExceptionOr<String> create_object_url(JS::VM&, GC::Ref<FileAPI::Blob> object);
-    static WebIDL::ExceptionOr<void> revoke_object_url(JS::VM&, StringView url);
+    static void revoke_object_url(JS::VM&, StringView url);
 
     static GC::Ptr<DOMURL> parse_for_bindings(JS::VM&, String const& url, Optional<String> const& base = {});
     static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
 
-    WebIDL::ExceptionOr<String> href() const;
+    String href() const;
     WebIDL::ExceptionOr<void> set_href(String const&);
 
     String origin() const;
@@ -75,7 +75,7 @@ public:
     WebIDL::ExceptionOr<String> hash() const;
     void set_hash(String const&);
 
-    WebIDL::ExceptionOr<String> to_json() const;
+    String to_json() const;
 
     Optional<String> const& query() const { return m_url.query(); }
     void set_query(Badge<URLSearchParams>, Optional<String> query) { m_url.set_query(move(query)); }

+ 2 - 2
Libraries/LibWeb/Fetch/Request.cpp

@@ -514,7 +514,7 @@ String Request::method() const
 String Request::url() const
 {
     // The url getter steps are to return this’s request’s URL, serialized.
-    return MUST(String::from_byte_string(m_request->url().serialize()));
+    return m_request->url().serialize();
 }
 
 // https://fetch.spec.whatwg.org/#dom-request-headers
@@ -549,7 +549,7 @@ String Request::referrer() const
         },
         [&](URL::URL const& url) {
             // 3. Return this’s request’s referrer, serialized.
-            return MUST(String::from_byte_string(url.serialize()));
+            return url.serialize();
         });
 }
 

+ 1 - 1
Libraries/LibWeb/Fetch/Response.cpp

@@ -236,7 +236,7 @@ String Response::url() const
     // The url getter steps are to return the empty string if this’s response’s URL is null; otherwise this’s response’s URL, serialized with exclude fragment set to true.
     return !m_response->url().has_value()
         ? String {}
-        : MUST(String::from_byte_string(m_response->url()->serialize(URL::ExcludeFragment::Yes)));
+        : m_response->url()->serialize(URL::ExcludeFragment::Yes);
 }
 
 // https://fetch.spec.whatwg.org/#dom-response-redirected

+ 3 - 4
Libraries/LibWeb/FileAPI/BlobURLStore.cpp

@@ -79,17 +79,16 @@ ErrorOr<String> add_entry_to_blob_url_store(GC::Ref<Blob> object)
 }
 
 // https://w3c.github.io/FileAPI/#removeTheEntry
-ErrorOr<void> remove_entry_from_blob_url_store(StringView url)
+void remove_entry_from_blob_url_store(StringView url)
 {
     // 1. Let store be the user agent’s blob URL store;
     auto& store = blob_url_store();
 
     // 2. Let url string be the result of serializing url.
-    auto url_string = TRY(URL::URL { url }.to_string());
+    auto url_string = URL::URL { url }.to_string();
 
     // 3. Remove store[url string].
     store.remove(url_string);
-    return {};
 }
 
 // https://w3c.github.io/FileAPI/#lifeTime
@@ -117,7 +116,7 @@ Optional<BlobURLEntry const&> resolve_a_blob_url(URL::URL const& url)
     auto& store = blob_url_store();
 
     // 3. Let url string be the result of serializing url with the exclude fragment flag set.
-    auto url_string = MUST(String::from_byte_string(url.serialize(URL::ExcludeFragment::Yes)));
+    auto url_string = url.serialize(URL::ExcludeFragment::Yes);
 
     // 4. If store[url string] exists, return store[url string]; otherwise return failure.
     return store.get(url_string);

+ 1 - 1
Libraries/LibWeb/FileAPI/BlobURLStore.h

@@ -27,7 +27,7 @@ using BlobURLStore = HashMap<String, BlobURLEntry>;
 BlobURLStore& blob_url_store();
 ErrorOr<String> generate_new_blob_url();
 ErrorOr<String> add_entry_to_blob_url_store(GC::Ref<Blob> object);
-ErrorOr<void> remove_entry_from_blob_url_store(StringView url);
+void remove_entry_from_blob_url_store(StringView url);
 Optional<BlobURLEntry const&> resolve_a_blob_url(URL::URL const&);
 
 void run_unloading_cleanup_steps(GC::Ref<DOM::Document>);

+ 1 - 1
Libraries/LibWeb/FileAPI/FileReader.cpp

@@ -72,7 +72,7 @@ WebIDL::ExceptionOr<FileReader::Result> FileReader::blob_package_data(JS::Realm&
         // Return bytes as a DataURL [RFC2397] subject to the considerations below:
         // Use mimeType as part of the Data URL if it is available in keeping with the Data URL specification [RFC2397].
         // If mimeType is not available return a Data URL without a media-type. [RFC2397].
-        return MUST(URL::create_with_data(mime_type.value_or(String {}), MUST(encode_base64(bytes)), true).to_string());
+        return URL::create_with_data(mime_type.value_or(String {}), MUST(encode_base64(bytes)), true).to_string();
     case Type::Text: {
         // 1. Let encoding be failure.
         Optional<StringView> encoding;

+ 1 - 1
Libraries/LibWeb/HTML/BrowsingContext.cpp

@@ -256,7 +256,7 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
     // 16. If creator is non-null, then:
     if (creator) {
         // 1. Set document's referrer to the serialization of creator's URL.
-        document->set_referrer(MUST(String::from_byte_string(creator->url().serialize())));
+        document->set_referrer(creator->url().serialize());
 
         // 2. Set document's policy container to a clone of creator's policy container.
         document->set_policy_container(creator->policy_container());

+ 1 - 1
Libraries/LibWeb/HTML/EventSource.h

@@ -34,7 +34,7 @@ public:
     static WebIDL::ExceptionOr<GC::Ref<EventSource>> construct_impl(JS::Realm&, StringView url, EventSourceInit event_source_init_dict = {});
 
     // https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource-url
-    String url() const { return MUST(String::from_byte_string(m_url.serialize())); }
+    String url() const { return m_url.serialize(); }
 
     // https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource-withcredentials
     bool with_credentials() const { return m_with_credentials; }

+ 1 - 1
Libraries/LibWeb/HTML/FormAssociatedElement.cpp

@@ -191,7 +191,7 @@ String FormAssociatedElement::form_action() const
     }
 
     auto document_base_url = html_element.document().base_url();
-    return MUST(document_base_url.complete_url(form_action_attribute.value()).to_string());
+    return document_base_url.complete_url(form_action_attribute.value()).to_string();
 }
 
 WebIDL::ExceptionOr<void> FormAssociatedElement::set_form_action(String const& value)

+ 1 - 1
Libraries/LibWeb/HTML/HTMLBaseElement.cpp

@@ -100,7 +100,7 @@ String HTMLBaseElement::href() const
         return url;
 
     // 5. Return the serialization of urlRecord.
-    return MUST(url_record.to_string());
+    return url_record.to_string();
 }
 
 // https://html.spec.whatwg.org/multipage/semantics.html#dom-base-href

+ 1 - 1
Libraries/LibWeb/HTML/HTMLCanvasElement.cpp

@@ -312,7 +312,7 @@ String HTMLCanvasElement::to_data_url(StringView type, JS::Value quality)
     if (base64_encoded_or_error.is_error()) {
         return "data:,"_string;
     }
-    return MUST(URL::create_with_data(file.value().mime_type, base64_encoded_or_error.release_value(), true).to_string());
+    return URL::create_with_data(file.value().mime_type, base64_encoded_or_error.release_value(), true).to_string();
 }
 
 // https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob

+ 1 - 1
Libraries/LibWeb/HTML/HTMLFormElement.cpp

@@ -593,7 +593,7 @@ String HTMLFormElement::action() const
         return document().url_string();
     }
 
-    return MUST(document().base_url().complete_url(form_action_attribute.value()).to_string());
+    return document().base_url().complete_url(form_action_attribute.value()).to_string();
 }
 
 // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-action

+ 3 - 3
Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp

@@ -424,7 +424,7 @@ String HTMLHyperlinkElementUtils::href() const
         return href_content_attribute.release_value();
 
     // 5. Return url, serialized.
-    return MUST(String::from_byte_string(url->serialize()));
+    return url->serialize();
 }
 
 // https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-href
@@ -438,7 +438,7 @@ WebIDL::ExceptionOr<void> HTMLHyperlinkElementUtils::set_href(String href)
 void HTMLHyperlinkElementUtils::update_href()
 {
     // To update href, set the element's href content attribute's value to the element's url, serialized.
-    MUST(set_hyperlink_element_utils_href(MUST(String::from_byte_string(m_url->serialize()))));
+    MUST(set_hyperlink_element_utils_href(m_url->serialize()));
 }
 
 bool HTMLHyperlinkElementUtils::cannot_navigate() const
@@ -492,7 +492,7 @@ void HTMLHyperlinkElementUtils::follow_the_hyperlink(Optional<String> hyperlink_
     if (!url.is_valid())
         return;
 
-    auto url_string = MUST(url.to_string());
+    auto url_string = url.to_string();
 
     // 10. If hyperlinkSuffix is non-null, then append it to urlString.
     if (hyperlink_suffix.has_value()) {

+ 1 - 1
Libraries/LibWeb/HTML/HTMLImageElement.cpp

@@ -306,7 +306,7 @@ String HTMLImageElement::current_src() const
     auto current_url = m_current_request->current_url();
     if (!current_url.is_valid())
         return {};
-    return MUST(current_url.to_string());
+    return current_url.to_string();
 }
 
 // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode

+ 1 - 1
Libraries/LibWeb/HTML/HTMLLinkElement.cpp

@@ -433,7 +433,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru
                 if (m_loaded_style_sheet) {
                     Optional<String> location;
                     if (!response.url_list().is_empty())
-                        location = MUST(response.url_list().first().to_string());
+                        location = response.url_list().first().to_string();
 
                     document().style_sheets().create_a_css_style_sheet(
                         "text/css"_string,

+ 2 - 2
Libraries/LibWeb/HTML/HTMLMediaElement.cpp

@@ -628,7 +628,7 @@ public:
         //    would have resulted from parsing the URL specified by candidate's src attribute's value relative to the
         //    candidate's node document when the src attribute was last changed.
         auto url_record = m_candidate->document().parse_url(candiate_src);
-        auto url_string = MUST(url_record.to_string());
+        auto url_string = url_record.to_string();
 
         // 4. ⌛ If urlString was not obtained successfully, then end the synchronous section, and jump down to the failed
         //    with elements step below.
@@ -875,7 +875,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::select_resource()
 
         // 3. ⌛ If urlString was obtained successfully, set the currentSrc attribute to urlString.
         if (url_record.is_valid())
-            m_current_src = MUST(url_record.to_string());
+            m_current_src = url_record.to_string();
 
         // 4. End the synchronous section, continuing the remaining steps in parallel.
 

+ 1 - 1
Libraries/LibWeb/HTML/HTMLObjectElement.cpp

@@ -137,7 +137,7 @@ String HTMLObjectElement::data() const
     if (!data.has_value())
         return {};
 
-    return MUST(document().parse_url(*data).to_string());
+    return document().parse_url(*data).to_string();
 }
 
 GC::Ptr<Layout::Node> HTMLObjectElement::create_layout_node(CSS::StyleProperties style)

+ 1 - 3
Libraries/LibWeb/HTML/Location.cpp

@@ -95,15 +95,13 @@ URL::URL Location::url() const
 // https://html.spec.whatwg.org/multipage/history.html#dom-location-href
 WebIDL::ExceptionOr<String> Location::href() const
 {
-    auto& vm = this->vm();
-
     // 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
     auto const relevant_document = this->relevant_document();
     if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
         return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"_string);
 
     // 2. Return this's url, serialized.
-    return TRY_OR_THROW_OOM(vm, String::from_byte_string(url().serialize()));
+    return url().serialize();
 }
 
 // https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2

+ 1 - 1
Libraries/LibWeb/HTML/Navigable.cpp

@@ -1600,7 +1600,7 @@ WebIDL::ExceptionOr<GC::Ptr<DOM::Document>> Navigable::evaluate_javascript_url(U
     auto url_string = url.serialize();
 
     // 2. Let encodedScriptSource be the result of removing the leading "javascript:" from urlString.
-    auto encoded_script_source = url_string.substring_view(11, url_string.length() - 11);
+    auto encoded_script_source = url_string.bytes_as_string_view().substring_view(11);
 
     // 3. Let scriptSource be the UTF-8 decoding of the percent-decoding of encodedScriptSource.
     auto script_source = URL::percent_decode(encoded_script_source);

+ 2 - 2
Libraries/LibWeb/HTML/NavigationDestination.cpp

@@ -40,10 +40,10 @@ void NavigationDestination::visit_edges(JS::Cell::Visitor& visitor)
 }
 
 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-url
-WebIDL::ExceptionOr<String> NavigationDestination::url() const
+String NavigationDestination::url() const
 {
     // The url getter steps are to return this's URL, serialized.
-    return TRY_OR_THROW_OOM(vm(), String::from_byte_string(m_url.serialize()));
+    return m_url.serialize();
 }
 
 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-key

+ 1 - 1
Libraries/LibWeb/HTML/NavigationDestination.h

@@ -20,7 +20,7 @@ class NavigationDestination : public Bindings::PlatformObject {
 public:
     [[nodiscard]] static GC::Ref<NavigationDestination> create(JS::Realm&);
 
-    WebIDL::ExceptionOr<String> url() const;
+    String url() const;
     String key() const;
     String id() const;
     i64 index() const;

+ 2 - 2
Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp

@@ -44,7 +44,7 @@ void NavigationHistoryEntry::visit_edges(JS::Cell::Visitor& visitor)
 }
 
 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationhistoryentry-url
-WebIDL::ExceptionOr<Optional<String>> NavigationHistoryEntry::url() const
+Optional<String> NavigationHistoryEntry::url() const
 {
     // The url getter steps are:
     // 1. Let document be this's relevant global object's associated Document.
@@ -65,7 +65,7 @@ WebIDL::ExceptionOr<Optional<String>> NavigationHistoryEntry::url() const
         return OptionalNone {};
 
     // 5. Return she's URL, serialized.
-    return TRY_OR_THROW_OOM(vm(), String::from_byte_string(she->url().serialize()));
+    return she->url().serialize();
 }
 
 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationhistoryentry-key

+ 1 - 1
Libraries/LibWeb/HTML/NavigationHistoryEntry.h

@@ -18,7 +18,7 @@ class NavigationHistoryEntry : public DOM::EventTarget {
 public:
     [[nodiscard]] static GC::Ref<NavigationHistoryEntry> create(JS::Realm&, GC::Ref<SessionHistoryEntry>);
 
-    WebIDL::ExceptionOr<Optional<String>> url() const;
+    Optional<String> url() const;
     String key() const;
     String id() const;
     i64 index() const;

+ 3 - 3
Libraries/LibWeb/HTML/Scripting/Fetching.cpp

@@ -127,7 +127,7 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referri
     auto as_url = resolve_url_like_module_specifier(specifier, *base_url);
 
     // 8. Let normalizedSpecifier be the serialization of asURL, if asURL is non-null; otherwise, specifier.
-    auto normalized_specifier = as_url.has_value() ? as_url->serialize() : specifier;
+    auto normalized_specifier = as_url.has_value() ? as_url->serialize().to_byte_string() : specifier;
 
     // 9. For each scopePrefix → scopeImports of importMap's scopes:
     for (auto const& entry : import_map.scopes()) {
@@ -137,7 +137,7 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referri
         auto const& scope_imports = entry.value;
 
         // 1. If scopePrefix is baseURLString, or if scopePrefix ends with U+002F (/) and scopePrefix is a code unit prefix of baseURLString, then:
-        if (scope_prefix == base_url_string || (scope_prefix.ends_with("/"sv) && Infra::is_code_unit_prefix(scope_prefix, base_url_string))) {
+        if (scope_prefix == base_url_string || (scope_prefix.ends_with('/') && Infra::is_code_unit_prefix(scope_prefix, base_url_string))) {
             // 1. Let scopeImportsMatch be the result of resolving an imports match given normalizedSpecifier, asURL, and scopeImports.
             auto scope_imports_match = TRY(resolve_imports_match(normalized_specifier, as_url, scope_imports));
 
@@ -202,7 +202,7 @@ WebIDL::ExceptionOr<Optional<URL::URL>> resolve_imports_match(ByteString const&
             auto after_prefix = normalized_specifier.substring(specifier_key.length());
 
             // 4. Assert: resolutionResult, serialized, ends with U+002F (/), as enforced during parsing.
-            VERIFY(resolution_result->serialize().ends_with("/"sv));
+            VERIFY(resolution_result->serialize().ends_with('/'));
 
             // 5. Let url be the result of URL parsing afterPrefix with resolutionResult.
             auto url = DOMURL::parse(after_prefix, *resolution_result);

+ 2 - 2
Libraries/LibWeb/HTML/Scripting/ImportMap.cpp

@@ -107,7 +107,7 @@ Optional<DeprecatedFlyString> normalise_specifier_key(JS::Realm& realm, Deprecat
 
     // 3. If url is not null, then return the serialization of url.
     if (url.has_value())
-        return url->serialize();
+        return url->serialize().to_byte_string();
 
     // 4. Return specifierKey.
     return specifier_key;
@@ -160,7 +160,7 @@ WebIDL::ExceptionOr<ModuleSpecifierMap> sort_and_normalise_module_specifier_map(
         }
 
         // 6. If specifierKey ends with U+002F (/), and the serialization of addressURL does not end with U+002F (/), then:
-        if (specifier_key.as_string().ends_with("/"sv) && !address_url->serialize().ends_with("/"sv)) {
+        if (specifier_key.as_string().ends_with("/"sv) && !address_url->serialize().ends_with('/')) {
             // 1. The user agent may report a warning to the console indicating that an invalid address was given for the specifier key specifierKey; since specifierKey ends with a slash, the address needs to as well.
             auto& console = realm.intrinsics().console_object()->console();
             console.output_debug_message(JS::Console::LogLevel::Warn,

+ 1 - 1
Libraries/LibWeb/HTML/WorkerLocation.cpp

@@ -17,7 +17,7 @@ GC_DEFINE_ALLOCATOR(WorkerLocation);
 String WorkerLocation::href() const
 {
     // The href getter steps are to return this's WorkerGlobalScope object's url, serialized.
-    return MUST(String::from_byte_string(m_global_scope->url().serialize()));
+    return m_global_scope->url().serialize();
 }
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-origin

+ 2 - 2
Libraries/LibWeb/MixedContent/AbstractOperations.cpp

@@ -86,7 +86,7 @@ Fetch::Infrastructure::RequestOrResponseBlocking should_fetching_request_be_bloc
     }
 
     // 2. Return blocked.
-    dbgln("MixedContent: Blocked '{}' (request)", MUST(request.url().to_string()));
+    dbgln("MixedContent: Blocked '{}' (request)", request.url().to_string());
     return Fetch::Infrastructure::RequestOrResponseBlocking::Blocked;
 }
 
@@ -111,7 +111,7 @@ Web::Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request
     }
 
     // 2. Return blocked.
-    dbgln("MixedContent: Blocked '{}' (response to request)", MUST(request.url().to_string()));
+    dbgln("MixedContent: Blocked '{}' (response to request)", request.url().to_string());
     return Fetch::Infrastructure::RequestOrResponseBlocking::Blocked;
 }
 

+ 1 - 1
Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp

@@ -107,7 +107,7 @@ Optional<URL::URL> determine_requests_referrer(Fetch::Infrastructure::Request co
 
     // 6. If the result of serializing referrerURL is a string whose length is greater than 4096, set referrerURL to
     //    referrerOrigin.
-    if (referrer_url.has_value() && referrer_url.value().serialize().length() > 4096)
+    if (referrer_url.has_value() && referrer_url.value().serialize().bytes().size() > 4096)
         referrer_url = referrer_origin;
 
     // 7. The user agent MAY alter referrerURL or referrerOrigin at this point to enforce arbitrary policy

+ 1 - 1
Libraries/LibWeb/ServiceWorker/Job.cpp

@@ -569,7 +569,7 @@ void schedule_job(JS::VM& vm, GC::Ref<Job> job)
 
     // 2. Let jobScope be job’s scope url, serialized.
     // FIXME: Suspect that spec should specify to not use fragment here
-    auto job_scope = job->scope_url.serialize();
+    auto job_scope = job->scope_url.serialize().to_byte_string();
 
     // 3. If scope to job queue map[jobScope] does not exist, set scope to job queue map[jobScope] to a new job queue.
     // 4. Set jobQueue to scope to job queue map[jobScope].

+ 4 - 4
Libraries/LibWeb/ServiceWorker/Registration.cpp

@@ -32,7 +32,7 @@ bool Registration::is_unregistered()
 {
     // A service worker registration is said to be unregistered if registration map[this service worker registration's (storage key, serialized scope url)] is not this service worker registration.
     // FIXME: Suspect that spec should say to serialize without fragment
-    auto const key = RegistrationKey { m_storage_key, m_scope_url.serialize(URL::ExcludeFragment::Yes) };
+    auto const key = RegistrationKey { m_storage_key, m_scope_url.serialize(URL::ExcludeFragment::Yes).to_byte_string() };
     return s_registrations.get(key).map([](auto& registration) { return &registration; }).value_or(nullptr) != this;
 }
 
@@ -60,7 +60,7 @@ Optional<Registration&> Registration::get(StorageAPI::StorageKey const& key, Opt
 
     // 3. If scope is not null, set scopeString to serialized scope with the exclude fragment flag set.
     if (scope.has_value())
-        scope_string = scope.value().serialize(URL::ExcludeFragment::Yes);
+        scope_string = scope.value().serialize(URL::ExcludeFragment::Yes).to_byte_string();
 
     // 4. For each (entry storage key, entry scope) → registration of registration map:
     //   1. If storage key equals entry storage key and scopeString matches entry scope, then return registration.
@@ -79,14 +79,14 @@ Registration& Registration::set(StorageAPI::StorageKey const& storage_key, URL::
     // 5. Return registration.
 
     // FIXME: Is there a way to "ensure but always replace?"
-    auto key = RegistrationKey { storage_key, scope.serialize(URL::ExcludeFragment::Yes) };
+    auto key = RegistrationKey { storage_key, scope.serialize(URL::ExcludeFragment::Yes).to_byte_string() };
     (void)s_registrations.set(key, Registration(storage_key, scope, update_via_cache));
     return s_registrations.get(key).value();
 }
 
 void Registration::remove(StorageAPI::StorageKey const& key, URL::URL const& scope)
 {
-    (void)s_registrations.remove({ key, scope.serialize(URL::ExcludeFragment::Yes) });
+    (void)s_registrations.remove({ key, scope.serialize(URL::ExcludeFragment::Yes).to_byte_string() });
 }
 
 // https://w3c.github.io/ServiceWorker/#get-newest-worker

+ 3 - 3
Libraries/LibWeb/WebSockets/WebSocket.cpp

@@ -292,7 +292,7 @@ void WebSocket::on_message(ByteBuffer message, bool is_text)
             auto text_message = ByteString(ReadonlyBytes(message));
             HTML::MessageEventInit event_init;
             event_init.data = JS::PrimitiveString::create(vm(), text_message);
-            event_init.origin = url().release_value_but_fixme_should_propagate_errors();
+            event_init.origin = url();
             dispatch_event(HTML::MessageEvent::create(realm(), HTML::EventNames::message, event_init));
             return;
         }
@@ -301,14 +301,14 @@ void WebSocket::on_message(ByteBuffer message, bool is_text)
             // type indicates that the data is Binary and binaryType is "blob"
             HTML::MessageEventInit event_init;
             event_init.data = FileAPI::Blob::create(realm(), message, "text/plain;charset=utf-8"_string);
-            event_init.origin = url().release_value_but_fixme_should_propagate_errors();
+            event_init.origin = url();
             dispatch_event(HTML::MessageEvent::create(realm(), HTML::EventNames::message, event_init));
             return;
         } else if (m_binary_type == "arraybuffer") {
             // type indicates that the data is Binary and binaryType is "arraybuffer"
             HTML::MessageEventInit event_init;
             event_init.data = JS::ArrayBuffer::create(realm(), message);
-            event_init.origin = url().release_value_but_fixme_should_propagate_errors();
+            event_init.origin = url();
             dispatch_event(HTML::MessageEvent::create(realm(), HTML::EventNames::message, event_init));
             return;
         }

+ 1 - 1
Libraries/LibWeb/WebSockets/WebSocket.h

@@ -35,7 +35,7 @@ public:
 
     virtual ~WebSocket() override;
 
-    WebIDL::ExceptionOr<String> url() const { return TRY_OR_THROW_OOM(vm(), m_url.to_string()); }
+    String url() const { return m_url.to_string(); }
     void set_url(URL::URL url) { m_url = move(url); }
 
 #undef __ENUMERATE

+ 1 - 1
Libraries/LibWebView/URL.cpp

@@ -139,7 +139,7 @@ URLType url_type(URL::URL const& url)
 
 String url_text_to_copy(URL::URL const& url)
 {
-    auto url_text = MUST(url.to_string());
+    auto url_text = url.to_string();
 
     if (url.scheme() == "mailto"sv)
         return MUST(url_text.substring_from_byte_offset("mailto:"sv.length()));

+ 1 - 1
Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp

@@ -3775,7 +3775,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.getter_callback@)
 
     auto url_string = impl->document().parse_url(*content_attribute_value);
     if (url_string.is_valid())
-        return JS::PrimitiveString::create(vm, MUST(url_string.to_string()));
+        return JS::PrimitiveString::create(vm, url_string.to_string());
 )~~~");
                 }
 

+ 3 - 3
Services/RequestServer/ConnectionFromClient.cpp

@@ -377,7 +377,7 @@ void ConnectionFromClient::start_request(i32 request_id, ByteString const& metho
             async_request_started(request_id, IPC::File::adopt_fd(reader_fd));
 
             auto request = make<ActiveRequest>(*this, m_curl_multi, easy, request_id, writer_fd);
-            request->url = url.to_string().value();
+            request->url = url.to_string();
 
             auto set_option = [easy](auto option, auto value) {
                 auto result = curl_easy_setopt(easy, option, value);
@@ -394,7 +394,7 @@ void ConnectionFromClient::start_request(i32 request_id, ByteString const& metho
                 set_option(CURLOPT_CAINFO, g_default_certificate_path.characters());
 
             set_option(CURLOPT_ACCEPT_ENCODING, "gzip, deflate, br");
-            set_option(CURLOPT_URL, url.to_string().value().to_byte_string().characters());
+            set_option(CURLOPT_URL, url.to_string().to_byte_string().characters());
             set_option(CURLOPT_PORT, url.port_or_default());
             set_option(CURLOPT_CONNECTTIMEOUT, s_connect_timeout_seconds);
 
@@ -568,7 +568,7 @@ void ConnectionFromClient::ensure_connection(URL::URL const& url, ::RequestServe
         return;
     }
 
-    auto const url_string_value = url.to_string().value();
+    auto const url_string_value = url.to_string();
 
     if (cache_level == CacheLevel::CreateConnection) {
         auto* easy = curl_easy_init();

+ 1 - 1
Services/WebContent/PageClient.cpp

@@ -787,7 +787,7 @@ static void gather_style_sheets(Vector<Web::CSS::StyleSheetIdentifier>& results,
         } else {
             // We can gather this anyway, and hope it loads later
             results.append({ .type = Web::CSS::StyleSheetIdentifier::Type::ImportRule,
-                .url = MUST(import_rule->url().to_string()) });
+                .url = import_rule->url().to_string() });
         }
     }
 }

+ 1 - 1
Tests/LibWebView/TestWebViewURL.cpp

@@ -22,7 +22,7 @@ static bool is_sanitized_url_the_same(StringView url)
     auto sanitized_url = WebView::sanitize_url(url);
     if (!sanitized_url.has_value())
         return false;
-    return sanitized_url->to_string().value() == url;
+    return sanitized_url->to_string() == url;
 }
 
 TEST_CASE(invalid_url)

+ 1 - 1
UI/Android/src/main/cpp/WebViewImplementationNative.cpp

@@ -38,7 +38,7 @@ WebViewImplementationNative::WebViewImplementationNative(jobject thiz)
 
     on_load_start = [this](URL::URL const& url, bool is_redirect) {
         JavaEnvironment env(global_vm);
-        auto url_string = env.jstring_from_ak_string(MUST(url.to_string()));
+        auto url_string = env.jstring_from_ak_string(url.to_string());
         env.get()->CallVoidMethod(m_java_instance, on_load_start_method, url_string, is_redirect);
         env.get()->DeleteLocalRef(url_string);
     };