mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 03:25:13 +00:00
LibWeb/URLPattern: Implement IDL interface for URLPattern test and exec
There is further work needed to complete the implementation of URL::Pattern::Pattern, but this implements the remaining URLPattern exec and test IDL interfaces, leaving all remaining work to LibURL.
This commit is contained in:
parent
10b32a8dd8
commit
569ebeb6a4
Notes:
github-actions[bot]
2025-03-04 21:52:41 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/569ebeb6a47 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3739 Reviewed-by: https://github.com/trflynn89
3 changed files with 27 additions and 6 deletions
|
@ -51,11 +51,31 @@ WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::create(JS::Realm& realm, UR
|
|||
return realm.create<URLPattern>(realm, pattern_or_error.release_value());
|
||||
}
|
||||
|
||||
// https://urlpattern.spec.whatwg.org/#dom-urlpattern-exec
|
||||
Optional<URLPatternResult> URLPattern::exec(URLPatternInput const&, Optional<String> const&) const
|
||||
// https://urlpattern.spec.whatwg.org/#dom-urlpattern-test
|
||||
WebIDL::ExceptionOr<bool> URLPattern::test(URLPatternInput const& input, Optional<String> const& base_url) const
|
||||
{
|
||||
dbgln("FIXME: Implement URLPattern::match");
|
||||
return {};
|
||||
// 1. Let result be the result of match given this's associated URL pattern, input, and baseURL if given.
|
||||
auto result_or_error = m_url_pattern.match(input, base_url);
|
||||
if (result_or_error.is_error())
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, result_or_error.error().message };
|
||||
auto result = result_or_error.release_value();
|
||||
|
||||
// 2. If result is null, return false.
|
||||
if (!result.has_value())
|
||||
return false;
|
||||
|
||||
// 3. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://urlpattern.spec.whatwg.org/#dom-urlpattern-exec
|
||||
WebIDL::ExceptionOr<Optional<URLPatternResult>> URLPattern::exec(URLPatternInput const& input, Optional<String> const& base_url) const
|
||||
{
|
||||
// 1. Return the result of match given this's associated URL pattern, input, and baseURL if given.
|
||||
auto result_or_error = m_url_pattern.match(input, base_url);
|
||||
if (result_or_error.is_error())
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, result_or_error.error().message };
|
||||
return result_or_error.release_value();
|
||||
}
|
||||
|
||||
// https://urlpattern.spec.whatwg.org/#dom-urlpattern-protocol
|
||||
|
|
|
@ -28,7 +28,8 @@ public:
|
|||
static WebIDL::ExceptionOr<GC::Ref<URLPattern>> construct_impl(JS::Realm&, URLPatternInput const&, String const& base_url, URLPatternOptions const& = {});
|
||||
static WebIDL::ExceptionOr<GC::Ref<URLPattern>> construct_impl(JS::Realm&, URLPatternInput const&, URLPatternOptions const& = {});
|
||||
|
||||
Optional<URLPatternResult> exec(URLPatternInput const&, Optional<String> const&) const;
|
||||
WebIDL::ExceptionOr<bool> test(URLPatternInput const&, Optional<String> const& base_url) const;
|
||||
WebIDL::ExceptionOr<Optional<URLPatternResult>> exec(URLPatternInput const&, Optional<String> const& base_url) const;
|
||||
|
||||
String const& protocol() const;
|
||||
String const& username() const;
|
||||
|
|
|
@ -6,7 +6,7 @@ interface URLPattern {
|
|||
constructor(URLPatternInput input, USVString baseURL, optional URLPatternOptions options = {});
|
||||
constructor(optional URLPatternInput input = {}, optional URLPatternOptions options = {});
|
||||
|
||||
[FIXME] boolean test(optional URLPatternInput input = {}, optional USVString baseURL);
|
||||
boolean test(optional URLPatternInput input = {}, optional USVString baseURL);
|
||||
|
||||
URLPatternResult? exec(optional URLPatternInput input = {}, optional USVString baseURL);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue