mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb/LibURL: Use an IgnoreCase enum for URLPatternOptions
This is to save a future name conflict that will appear between the options IDL dictionary and the options struct that are both present in the spec. It is also a nicer interface for now given there is only a single option at the moment.
This commit is contained in:
parent
f80e7d6816
commit
8a33c57c1e
Notes:
github-actions[bot]
2025-04-06 12:28:11 +00:00
Author: https://github.com/shannonbooth
Commit: 8a33c57c1e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3847
Reviewed-by: https://github.com/trflynn89
4 changed files with 14 additions and 9 deletions
|
@ -10,7 +10,7 @@
|
||||||
namespace URL::Pattern {
|
namespace URL::Pattern {
|
||||||
|
|
||||||
// https://urlpattern.spec.whatwg.org/#url-pattern-create
|
// https://urlpattern.spec.whatwg.org/#url-pattern-create
|
||||||
PatternErrorOr<Pattern> Pattern::create(Input const& input, Optional<String> const& base_url, Options const&)
|
PatternErrorOr<Pattern> Pattern::create(Input const& input, Optional<String> const& base_url, IgnoreCase)
|
||||||
{
|
{
|
||||||
// 1. Let init be null.
|
// 1. Let init be null.
|
||||||
Init init;
|
Init init;
|
||||||
|
|
|
@ -19,11 +19,6 @@ namespace URL::Pattern {
|
||||||
// https://urlpattern.spec.whatwg.org/#typedefdef-urlpatterninput
|
// https://urlpattern.spec.whatwg.org/#typedefdef-urlpatterninput
|
||||||
using Input = Variant<String, Init>;
|
using Input = Variant<String, Init>;
|
||||||
|
|
||||||
// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions
|
|
||||||
struct Options {
|
|
||||||
bool ignore_case { false };
|
|
||||||
};
|
|
||||||
|
|
||||||
// https://urlpattern.spec.whatwg.org/#dictdef-urlpatterncomponentresult
|
// https://urlpattern.spec.whatwg.org/#dictdef-urlpatterncomponentresult
|
||||||
struct ComponentResult {
|
struct ComponentResult {
|
||||||
String input;
|
String input;
|
||||||
|
@ -44,10 +39,16 @@ struct Result {
|
||||||
ComponentResult hash;
|
ComponentResult hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions
|
||||||
|
enum class IgnoreCase {
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
};
|
||||||
|
|
||||||
// https://urlpattern.spec.whatwg.org/#url-pattern
|
// https://urlpattern.spec.whatwg.org/#url-pattern
|
||||||
class Pattern {
|
class Pattern {
|
||||||
public:
|
public:
|
||||||
static PatternErrorOr<Pattern> create(Input const&, Optional<String> const& base_url = {}, Options const& = {});
|
static PatternErrorOr<Pattern> create(Input const&, Optional<String> const& base_url = {}, IgnoreCase = IgnoreCase::No);
|
||||||
|
|
||||||
PatternErrorOr<Optional<Result>> match(Input const&, Optional<String> const& base_url_string) const;
|
PatternErrorOr<Optional<Result>> match(Input const&, Optional<String> const& base_url_string) const;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::construct_impl(JS::Realm& r
|
||||||
WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::create(JS::Realm& realm, URLPatternInput const& input, Optional<String> const& base_url, URLPatternOptions const& options)
|
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.
|
// 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);
|
auto pattern_or_error = URL::Pattern::Pattern::create(input, base_url, options.ignore_case ? URL::Pattern::IgnoreCase::Yes : URL::Pattern::IgnoreCase::No);
|
||||||
if (pattern_or_error.is_error())
|
if (pattern_or_error.is_error())
|
||||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, pattern_or_error.error().message };
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, pattern_or_error.error().message };
|
||||||
return realm.create<URLPattern>(realm, pattern_or_error.release_value());
|
return realm.create<URLPattern>(realm, pattern_or_error.release_value());
|
||||||
|
|
|
@ -15,9 +15,13 @@ namespace Web::URLPattern {
|
||||||
|
|
||||||
using URLPatternInit = URL::Pattern::Init;
|
using URLPatternInit = URL::Pattern::Init;
|
||||||
using URLPatternInput = URL::Pattern::Input;
|
using URLPatternInput = URL::Pattern::Input;
|
||||||
using URLPatternOptions = URL::Pattern::Options;
|
|
||||||
using URLPatternResult = URL::Pattern::Result;
|
using URLPatternResult = URL::Pattern::Result;
|
||||||
|
|
||||||
|
// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions
|
||||||
|
struct URLPatternOptions {
|
||||||
|
bool ignore_case { false };
|
||||||
|
};
|
||||||
|
|
||||||
// https://urlpattern.spec.whatwg.org/#urlpattern
|
// https://urlpattern.spec.whatwg.org/#urlpattern
|
||||||
class URLPattern : public Bindings::PlatformObject {
|
class URLPattern : public Bindings::PlatformObject {
|
||||||
WEB_PLATFORM_OBJECT(URLPattern, Bindings::PlatformObject);
|
WEB_PLATFORM_OBJECT(URLPattern, Bindings::PlatformObject);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue