From 9e3ff326c2b382cc2c7dd4ea6cca09f3d8d1858c Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 10 May 2023 14:40:32 -0700 Subject: [PATCH] Warn if URLSearchParams has or delete are called with multiple args 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: https://github.com/whatwg/url/pull/735 --- src/workerd/api/url-standard.c++ | 22 ++++++++++++++++++++-- src/workerd/api/url-standard.h | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/workerd/api/url-standard.c++ b/src/workerd/api/url-standard.c++ index ad885e9f031..fe694941f66 100644 --- a/src/workerd/api/url-standard.c++ +++ b/src/workerd/api/url-standard.c++ @@ -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 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()); @@ -1965,7 +1974,16 @@ kj::Array URLSearchParams::getAll(jsg::UsvString name) { return result.releaseAsArray(); } -bool URLSearchParams::has(jsg::UsvString name) { +bool URLSearchParams::has(jsg::UsvString name, jsg::Optional 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; } diff --git a/src/workerd/api/url-standard.h b/src/workerd/api/url-standard.h index 5ebb9a3344d..25c0f2bd576 100644 --- a/src/workerd/api/url-standard.h +++ b/src/workerd/api/url-standard.h @@ -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 value); kj::Maybe get(jsg::UsvString name); kj::Array getAll(jsg::UsvString name); - bool has(jsg::UsvString name); + bool has(jsg::UsvString name, jsg::Optional value); void set(jsg::UsvString name, jsg::UsvString value); void sort();