diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 96a9cd5e0d56..1368820b0804 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -778,6 +778,7 @@ set(SOURCES UIEvents/TextEvent.cpp UIEvents/UIEvent.cpp UIEvents/WheelEvent.cpp + URLPattern/URLPattern.cpp UserTiming/PerformanceMark.cpp UserTiming/PerformanceMeasure.cpp WebAssembly/Global.cpp diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 950a6d93f835..c4faad7a0976 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -799,6 +799,10 @@ class TextEvent; class UIEvent; } +namespace Web::URLPattern { +class URLPattern; +} + namespace Web::DOMURL { class DOMURL; class URLSearchParams; diff --git a/Libraries/LibWeb/URLPattern/URLPattern.cpp b/Libraries/LibWeb/URLPattern/URLPattern.cpp new file mode 100644 index 000000000000..ea8c6b8cd60f --- /dev/null +++ b/Libraries/LibWeb/URLPattern/URLPattern.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::URLPattern { + +GC_DEFINE_ALLOCATOR(URLPattern); + +URLPattern::URLPattern(JS::Realm& realm) + : PlatformObject(realm) +{ +} + +URLPattern::~URLPattern() = default; + +void URLPattern::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(URLPattern); +} + +WebIDL::ExceptionOr> URLPattern::construct_impl(JS::Realm& realm, URLPatternInput const&, String const&, URLPatternOptions const&) +{ + return realm.create(realm); +} + +WebIDL::ExceptionOr> URLPattern::construct_impl(JS::Realm& realm, URLPatternInput const&, URLPatternOptions const&) +{ + return realm.create(realm); +} + +} diff --git a/Libraries/LibWeb/URLPattern/URLPattern.h b/Libraries/LibWeb/URLPattern/URLPattern.h new file mode 100644 index 000000000000..e2ed2fe6c9f7 --- /dev/null +++ b/Libraries/LibWeb/URLPattern/URLPattern.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::URLPattern { + +using URLPatternInit = URL::Pattern::Init; +using URLPatternInput = URL::Pattern::Input; +using URLPatternOptions = URL::Pattern::Options; + +// https://urlpattern.spec.whatwg.org/#urlpattern +class URLPattern : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(URLPattern, Bindings::PlatformObject); + GC_DECLARE_ALLOCATOR(URLPattern); + +public: + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, URLPatternInput const&, String const& base_url, URLPatternOptions const& = {}); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, URLPatternInput const&, URLPatternOptions const& = {}); + + virtual ~URLPattern() override; + +protected: + virtual void initialize(JS::Realm&) override; + + explicit URLPattern(JS::Realm&); +}; + +} diff --git a/Libraries/LibWeb/URLPattern/URLPattern.idl b/Libraries/LibWeb/URLPattern/URLPattern.idl new file mode 100644 index 000000000000..84ef30079b69 --- /dev/null +++ b/Libraries/LibWeb/URLPattern/URLPattern.idl @@ -0,0 +1,61 @@ +typedef (USVString or URLPatternInit) URLPatternInput; + +// https://urlpattern.spec.whatwg.org/#urlpattern +[Exposed=(Window,Worker)] +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); + + [FIXME] URLPatternResult? exec(optional URLPatternInput input = {}, optional USVString baseURL); + + [FIXME] readonly attribute USVString protocol; + [FIXME] readonly attribute USVString username; + [FIXME] readonly attribute USVString password; + [FIXME] readonly attribute USVString hostname; + [FIXME] readonly attribute USVString port; + [FIXME] readonly attribute USVString pathname; + [FIXME] readonly attribute USVString search; + [FIXME] readonly attribute USVString hash; + + [FIXME] readonly attribute boolean hasRegExpGroups; +}; + +// https://urlpattern.spec.whatwg.org/#dictdef-urlpatterninit +dictionary URLPatternInit { + USVString protocol; + USVString username; + USVString password; + USVString hostname; + USVString port; + USVString pathname; + USVString search; + USVString hash; + USVString baseURL; +}; + +// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions +dictionary URLPatternOptions { + boolean ignoreCase = false; +}; + +// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternresult +dictionary URLPatternResult { + sequence inputs; + + URLPatternComponentResult protocol; + URLPatternComponentResult username; + URLPatternComponentResult password; + URLPatternComponentResult hostname; + URLPatternComponentResult port; + URLPatternComponentResult pathname; + URLPatternComponentResult search; + URLPatternComponentResult hash; +}; + +// https://urlpattern.spec.whatwg.org/#dictdef-urlpatterncomponentresult +dictionary URLPatternComponentResult { + USVString input; + record groups; +}; diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake index 07a13fdb78ce..445635066933 100644 --- a/Libraries/LibWeb/idl_files.cmake +++ b/Libraries/LibWeb/idl_files.cmake @@ -349,6 +349,7 @@ libweb_js_bindings(UIEvents/PointerEvent) libweb_js_bindings(UIEvents/TextEvent) libweb_js_bindings(UIEvents/UIEvent) libweb_js_bindings(UIEvents/WheelEvent) +libweb_js_bindings(URLPattern/URLPattern) libweb_js_bindings(UserTiming/PerformanceMark) libweb_js_bindings(UserTiming/PerformanceMeasure) libweb_js_bindings(WebAssembly/Global) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index d36203836cb1..9fae71ec556c 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -4434,6 +4434,7 @@ using namespace Web::StorageAPI; using namespace Web::Streams; using namespace Web::SVG; using namespace Web::UIEvents; +using namespace Web::URLPattern; using namespace Web::UserTiming; using namespace Web::WebAssembly; using namespace Web::WebAudio; diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/Namespaces.h b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/Namespaces.h index a9ae100ff983..3bcd63c8cb07 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/Namespaces.h +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/Namespaces.h @@ -37,6 +37,7 @@ static constexpr Array libweb_interface_namespaces = { "Selection"sv, "ServiceWorker"sv, "UIEvents"sv, + "URLPattern"sv, "WebAudio"sv, "WebGL"sv, "WebIDL"sv, diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index c907bb628c70..fc4edc633bf7 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -390,6 +390,7 @@ TypeError UIEvent URIError URL +URLPattern URLSearchParams Uint16Array Uint32Array