LibWeb/URLPattern: Implement the URLPattern constructors

The underlying URL::Pattern implementation still has to be fully
implemented, but this does complete the IDL wrapper layer of the
implementation.
This commit is contained in:
Shannon Booth 2025-03-01 14:47:36 +13:00 committed by Tim Flynn
parent ff07cc1a6c
commit ba93e2a8a3
Notes: github-actions[bot] 2025-03-04 21:52:53 +00:00
2 changed files with 22 additions and 6 deletions

View file

@ -13,8 +13,9 @@ namespace Web::URLPattern {
GC_DEFINE_ALLOCATOR(URLPattern);
URLPattern::URLPattern(JS::Realm& realm)
URLPattern::URLPattern(JS::Realm& realm, URL::Pattern::Pattern pattern)
: PlatformObject(realm)
, m_url_pattern(move(pattern))
{
}
@ -26,14 +27,28 @@ void URLPattern::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(URLPattern);
}
WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::construct_impl(JS::Realm& realm, URLPatternInput const&, String const&, URLPatternOptions const&)
// https://urlpattern.spec.whatwg.org/#dom-urlpattern-urlpattern
WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::construct_impl(JS::Realm& realm, URLPatternInput const& input, String const& base_url, URLPatternOptions const& options)
{
return realm.create<URLPattern>(realm);
// 1. Run initialize given this, input, baseURL, and options.
return create(realm, input, base_url, options);
}
WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::construct_impl(JS::Realm& realm, URLPatternInput const&, URLPatternOptions const&)
// https://urlpattern.spec.whatwg.org/#dom-urlpattern-urlpattern-input-options
WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::construct_impl(JS::Realm& realm, URLPatternInput const& input, URLPatternOptions const& options)
{
return realm.create<URLPattern>(realm);
// 1. Run initialize given this, input, null, and options.
return create(realm, input, {}, options);
}
// https://urlpattern.spec.whatwg.org/#urlpattern-initialize
WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::create(JS::Realm& realm, URLPatternInput const& input, Optional<String> const& base_url, URLPatternOptions const& options)
{
// 1. Set thiss associated URL pattern to the result of create given input, baseURL, and options.
auto pattern_or_error = URL::Pattern::Pattern::create(input, base_url, options);
if (pattern_or_error.is_error())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, pattern_or_error.error().message };
return realm.create<URLPattern>(realm, pattern_or_error.release_value());
}
// https://urlpattern.spec.whatwg.org/#dom-urlpattern-exec