diff --git a/Libraries/LibWeb/HTML/EventSource.cpp b/Libraries/LibWeb/HTML/EventSource.cpp index 29aad139be0..6bca0823226 100644 --- a/Libraries/LibWeb/HTML/EventSource.cpp +++ b/Libraries/LibWeb/HTML/EventSource.cpp @@ -46,11 +46,11 @@ WebIDL::ExceptionOr> EventSource::construct_impl(JS::Realm& auto url_record = settings.encoding_parse_url(url); // 4. If urlRecord is failure, then throw a "SyntaxError" DOMException. - if (!url_record.is_valid()) + if (!url_record.has_value()) return WebIDL::SyntaxError::create(realm, MUST(String::formatted("Invalid URL '{}'", url))); // 5. Set ev's url to urlRecord. - event_source->m_url = move(url_record); + event_source->m_url = url_record.release_value(); // 6. Let corsAttributeState be Anonymous. auto cors_attribute_state = CORSSettingAttribute::Anonymous; diff --git a/Libraries/LibWeb/HTML/History.cpp b/Libraries/LibWeb/HTML/History.cpp index 5c9a5cfd360..98d632a6a5f 100644 --- a/Libraries/LibWeb/HTML/History.cpp +++ b/Libraries/LibWeb/HTML/History.cpp @@ -199,11 +199,11 @@ WebIDL::ExceptionOr History::shared_history_push_replace_state(JS::Value d auto parsed_url = relevant_settings_object(*this).parse_url(url->to_byte_string()); // 2. If that fails, then throw a "SecurityError" DOMException. - if (!parsed_url.is_valid()) + if (!parsed_url.has_value()) return WebIDL::SecurityError::create(realm(), "Cannot pushState or replaceState to incompatible URL"_string); // 3. Set newURL to the resulting URL record. - new_url = parsed_url; + new_url = parsed_url.release_value(); // 4. If document cannot have its URL rewritten to newURL, then throw a "SecurityError" DOMException. if (!can_have_its_url_rewritten(document, new_url)) diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cpp index ab623084d37..af4d69c65b3 100644 --- a/Libraries/LibWeb/HTML/Location.cpp +++ b/Libraries/LibWeb/HTML/Location.cpp @@ -141,11 +141,11 @@ WebIDL::ExceptionOr Location::set_href(String const& new_href) auto url = entry_settings_object().encoding_parse_url(new_href.to_byte_string()); // 3. If url is failure, then throw a "SyntaxError" DOMException. - if (!url.is_valid()) + if (!url.has_value()) return WebIDL::SyntaxError::create(realm, MUST(String::formatted("Invalid URL '{}'", new_href))); // 4. Location-object navigate this to url. - TRY(navigate(url)); + TRY(navigate(url.release_value())); return {}; } @@ -450,11 +450,11 @@ WebIDL::ExceptionOr Location::replace(String const& url) // 2. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException. auto replace_url = entry_settings_object().parse_url(url); - if (!replace_url.is_valid()) + if (!replace_url.has_value()) return WebIDL::SyntaxError::create(realm(), MUST(String::formatted("Invalid URL '{}'", url))); // 3. Location-object navigate this to the resulting URL record given "replace". - TRY(navigate(replace_url, Bindings::NavigationHistoryBehavior::Replace)); + TRY(navigate(replace_url.release_value(), Bindings::NavigationHistoryBehavior::Replace)); return {}; } @@ -473,11 +473,11 @@ WebIDL::ExceptionOr Location::assign(String const& url) // 3. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException. auto assign_url = entry_settings_object().parse_url(url); - if (!assign_url.is_valid()) + if (!assign_url.has_value()) return WebIDL::SyntaxError::create(realm(), MUST(String::formatted("Invalid URL '{}'", url))); // 4. Location-object navigate this to the resulting URL record. - TRY(navigate(assign_url)); + TRY(navigate(assign_url.release_value())); return {}; } diff --git a/Libraries/LibWeb/HTML/Navigation.cpp b/Libraries/LibWeb/HTML/Navigation.cpp index a391f1c6967..255aab7e3bc 100644 --- a/Libraries/LibWeb/HTML/Navigation.cpp +++ b/Libraries/LibWeb/HTML/Navigation.cpp @@ -229,7 +229,7 @@ WebIDL::ExceptionOr Navigation::navigate(String url, Navigatio // If that returns failure, then return an early error result for a "SyntaxError" DOMException. // Otherwise, let urlRecord be the resulting URL record. auto url_record = relevant_settings_object(*this).parse_url(url); - if (!url_record.is_valid()) + if (!url_record.has_value()) return early_error_result(WebIDL::SyntaxError::create(realm, "Cannot navigate to Invalid URL"_string)); // 2. Let document be this's relevant global object's associated Document. @@ -237,7 +237,7 @@ WebIDL::ExceptionOr Navigation::navigate(String url, Navigatio // 3. If options["history"] is "push", and the navigation must be a replace given urlRecord and document, // then return an early error result for a "NotSupportedError" DOMException. - if (options.history == Bindings::NavigationHistoryBehavior::Push && navigation_must_be_a_replace(url_record, document)) + if (options.history == Bindings::NavigationHistoryBehavior::Push && navigation_must_be_a_replace(url_record.value(), document)) return early_error_result(WebIDL::NotSupportedError::create(realm, "Navigation must be a replace, but push was requested"_string)); // 4. Let state be options["state"], if it exists; otherwise, undefined. @@ -278,7 +278,7 @@ WebIDL::ExceptionOr Navigation::navigate(String url, Navigatio // of the navigation, and we don't need to deal with the allowed by sandboxing to navigate check and its // acccompanying exceptionsEnabled flag. We just treat all navigations as if they come from the Document // corresponding to this Navigation object itself (i.e., document). - TRY(document.navigable()->navigate({ .url = url_record, .source_document = document, .history_handling = options.history, .navigation_api_state = move(serialized_state) })); + TRY(document.navigable()->navigate({ .url = url_record.release_value(), .source_document = document, .history_handling = options.history, .navigation_api_state = move(serialized_state) })); // 11. If this's upcoming non-traverse API method tracker is apiMethodTracker, then: // NOTE: If the upcoming non-traverse API method tracker is still apiMethodTracker, this means that the navigate diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cpp index c077ece2e3a..fc7d3c4f0ce 100644 --- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -203,17 +203,17 @@ void prepare_to_run_callback(JS::Realm& realm) } // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#parse-a-url -URL::URL EnvironmentSettingsObject::parse_url(StringView url) +Optional EnvironmentSettingsObject::parse_url(StringView url) { // 1. Let baseURL be environment's base URL, if environment is a Document object; otherwise environment's API base URL. auto base_url = api_base_url(); // 2. Return the result of applying the URL parser to url, with baseURL. - return DOMURL::parse(url, base_url).value_or(URL::URL {}); + return DOMURL::parse(url, base_url); } // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-a-url -URL::URL EnvironmentSettingsObject::encoding_parse_url(StringView url) +Optional EnvironmentSettingsObject::encoding_parse_url(StringView url) { // 1. Let encoding be UTF-8. auto encoding = "UTF-8"_string; @@ -229,7 +229,7 @@ URL::URL EnvironmentSettingsObject::encoding_parse_url(StringView url) auto base_url = api_base_url(); // 5. Return the result of applying the URL parser to url, with baseURL and encoding. - return DOMURL::parse(url, base_url, encoding).value_or(URL::URL {}); + return DOMURL::parse(url, base_url, encoding); } // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-and-serializing-a-url @@ -239,11 +239,11 @@ Optional EnvironmentSettingsObject::encoding_parse_and_serialize_url(Str auto parsed_url = encoding_parse_url(url); // 2. If url is failure, then return failure. - if (!parsed_url.is_valid()) + if (!parsed_url.has_value()) return {}; // 3. Return the result of applying the URL serializer to url. - return parsed_url.serialize(); + return parsed_url->serialize(); } // https://html.spec.whatwg.org/multipage/webappapis.html#clean-up-after-running-a-callback diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.h b/Libraries/LibWeb/HTML/Scripting/Environments.h index ad9d5e08ea2..84486042140 100644 --- a/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -91,8 +91,8 @@ public: // https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-time-origin virtual double time_origin() const = 0; - URL::URL parse_url(StringView); - URL::URL encoding_parse_url(StringView); + Optional parse_url(StringView); + Optional encoding_parse_url(StringView); Optional encoding_parse_and_serialize_url(StringView); JS::Realm& realm(); diff --git a/Libraries/LibWeb/HTML/Worker.cpp b/Libraries/LibWeb/HTML/Worker.cpp index 390f9385f0c..568cb10b514 100644 --- a/Libraries/LibWeb/HTML/Worker.cpp +++ b/Libraries/LibWeb/HTML/Worker.cpp @@ -63,7 +63,7 @@ WebIDL::ExceptionOr> Worker::create(String const& script_url, Wo auto url = outside_settings.parse_url(script_url); // 4. If this fails, throw a "SyntaxError" DOMException. - if (!url.is_valid()) { + if (!url.has_value()) { dbgln_if(WEB_WORKER_DEBUG, "WebWorker: Invalid URL loaded '{}'.", script_url); return WebIDL::SyntaxError::create(document.realm(), "url is not valid"_string); } @@ -82,7 +82,7 @@ WebIDL::ExceptionOr> Worker::create(String const& script_url, Wo // 9. Run this step in parallel: // 1. Run a worker given worker, worker URL, outside settings, outside port, and options. - worker->run_a_worker(url, outside_settings, *outside_port, options); + worker->run_a_worker(url.value(), outside_settings, *outside_port, options); // 10. Return worker return worker; diff --git a/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp index 2d85e72ed7b..12455cd4030 100644 --- a/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp +++ b/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp @@ -106,11 +106,11 @@ WebIDL::ExceptionOr WorkerGlobalScope::import_scripts(Vector const auto url_record = settings_object.encoding_parse_url(url); // 2. If urlRecord is failure, then throw a "SyntaxError" DOMException. - if (!url_record.is_valid()) + if (!url_record.has_value()) return WebIDL::SyntaxError::create(realm(), "Invalid URL"_string); // 3. Append urlRecord to urlRecords. - url_records.unchecked_append(url_record); + url_records.unchecked_append(url_record.release_value()); } // 6. For each urlRecord of urlRecords: