Skip to content

Commit d5895c3

Browse files
committed
use ada-url's url_pattern implementation
1 parent d3fa366 commit d5895c3

14 files changed

+454
-1953
lines changed

Diff for: src/workerd/api/BUILD.bazel

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ filegroup(
2424
"rtti.c++",
2525
"url.c++",
2626
"urlpattern.c++",
27+
"urlpattern-standard.c++",
2728
"util.c++",
2829
],
2930
),
@@ -49,6 +50,7 @@ filegroup(
4950
"rtti.h",
5051
"url.h",
5152
"urlpattern.h",
53+
"urlpattern-standard.h",
5254
"util.h",
5355
],
5456
),
@@ -249,6 +251,18 @@ wd_cc_library(
249251
],
250252
)
251253

254+
wd_cc_library(
255+
name = "urlpattern-standard",
256+
srcs = ["urlpattern-standard.c++"],
257+
hdrs = ["urlpattern-standard.h"],
258+
visibility = ["//visibility:public"],
259+
deps = [
260+
"//src/workerd/jsg",
261+
"@ada-url",
262+
"@capnp-cpp//src/kj",
263+
],
264+
)
265+
252266
####################################################################################################
253267
## Tests
254268

Diff for: src/workerd/api/api-rtti-test.c++

+6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
#include <workerd/api/streams/standard.h>
2020
#include <workerd/api/trace.h>
2121
#include <workerd/api/url-standard.h>
22+
#include <workerd/api/urlpattern-standard.h>
2223
#include <workerd/api/urlpattern.h>
2324
#include <workerd/io/compatibility-date.h>
2425
#include <workerd/jsg/rtti.h>
2526

27+
// TODO(soon): Remove this once URLPattern autogate has been removed.
28+
#include <workerd/util/autogate.h>
29+
2630
#include <kj/test.h>
2731

2832
// Test building rtti for various APIs.
@@ -31,13 +35,15 @@ namespace workerd::api {
3135
namespace {
3236

3337
KJ_TEST("WorkerGlobalScope") {
38+
util::Autogate::initAutogate({});
3439
jsg::rtti::Builder builder((CompatibilityFlags::Reader()));
3540
builder.structure<WorkerGlobalScope>();
3641
KJ_EXPECT(builder.structure("workerd::api::Event"_kj) != kj::none);
3742
KJ_EXPECT(builder.structure("workerd::api::ObviouslyWrongName"_kj) == kj::none);
3843
}
3944

4045
KJ_TEST("ServiceWorkerGlobalScope") {
46+
util::Autogate::initAutogate({});
4147
jsg::rtti::Builder builder((CompatibilityFlags::Reader()));
4248
builder.structure<ServiceWorkerGlobalScope>();
4349
KJ_EXPECT(builder.structure("workerd::api::DurableObjectId"_kj) != kj::none);

Diff for: src/workerd/api/global-scope.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <workerd/io/io-timers.h>
1212
#include <workerd/jsg/jsg.h>
13+
#include <workerd/util/autogate.h>
1314
#ifdef WORKERD_EXPERIMENTAL_ENABLE_WEBGPU
1415
#include <workerd/api/gpu/gpu.h>
1516
#endif
@@ -52,11 +53,15 @@ class CompressionStream;
5253
class DecompressionStream;
5354
class TextEncoderStream;
5455
class TextDecoderStream;
55-
class URLPattern;
5656
class Blob;
5757
class File;
5858
class FormData;
5959

60+
class URLPattern;
61+
namespace urlpattern {
62+
class URLPattern;
63+
} // namespace urlpattern
64+
6065
class URL;
6166
class URLSearchParams;
6267
namespace url {
@@ -708,7 +713,13 @@ class ServiceWorkerGlobalScope: public WorkerGlobalScope {
708713
JSG_NESTED_TYPE(URL);
709714
JSG_NESTED_TYPE(URLSearchParams);
710715
}
711-
JSG_NESTED_TYPE(URLPattern);
716+
717+
// We conditionally enable a more spec compliant URLPattern to avoid any breakages.
718+
if (util::Autogate::isEnabled(util::AutogateKey::URLPATTERN)) {
719+
JSG_NESTED_TYPE_NAMED(urlpattern::URLPattern, URLPattern);
720+
} else {
721+
JSG_NESTED_TYPE(URLPattern);
722+
}
712723

713724
JSG_NESTED_TYPE(Blob);
714725
JSG_NESTED_TYPE(File);

Diff for: src/workerd/api/rtti.c++

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <workerd/api/trace.h>
3131
#include <workerd/api/unsafe.h>
3232
#include <workerd/api/url-standard.h>
33+
#include <workerd/api/urlpattern-standard.h>
3334
#include <workerd/api/urlpattern.h>
3435
#include <workerd/api/worker-rpc.h>
3536
#include <workerd/io/compatibility-date.h>
@@ -76,6 +77,7 @@
7677
F("url", EW_URL_ISOLATE_TYPES) \
7778
F("url-standard", EW_URL_STANDARD_ISOLATE_TYPES) \
7879
F("url-pattern", EW_URLPATTERN_ISOLATE_TYPES) \
80+
F("url-pattern-standard", EW_URLPATTERN_STANDARD_ISOLATE_TYPES) \
7981
F("websocket", EW_WEBSOCKET_ISOLATE_TYPES) \
8082
F("sql", EW_SQL_ISOLATE_TYPES) \
8183
F("sockets", EW_SOCKETS_ISOLATE_TYPES) \

0 commit comments

Comments
 (0)