From 0fa54c2327631e116590fade64480022477dd9f4 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Tue, 3 Dec 2024 22:31:33 +1300 Subject: [PATCH] LibURL+LibWeb: Make URL::serialize return a String Simplifying a bunch of uneeded error handling around the place. --- Libraries/LibURL/URL.cpp | 11 ++-------- Libraries/LibURL/URL.h | 8 +++---- Libraries/LibWeb/CSS/CSSFontFaceRule.cpp | 2 +- Libraries/LibWeb/CSS/CSSImportRule.cpp | 2 +- Libraries/LibWeb/CSS/CSSImportRule.h | 2 +- Libraries/LibWeb/CSS/CSSStyleSheet.cpp | 4 ++-- Libraries/LibWeb/CSS/Parser/RuleParsing.cpp | 2 +- Libraries/LibWeb/CSS/StyleComputer.cpp | 4 ++-- .../CSS/StyleValues/ImageStyleValue.cpp | 2 +- .../LibWeb/CSS/StyleValues/URLStyleValue.h | 2 +- Libraries/LibWeb/DOM/Document.cpp | 6 +++--- Libraries/LibWeb/DOM/Document.h | 2 +- Libraries/LibWeb/DOM/Node.cpp | 2 +- Libraries/LibWeb/DOMURL/DOMURL.cpp | 21 +++++++------------ Libraries/LibWeb/DOMURL/DOMURL.h | 6 +++--- Libraries/LibWeb/Fetch/Request.cpp | 4 ++-- Libraries/LibWeb/Fetch/Response.cpp | 2 +- Libraries/LibWeb/FileAPI/BlobURLStore.cpp | 7 +++---- Libraries/LibWeb/FileAPI/BlobURLStore.h | 2 +- Libraries/LibWeb/FileAPI/FileReader.cpp | 2 +- Libraries/LibWeb/HTML/BrowsingContext.cpp | 2 +- Libraries/LibWeb/HTML/EventSource.h | 2 +- .../LibWeb/HTML/FormAssociatedElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLBaseElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLCanvasElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLFormElement.cpp | 2 +- .../LibWeb/HTML/HTMLHyperlinkElementUtils.cpp | 6 +++--- Libraries/LibWeb/HTML/HTMLImageElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLMediaElement.cpp | 4 ++-- Libraries/LibWeb/HTML/HTMLObjectElement.cpp | 2 +- Libraries/LibWeb/HTML/Location.cpp | 4 +--- Libraries/LibWeb/HTML/Navigable.cpp | 2 +- .../LibWeb/HTML/NavigationDestination.cpp | 4 ++-- Libraries/LibWeb/HTML/NavigationDestination.h | 2 +- .../LibWeb/HTML/NavigationHistoryEntry.cpp | 4 ++-- .../LibWeb/HTML/NavigationHistoryEntry.h | 2 +- Libraries/LibWeb/HTML/Scripting/Fetching.cpp | 6 +++--- Libraries/LibWeb/HTML/Scripting/ImportMap.cpp | 4 ++-- Libraries/LibWeb/HTML/WorkerLocation.cpp | 2 +- .../MixedContent/AbstractOperations.cpp | 4 ++-- .../ReferrerPolicy/AbstractOperations.cpp | 2 +- Libraries/LibWeb/ServiceWorker/Job.cpp | 2 +- .../LibWeb/ServiceWorker/Registration.cpp | 8 +++---- Libraries/LibWeb/WebSockets/WebSocket.cpp | 6 +++--- Libraries/LibWeb/WebSockets/WebSocket.h | 2 +- Libraries/LibWebView/URL.cpp | 2 +- .../BindingsGenerator/IDLGenerators.cpp | 2 +- .../RequestServer/ConnectionFromClient.cpp | 6 +++--- Services/WebContent/PageClient.cpp | 2 +- Tests/LibWebView/TestWebViewURL.cpp | 2 +- .../main/cpp/WebViewImplementationNative.cpp | 2 +- 52 files changed, 88 insertions(+), 103 deletions(-) diff --git a/Libraries/LibURL/URL.cpp b/Libraries/LibURL/URL.cpp index 45c070ae707..bcc59c79ab0 100644 --- a/Libraries/LibURL/URL.cpp +++ b/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 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; diff --git a/Libraries/LibURL/URL.h b/Libraries/LibURL/URL.h index 72132a2f08a..51b540c0965 100644 --- a/Libraries/LibURL/URL.h +++ b/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 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 : AK::Formatter { template<> struct AK::Traits : public AK::DefaultTraits { - 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(); } }; diff --git a/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp b/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp index 26e20cfa52b..f53c0dee149 100644 --- a/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp +++ b/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()) { - serialize_a_url(builder, MUST(source.local_or_url.get().to_string())); + serialize_a_url(builder, source.local_or_url.get().to_string()); } else { builder.appendff("local({})", source.local_or_url.get()); } diff --git a/Libraries/LibWeb/CSS/CSSImportRule.cpp b/Libraries/LibWeb/CSS/CSSImportRule.cpp index 23fbac26a4a..1fa7872cad6 100644 --- a/Libraries/LibWeb/CSS/CSSImportRule.cpp +++ b/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. diff --git a/Libraries/LibWeb/CSS/CSSImportRule.h b/Libraries/LibWeb/CSS/CSSImportRule.h index cf9910581ff..63f85b948bb 100644 --- a/Libraries/LibWeb/CSS/CSSImportRule.h +++ b/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; } diff --git a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index eab6b0a5640..7fa0765379e 100644 --- a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -36,7 +36,7 @@ WebIDL::ExceptionOr> 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::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); diff --git a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp index 0c96483afab..95d1d62267b 100644 --- a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp @@ -426,7 +426,7 @@ GC::Ptr 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 { diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 4de57403865..a13f0cd4a9d 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/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 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()) - urls.append(m_document->parse_url(MUST(source.local_or_url.get().to_string()))); + urls.append(m_document->parse_url(source.local_or_url.get().to_string())); // FIXME: Handle local() } diff --git a/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp index 530c1d20f55..a00abfad28f 100644 --- a/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp +++ b/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 diff --git a/Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h index cca656d4e4f..7e1fbdc7ce5 100644 --- a/Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h +++ b/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: diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index f9fcec906f0..7fd65599105 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -344,7 +344,7 @@ WebIDL::ExceptionOr> 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()) { - document->m_referrer = MUST(String::from_byte_string(referrer.get().serialize())); + document->m_referrer = referrer.get().serialize(); } } @@ -4468,8 +4468,8 @@ void Document::update_for_history_step_application(GC::Refurl().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); diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 5b3e552997e..909be6e0b7b 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -147,7 +147,7 @@ public: void update_base_element(Badge); GC::Ptr 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; diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 0a7066aab84..3e2c4f90f5a 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/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 diff --git a/Libraries/LibWeb/DOMURL/DOMURL.cpp b/Libraries/LibWeb/DOMURL/DOMURL.cpp index b5fee14210c..c230e063e76 100644 --- a/Libraries/LibWeb/DOMURL/DOMURL.cpp +++ b/Libraries/LibWeb/DOMURL/DOMURL.cpp @@ -131,14 +131,14 @@ WebIDL::ExceptionOr DOMURL::create_object_url(JS::VM& vm, GC::Ref 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 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 const& base) } // https://url.spec.whatwg.org/#dom-url-href -WebIDL::ExceptionOr 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 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② diff --git a/Libraries/LibWeb/DOMURL/DOMURL.h b/Libraries/LibWeb/DOMURL/DOMURL.h index dec456b1e91..42ed1faa442 100644 --- a/Libraries/LibWeb/DOMURL/DOMURL.h +++ b/Libraries/LibWeb/DOMURL/DOMURL.h @@ -27,12 +27,12 @@ public: virtual ~DOMURL() override; static WebIDL::ExceptionOr create_object_url(JS::VM&, GC::Ref object); - static WebIDL::ExceptionOr revoke_object_url(JS::VM&, StringView url); + static void revoke_object_url(JS::VM&, StringView url); static GC::Ptr parse_for_bindings(JS::VM&, String const& url, Optional const& base = {}); static bool can_parse(JS::VM&, String const& url, Optional const& base = {}); - WebIDL::ExceptionOr href() const; + String href() const; WebIDL::ExceptionOr set_href(String const&); String origin() const; @@ -75,7 +75,7 @@ public: WebIDL::ExceptionOr hash() const; void set_hash(String const&); - WebIDL::ExceptionOr to_json() const; + String to_json() const; Optional const& query() const { return m_url.query(); } void set_query(Badge, Optional query) { m_url.set_query(move(query)); } diff --git a/Libraries/LibWeb/Fetch/Request.cpp b/Libraries/LibWeb/Fetch/Request.cpp index 376309de3cc..86fb49f34d5 100644 --- a/Libraries/LibWeb/Fetch/Request.cpp +++ b/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(); }); } diff --git a/Libraries/LibWeb/Fetch/Response.cpp b/Libraries/LibWeb/Fetch/Response.cpp index ce538b2fd8d..3bb89a8f2e4 100644 --- a/Libraries/LibWeb/Fetch/Response.cpp +++ b/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 diff --git a/Libraries/LibWeb/FileAPI/BlobURLStore.cpp b/Libraries/LibWeb/FileAPI/BlobURLStore.cpp index da8f50d100f..f73cc5ab50b 100644 --- a/Libraries/LibWeb/FileAPI/BlobURLStore.cpp +++ b/Libraries/LibWeb/FileAPI/BlobURLStore.cpp @@ -79,17 +79,16 @@ ErrorOr add_entry_to_blob_url_store(GC::Ref object) } // https://w3c.github.io/FileAPI/#removeTheEntry -ErrorOr 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 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); diff --git a/Libraries/LibWeb/FileAPI/BlobURLStore.h b/Libraries/LibWeb/FileAPI/BlobURLStore.h index a913f05a5d5..f082d134f05 100644 --- a/Libraries/LibWeb/FileAPI/BlobURLStore.h +++ b/Libraries/LibWeb/FileAPI/BlobURLStore.h @@ -27,7 +27,7 @@ using BlobURLStore = HashMap; BlobURLStore& blob_url_store(); ErrorOr generate_new_blob_url(); ErrorOr add_entry_to_blob_url_store(GC::Ref object); -ErrorOr remove_entry_from_blob_url_store(StringView url); +void remove_entry_from_blob_url_store(StringView url); Optional resolve_a_blob_url(URL::URL const&); void run_unloading_cleanup_steps(GC::Ref); diff --git a/Libraries/LibWeb/FileAPI/FileReader.cpp b/Libraries/LibWeb/FileAPI/FileReader.cpp index db04958fd5e..c6591cf4712 100644 --- a/Libraries/LibWeb/FileAPI/FileReader.cpp +++ b/Libraries/LibWeb/FileAPI/FileReader.cpp @@ -72,7 +72,7 @@ WebIDL::ExceptionOr 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 encoding; diff --git a/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Libraries/LibWeb/HTML/BrowsingContext.cpp index a7d51c787d6..fe0b0b4729a 100644 --- a/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -256,7 +256,7 @@ WebIDL::ExceptionOr 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()); diff --git a/Libraries/LibWeb/HTML/EventSource.h b/Libraries/LibWeb/HTML/EventSource.h index 9a3d77fab7a..6fd5400bf8d 100644 --- a/Libraries/LibWeb/HTML/EventSource.h +++ b/Libraries/LibWeb/HTML/EventSource.h @@ -34,7 +34,7 @@ public: static WebIDL::ExceptionOr> 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; } diff --git a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp index 568dd09277c..a187d32f11a 100644 --- a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp +++ b/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 FormAssociatedElement::set_form_action(String const& value) diff --git a/Libraries/LibWeb/HTML/HTMLBaseElement.cpp b/Libraries/LibWeb/HTML/HTMLBaseElement.cpp index 64e7548ed42..9b153fa730e 100644 --- a/Libraries/LibWeb/HTML/HTMLBaseElement.cpp +++ b/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 diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index f5f77eecf1a..8a93fcab335 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/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 diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Libraries/LibWeb/HTML/HTMLFormElement.cpp index e578fae9c12..c397482a86a 100644 --- a/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/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 diff --git a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp index 18fa9e402a1..cb496c73408 100644 --- a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp +++ b/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 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 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()) { diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 8372ad9e1ef..ba59f1863ef 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/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 diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 4b67f2f8d81..852155bd71c 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -433,7 +433,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru if (m_loaded_style_sheet) { Optional 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, diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index e59fec5dd2f..a724421fd6e 100644 --- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/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 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. diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index d0bea443717..170c5a2a602 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/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 HTMLObjectElement::create_layout_node(CSS::StyleProperties style) diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cpp index 40e41cd3bfe..9ca6031f74a 100644 --- a/Libraries/LibWeb/HTML/Location.cpp +++ b/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 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 diff --git a/Libraries/LibWeb/HTML/Navigable.cpp b/Libraries/LibWeb/HTML/Navigable.cpp index fa9dfa1a88d..a407425f14f 100644 --- a/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Libraries/LibWeb/HTML/Navigable.cpp @@ -1600,7 +1600,7 @@ WebIDL::ExceptionOr> 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); diff --git a/Libraries/LibWeb/HTML/NavigationDestination.cpp b/Libraries/LibWeb/HTML/NavigationDestination.cpp index e638da8ce8e..1ecfbcd6c30 100644 --- a/Libraries/LibWeb/HTML/NavigationDestination.cpp +++ b/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 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 diff --git a/Libraries/LibWeb/HTML/NavigationDestination.h b/Libraries/LibWeb/HTML/NavigationDestination.h index 62f4308d84f..ce6104facc9 100644 --- a/Libraries/LibWeb/HTML/NavigationDestination.h +++ b/Libraries/LibWeb/HTML/NavigationDestination.h @@ -20,7 +20,7 @@ class NavigationDestination : public Bindings::PlatformObject { public: [[nodiscard]] static GC::Ref create(JS::Realm&); - WebIDL::ExceptionOr url() const; + String url() const; String key() const; String id() const; i64 index() const; diff --git a/Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp b/Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp index f44e6ca4b0e..cb3dda64865 100644 --- a/Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp +++ b/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> NavigationHistoryEntry::url() const +Optional 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> 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 diff --git a/Libraries/LibWeb/HTML/NavigationHistoryEntry.h b/Libraries/LibWeb/HTML/NavigationHistoryEntry.h index 2f21bbb8451..d08f00fdf01 100644 --- a/Libraries/LibWeb/HTML/NavigationHistoryEntry.h +++ b/Libraries/LibWeb/HTML/NavigationHistoryEntry.h @@ -18,7 +18,7 @@ class NavigationHistoryEntry : public DOM::EventTarget { public: [[nodiscard]] static GC::Ref create(JS::Realm&, GC::Ref); - WebIDL::ExceptionOr> url() const; + Optional url() const; String key() const; String id() const; i64 index() const; diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp index b259a1c79eb..66cb8d3730a 100644 --- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp +++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp @@ -127,7 +127,7 @@ WebIDL::ExceptionOr resolve_module_specifier(Optional 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 resolve_module_specifier(Optional 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> 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); diff --git a/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp b/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp index 0f8d646162e..46c8c32cf30 100644 --- a/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp +++ b/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp @@ -107,7 +107,7 @@ Optional 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 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, diff --git a/Libraries/LibWeb/HTML/WorkerLocation.cpp b/Libraries/LibWeb/HTML/WorkerLocation.cpp index d3f2586eaa4..3947a2ba117 100644 --- a/Libraries/LibWeb/HTML/WorkerLocation.cpp +++ b/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 diff --git a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp b/Libraries/LibWeb/MixedContent/AbstractOperations.cpp index f31ad8342a8..17dd0ddf381 100644 --- a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp +++ b/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; } diff --git a/Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp b/Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp index 89ba0afbdb0..540a8abd2c9 100644 --- a/Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp +++ b/Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp @@ -107,7 +107,7 @@ Optional 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 diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cpp index f50b835b131..f9b6e26acb8 100644 --- a/Libraries/LibWeb/ServiceWorker/Job.cpp +++ b/Libraries/LibWeb/ServiceWorker/Job.cpp @@ -569,7 +569,7 @@ void schedule_job(JS::VM& vm, GC::Ref 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]. diff --git a/Libraries/LibWeb/ServiceWorker/Registration.cpp b/Libraries/LibWeb/ServiceWorker/Registration.cpp index 5477be61bb0..07838b34f33 100644 --- a/Libraries/LibWeb/ServiceWorker/Registration.cpp +++ b/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 ®istration; }).value_or(nullptr) != this; } @@ -60,7 +60,7 @@ Optional 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 diff --git a/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Libraries/LibWeb/WebSockets/WebSocket.cpp index 51373086baa..4cfb17ae6cf 100644 --- a/Libraries/LibWeb/WebSockets/WebSocket.cpp +++ b/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; } diff --git a/Libraries/LibWeb/WebSockets/WebSocket.h b/Libraries/LibWeb/WebSockets/WebSocket.h index 7626ae452cf..48955fc3df9 100644 --- a/Libraries/LibWeb/WebSockets/WebSocket.h +++ b/Libraries/LibWeb/WebSockets/WebSocket.h @@ -35,7 +35,7 @@ public: virtual ~WebSocket() override; - WebIDL::ExceptionOr 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 diff --git a/Libraries/LibWebView/URL.cpp b/Libraries/LibWebView/URL.cpp index ef0117c38bc..59ae21c5efb 100644 --- a/Libraries/LibWebView/URL.cpp +++ b/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())); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 7557613f92b..19c3dac5994 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/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()); )~~~"); } diff --git a/Services/RequestServer/ConnectionFromClient.cpp b/Services/RequestServer/ConnectionFromClient.cpp index 62149a14db8..e6d4cbe0b10 100644 --- a/Services/RequestServer/ConnectionFromClient.cpp +++ b/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(*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(); diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp index f0dfccedd1e..05091c8a7e3 100644 --- a/Services/WebContent/PageClient.cpp +++ b/Services/WebContent/PageClient.cpp @@ -787,7 +787,7 @@ static void gather_style_sheets(Vector& 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() }); } } } diff --git a/Tests/LibWebView/TestWebViewURL.cpp b/Tests/LibWebView/TestWebViewURL.cpp index 8b065f3d476..7419abba3da 100644 --- a/Tests/LibWebView/TestWebViewURL.cpp +++ b/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) diff --git a/UI/Android/src/main/cpp/WebViewImplementationNative.cpp b/UI/Android/src/main/cpp/WebViewImplementationNative.cpp index 41164f8688f..ffa71c6ba09 100644 --- a/UI/Android/src/main/cpp/WebViewImplementationNative.cpp +++ b/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); };