From 17ddf2f97c58db0b6825809a8bc325f0bda65b1b Mon Sep 17 00:00:00 2001 From: Lino Le Van <11367844+lino-levan@users.noreply.github.com> Date: Sun, 2 Jul 2023 08:26:48 -0700 Subject: feat(ext/url): URLSearchParams two-argument delete() and has() (#19654) --- ext/url/00_url.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'ext') diff --git a/ext/url/00_url.js b/ext/url/00_url.js index 2a238eae1..65cde2ce2 100644 --- a/ext/url/00_url.js +++ b/ext/url/00_url.js @@ -169,19 +169,31 @@ class URLSearchParams { /** * @param {string} name + * @param {string} [value] */ - delete(name) { + delete(name, value = undefined) { webidl.assertBranded(this, URLSearchParamsPrototype); const prefix = "Failed to execute 'append' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 1, prefix); name = webidl.converters.USVString(name, prefix, "Argument 1"); const list = this[_list]; let i = 0; - while (i < list.length) { - if (list[i][0] === name) { - ArrayPrototypeSplice(list, i, 1); - } else { - i++; + if (value === undefined) { + while (i < list.length) { + if (list[i][0] === name) { + ArrayPrototypeSplice(list, i, 1); + } else { + i++; + } + } + } else { + value = webidl.converters.USVString(value, prefix, "Argument 2"); + while (i < list.length) { + if (list[i][0] === name && list[i][1] === value) { + ArrayPrototypeSplice(list, i, 1); + } else { + i++; + } } } this.#updateUrlSearch(); @@ -228,13 +240,21 @@ class URLSearchParams { /** * @param {string} name + * @param {string} [value] * @return {boolean} */ - has(name) { + has(name, value = undefined) { webidl.assertBranded(this, URLSearchParamsPrototype); const prefix = "Failed to execute 'has' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 1, prefix); name = webidl.converters.USVString(name, prefix, "Argument 1"); + if (value !== undefined) { + value = webidl.converters.USVString(value, prefix, "Argument 2"); + return ArrayPrototypeSome( + this[_list], + (entry) => entry[0] === name && entry[1] === value, + ); + } return ArrayPrototypeSome(this[_list], (entry) => entry[0] === name); } -- cgit v1.2.3