LibWeb: Implement URL.parse

This was an addition to the URL spec, see:

https://github.com/whatwg/url/commit/58acb0
This commit is contained in:
Shannon Booth 2024-05-13 16:10:19 +12:00 committed by Andreas Kling
commit 9b6a1de777
Notes: sideshowbarker 2024-07-16 23:03:06 +09:00
5 changed files with 123 additions and 10 deletions

View file

@ -70,6 +70,24 @@ JS::NonnullGCPtr<DOMURL> DOMURL::initialize_a_url(JS::Realm& realm, URL::URL con
return result_url;
}
// https://url.spec.whatwg.org/#dom-url-parse
JS::GCPtr<DOMURL> DOMURL::parse_for_bindings(JS::VM& vm, String const& url, Optional<String> const& base)
{
auto& realm = *vm.current_realm();
// 1. Let parsedURL be the result of running the API URL parser on url with base, if given.
auto parsed_url = parse_api_url(url, base);
// 2. If parsedURL is failure, then return null.
if (!parsed_url.has_value())
return nullptr;
// 3. Let url be a new URL object.
// 4. Initialize url with parsedURL.
// 5. Return url.
return initialize_a_url(realm, parsed_url.value());
}
// https://url.spec.whatwg.org/#dom-url-url
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMURL>> DOMURL::construct_impl(JS::Realm& realm, String const& url, Optional<String> const& base)
{