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

Simplifying a bunch of uneeded error handling around the place.
This commit is contained in:
Shannon Booth 2024-12-03 22:31:33 +13:00 committed by Sam Atkins
commit 0fa54c2327
Notes: github-actions[bot] 2024-12-04 16:48:13 +00:00
52 changed files with 88 additions and 103 deletions

View file

@ -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 agents 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);

View file

@ -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>);

View file

@ -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;