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

use ada-url's url_pattern implementation #3529

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Feb 11, 2025

Since we moved URLPattern implementation to Ada and shared it with Node.js, we can now use it as a dependency and get rid of our implementation. This will allow us to have higher compatibility with the web-platform tests and spec, and reduce our codebase by 3800 lines...

Additionally with the help of @npaun, we now run web-platform tests and can get rid of our custom URLPattern tests for better web compatibility and maintenance, since WPT is always changing!

Copy link

github-actions bot commented Feb 11, 2025

The generated output of @cloudflare/workers-types has been changed by this PR. If this is intentional, run bazel build //types && rm -rf types/generated-snapshot && cp -r bazel-bin/types/definitions types/generated-snapshot to update the snapshot. Alternatively, you can download the full generated types: https://github.com/cloudflare/workerd/actions/runs/13399650587/artifacts/2612076737

Full Type Diff
diff -r bazel-bin/types/definitions/2021-11-03/index.d.ts types/generated-snapshot/2021-11-03/index.d.ts
2639d2638
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2021-11-03/index.ts types/generated-snapshot/2021-11-03/index.ts
2651d2650
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-01-31/index.d.ts types/generated-snapshot/2022-01-31/index.d.ts
2665d2664
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-01-31/index.ts types/generated-snapshot/2022-01-31/index.ts
2677d2676
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-03-21/index.d.ts types/generated-snapshot/2022-03-21/index.d.ts
2683d2682
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-03-21/index.ts types/generated-snapshot/2022-03-21/index.ts
2695d2694
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-08-04/index.d.ts types/generated-snapshot/2022-08-04/index.d.ts
2684d2683
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-08-04/index.ts types/generated-snapshot/2022-08-04/index.ts
2696d2695
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-10-31/index.d.ts types/generated-snapshot/2022-10-31/index.d.ts
2687d2686
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-10-31/index.ts types/generated-snapshot/2022-10-31/index.ts
2699d2698
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-11-30/index.d.ts types/generated-snapshot/2022-11-30/index.d.ts
2692d2691
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2022-11-30/index.ts types/generated-snapshot/2022-11-30/index.ts
2704d2703
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2023-03-01/index.d.ts types/generated-snapshot/2023-03-01/index.d.ts
2694d2693
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2023-03-01/index.ts types/generated-snapshot/2023-03-01/index.ts
2706d2705
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2023-07-01/index.d.ts types/generated-snapshot/2023-07-01/index.d.ts
2694d2693
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/2023-07-01/index.ts types/generated-snapshot/2023-07-01/index.ts
2706d2705
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/experimental/index.d.ts types/generated-snapshot/experimental/index.d.ts
2766d2765
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/experimental/index.ts types/generated-snapshot/experimental/index.ts
2778d2777
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/oldest/index.d.ts types/generated-snapshot/oldest/index.d.ts
2639d2638
<   get hasRegExpGroups(): boolean;
diff -r bazel-bin/types/definitions/oldest/index.ts types/generated-snapshot/oldest/index.ts
2651d2650
<   get hasRegExpGroups(): boolean;

@anonrig anonrig force-pushed the yagiz/replace-urlpattern branch 3 times, most recently from d75b95c to 5764de6 Compare February 12, 2025 16:22
@anonrig anonrig force-pushed the yagiz/replace-urlpattern branch 4 times, most recently from 449ffb5 to e2ea03b Compare February 13, 2025 23:55
@anonrig anonrig force-pushed the yagiz/replace-urlpattern branch 3 times, most recently from 69d0045 to 7b67ff7 Compare February 14, 2025 20:47
@anonrig anonrig force-pushed the yagiz/replace-urlpattern branch from 7b67ff7 to 16322b2 Compare February 18, 2025 20:38
@anonrig
Copy link
Member Author

anonrig commented Feb 18, 2025

Other than putting this behind a flag like @jasnell recommended, this is ready to review.

expectedFailures: [
// Each of these *ought* to pass. They are included here because we
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume that this comment is no longer needed since the tests themselves are invalid here.

@@ -4,8 +4,12 @@

#pragma once

#include "ada.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

As per KJ style, this should be <ada.h> (some people on the team have strong opinions about this).

@@ -249,6 +249,7 @@ wd_cc_library(
kj_test(
src = f,
deps = [
":urlpattern",
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no such target; it should be worthwhile to create one by isolating it from io as noted in the TODO at the top of this file. It is not necessary to do so in this PR though as doing so may require downstream changes. Furthermore, urlpattern.h is not used by any of these tests (it is needed for api-rtti-test so it would be correct to add it there).

Copy link
Member Author

Choose a reason for hiding this comment

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

I created urlpattern target on a different PR

Copy link
Member Author

Choose a reason for hiding this comment

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

It exists: #3546

@@ -21,7 +21,7 @@ build *args="//...":
bazel build {{args}}

build-asan *args="//...":
just build {{args}} --config=asan --sandbox_debug
Copy link
Collaborator

Choose a reason for hiding this comment

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

Changes to this file are already in #3551, let's avoid duplicating them here

#include <workerd/jsg/url.h>

#include <optional>
#include <string_view>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#include <string_view>
#include <kj/array.h>
#include <kj/one-of.h>
#include <kj/string.h>
#include <string>
#include <string_view>
#include <utility> // For std::move
#include <vector>

For include-what-you-use reasons.

Comment on lines +52 to +54
ada::url_pattern_options options{};
options.ignore_case = ignoreCase.orDefault(false);
return options;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ada::url_pattern_options options{};
options.ignore_case = ignoreCase.orDefault(false);
return options;
return {.ignore_case = ignoreCase.orDefault(false)};

jsg::Lock& js = jsg::Lock::from(v8::Isolate::GetCurrent());
KJ_IF_SOME(matches, pattern.getHandle(js)(js, kj::StringPtr(input.data(), input.size()))) {
std::vector<std::optional<std::string>> results;
results.reserve(matches.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are reserving one more slot than we need here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but adding -1 adds a branch (checking if size is bigger than 0), which reduces the impact of this optimization

}

#define V(uppercase, lowercase) \
Copy link
Contributor

Choose a reason for hiding this comment

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

Code like this is clearer if you give V a meaningful name like DEFINE_GETTER.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants