Skip to content

Commit

Permalink
Warn if URLSearchParams has or delete are called with multiple args
Browse files Browse the repository at this point in the history
In preparation for landing support for the new value arguments added
recently to URLSearchParams.has() and delete(), we need to know if
adding the new arguments will break any existing workers. This commit
adds a warning.

Refs: whatwg/url#735
  • Loading branch information
jasnell committed May 11, 2023
1 parent 69bf81a commit 9e3ff32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/workerd/api/url-standard.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,16 @@ void URLSearchParams::append(jsg::UsvString name, jsg::UsvString value) {
update();
}

void URLSearchParams::delete_(jsg::UsvString name) {
void URLSearchParams::delete_(jsg::UsvString name, jsg::Optional<jsg::Value> value) {
KJ_IF_MAYBE(v, value) {
// The WHATWG recently added new arguments to the delete() and has() methods.
// We need to determine if adding those will break anyone if they are added
// without a compat flag. For now, we're just logging so we can know for sure.
// If we get this warning even once in production we'll have to introduce the
// new arguments behind a compat flag.
// https://github.com/whatwg/url/pull/735
LOG_WARNING_ONCE("URLSearchParams.prototype.delete() called with a second argument.");
}
auto pivot = std::remove_if(list.begin(), list.end(),
[&name](auto& kv) { return kv.name == name; });
list.truncate(pivot - list.begin());
Expand All @@ -1965,7 +1974,16 @@ kj::Array<jsg::UsvStringPtr> URLSearchParams::getAll(jsg::UsvString name) {
return result.releaseAsArray();
}

bool URLSearchParams::has(jsg::UsvString name) {
bool URLSearchParams::has(jsg::UsvString name, jsg::Optional<jsg::Value> value) {
KJ_IF_MAYBE(v, value) {
// The WHATWG recently added new arguments to the delete() and has() methods.
// We need to determine if adding those will break anyone if they are added
// without a compat flag. For now, we're just logging so we can know for sure.
// If we get this warning even once in production we'll have to introduce the
// new arguments behind a compat flag.
// https://github.com/whatwg/url/pull/735
LOG_WARNING_ONCE("URLSearchParams.prototype.has() called with a second argument.");
}
for (auto& entry : list) {
if (entry.name == name) return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/url-standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ class URLSearchParams: public jsg::Object {
}

void append(jsg::UsvString name, jsg::UsvString value);
void delete_(jsg::UsvString name);
void delete_(jsg::UsvString name, jsg::Optional<jsg::Value> value);
kj::Maybe<jsg::UsvStringPtr> get(jsg::UsvString name);
kj::Array<jsg::UsvStringPtr> getAll(jsg::UsvString name);
bool has(jsg::UsvString name);
bool has(jsg::UsvString name, jsg::Optional<jsg::Value> value);
void set(jsg::UsvString name, jsg::UsvString value);
void sort();

Expand Down

0 comments on commit 9e3ff32

Please sign in to comment.