LibWeb: Modify createObjectURL to return Utf16Strings

This commit is contained in:
Tete17 2025-08-17 10:21:56 +02:00 committed by Jelle Raaijmakers
commit f60529dac5
Notes: github-actions[bot] 2025-08-19 21:51:48 +00:00
5 changed files with 10 additions and 10 deletions

View file

@ -120,7 +120,7 @@ void DOMURL::visit_edges(Cell::Visitor& visitor)
}
// https://w3c.github.io/FileAPI/#dfn-createObjectURL
WebIDL::ExceptionOr<String> DOMURL::create_object_url(JS::VM& vm, GC::Ref<FileAPI::Blob> object)
WebIDL::ExceptionOr<Utf16String> DOMURL::create_object_url(JS::VM& vm, GC::Ref<FileAPI::Blob> object)
{
// The createObjectURL(obj) static method must return the result of adding an entry to the blob URL store for obj.
return TRY_OR_THROW_OOM(vm, FileAPI::add_entry_to_blob_url_store(object));

View file

@ -26,7 +26,7 @@ public:
virtual ~DOMURL() override;
static WebIDL::ExceptionOr<String> create_object_url(JS::VM&, GC::Ref<FileAPI::Blob> object);
static WebIDL::ExceptionOr<Utf16String> create_object_url(JS::VM&, GC::Ref<FileAPI::Blob> object);
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 = {});

View file

@ -24,6 +24,6 @@ interface URL {
USVString toJSON();
static DOMString createObjectURL(Blob obj); // FIXME: Should be (Blob or MediaSource).
static Utf16DOMString createObjectURL(Blob obj); // FIXME: Should be (Blob or MediaSource).
static undefined revokeObjectURL(DOMString url);
};

View file

@ -25,10 +25,10 @@ BlobURLStore& blob_url_store()
}
// https://w3c.github.io/FileAPI/#unicodeBlobURL
ErrorOr<String> generate_new_blob_url()
ErrorOr<Utf16String> generate_new_blob_url()
{
// 1. Let result be the empty string.
StringBuilder result;
StringBuilder result { StringBuilder::Mode::UTF16 };
// 2. Append the string "blob:" to result.
TRY(result.try_append("blob:"sv));
@ -57,11 +57,11 @@ ErrorOr<String> generate_new_blob_url()
TRY(result.try_append(uuid));
// 10. Return result.
return result.to_string();
return result.to_utf16_string();
}
// https://w3c.github.io/FileAPI/#add-an-entry
ErrorOr<String> add_entry_to_blob_url_store(GC::Ref<Blob> object)
ErrorOr<Utf16String> add_entry_to_blob_url_store(GC::Ref<Blob> object)
{
// 1. Let store be the user agents blob URL store.
auto& store = blob_url_store();
@ -73,7 +73,7 @@ ErrorOr<String> add_entry_to_blob_url_store(GC::Ref<Blob> object)
BlobURLEntry entry { object, HTML::current_principal_settings_object() };
// 4. Set store[url] to entry.
TRY(store.try_set(url, move(entry)));
TRY(store.try_set(url.to_utf8_but_should_be_ported_to_utf16(), move(entry)));
// 5. Return url.
return url;

View file

@ -25,8 +25,8 @@ struct BlobURLEntry {
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<Utf16String> generate_new_blob_url();
ErrorOr<Utf16String> add_entry_to_blob_url_store(GC::Ref<Blob> object);
bool check_for_same_partition_blob_url_usage(URL::BlobURLEntry const&, GC::Ref<HTML::Environment>);
struct NavigationEnvironment { };
Optional<URL::BlobURLEntry::Object> obtain_a_blob_object(URL::BlobURLEntry const&, Variant<GC::Ref<HTML::Environment>, NavigationEnvironment> environment);