Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibURL+LibWeb: Add initial set of stubs for URLPatternInit #3224

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Libraries/LibURL/Pattern/Init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2025, Shannon Booth <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <AK/Optional.h>
#include <AK/String.h>

namespace URL::Pattern {

// https://urlpattern.spec.whatwg.org/#dictdef-urlpatterninit
struct Init {
Optional<String> protocol;
Optional<String> username;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing about putting it in LibURL is it will add an additional dependency on it to LibRegex, but I think that's fine

Optional<String> password;
Optional<String> hostname;
Optional<String> port;
Optional<String> pathname;
Optional<String> search;
Optional<String> hash;
Optional<String> base_url;
};

}
22 changes: 22 additions & 0 deletions Libraries/LibURL/Pattern/Pattern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2025, Shannon Booth <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <AK/Variant.h>
#include <LibURL/Pattern/Init.h>

namespace URL::Pattern {

// https://urlpattern.spec.whatwg.org/#typedefdef-urlpatterninput
using Input = Variant<String, Init>;

// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions
struct Options {
bool ignore_case { false };
};

}
1 change: 1 addition & 0 deletions Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ set(SOURCES
UIEvents/TextEvent.cpp
UIEvents/UIEvent.cpp
UIEvents/WheelEvent.cpp
URLPattern/URLPattern.cpp
UserTiming/PerformanceMark.cpp
UserTiming/PerformanceMeasure.cpp
WebAssembly/Global.cpp
Expand Down
4 changes: 4 additions & 0 deletions Libraries/LibWeb/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@ class TextEvent;
class UIEvent;
}

namespace Web::URLPattern {
class URLPattern;
}

namespace Web::DOMURL {
class DOMURL;
class URLSearchParams;
Expand Down
39 changes: 39 additions & 0 deletions Libraries/LibWeb/URLPattern/URLPattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2025, Shannon Booth <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/URLPatternPrototype.h>
#include <LibWeb/URLPattern/URLPattern.h>
#include <LibWeb/WebIDL/ExceptionOr.h>

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<GC::Ref<URLPattern>> URLPattern::construct_impl(JS::Realm& realm, URLPatternInput const&, String const&, URLPatternOptions const&)
{
return realm.create<URLPattern>(realm);
}

WebIDL::ExceptionOr<GC::Ref<URLPattern>> URLPattern::construct_impl(JS::Realm& realm, URLPatternInput const&, URLPatternOptions const&)
{
return realm.create<URLPattern>(realm);
}

}
37 changes: 37 additions & 0 deletions Libraries/LibWeb/URLPattern/URLPattern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2025, Shannon Booth <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <AK/String.h>
#include <LibURL/Pattern/Init.h>
#include <LibURL/Pattern/Pattern.h>
#include <LibWeb/Bindings/PlatformObject.h>

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<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& = {});

virtual ~URLPattern() override;

protected:
virtual void initialize(JS::Realm&) override;

explicit URLPattern(JS::Realm&);
};

}
61 changes: 61 additions & 0 deletions Libraries/LibWeb/URLPattern/URLPattern.idl
Original file line number Diff line number Diff line change
@@ -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<URLPatternInput> 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<USVString, (USVString or undefined)> groups;
};
1 change: 1 addition & 0 deletions Libraries/LibWeb/idl_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4435,6 +4435,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static constexpr Array libweb_interface_namespaces = {
"Selection"sv,
"ServiceWorker"sv,
"UIEvents"sv,
"URLPattern"sv,
"WebAudio"sv,
"WebGL"sv,
"WebIDL"sv,
Expand Down
1 change: 1 addition & 0 deletions Tests/LibWeb/Text/expected/all-window-properties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ TypeError
UIEvent
URIError
URL
URLPattern
URLSearchParams
Uint16Array
Uint32Array
Expand Down
Loading