mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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:
Notes:
github-actions[bot]
2025-03-04 21:52:53 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/ba93e2a8a38 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3739 Reviewed-by: https://github.com/trflynn89
@@ -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 this’s 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
|
||||
|
||||
Reference in New Issue
Block a user