From b50c02094e5943d4d90568167481cadb8d15b57c Mon Sep 17 00:00:00 2001 From: Lino Le Van <11367844+lino-levan@users.noreply.github.com> Date: Thu, 29 Jun 2023 07:03:52 -0700 Subject: [PATCH 1/4] feat(ext/url): two-argument delete() and has() --- ext/url/00_url.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/ext/url/00_url.js b/ext/url/00_url.js index 2a238eae16e986..44845bb9ddbb97 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) { 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) { 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); } From a8edc6e9e079ba40da20e61adc16ad96a0819408 Mon Sep 17 00:00:00 2001 From: Lino Le Van <11367844+lino-levan@users.noreply.github.com> Date: Thu, 29 Jun 2023 08:19:25 -0700 Subject: [PATCH 2/4] chore: update wpt expectation --- tools/wpt/expectation.json | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index 535372179351d3..1e7ac4bc1872f5 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -3206,11 +3206,9 @@ "urlsearchparams-constructor.any.worker.html": true, "urlsearchparams-delete.any.html": [ "Changing the query of a URL with an opaque path can impact the path", - "Two-argument delete()" ], "urlsearchparams-delete.any.worker.html": [ "Changing the query of a URL with an opaque path can impact the path", - "Two-argument delete()" ], "urlsearchparams-foreach.any.html": true, "urlsearchparams-foreach.any.worker.html": true, @@ -3218,12 +3216,8 @@ "urlsearchparams-get.any.worker.html": true, "urlsearchparams-getall.any.html": true, "urlsearchparams-getall.any.worker.html": true, - "urlsearchparams-has.any.html": [ - "Two-argument has()" - ], - "urlsearchparams-has.any.worker.html": [ - "Two-argument has()" - ], + "urlsearchparams-has.any.html": true, + "urlsearchparams-has.any.worker.html": true, "urlsearchparams-set.any.html": true, "urlsearchparams-set.any.worker.html": true, "urlsearchparams-size.any.html": true, From 9d8f904c65ad47582c8c6596edc80ac1f78ec917 Mon Sep 17 00:00:00 2001 From: Lino Le Van <11367844+lino-levan@users.noreply.github.com> Date: Thu, 29 Jun 2023 08:44:55 -0700 Subject: [PATCH 3/4] fix: remove bonus commas --- tools/wpt/expectation.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index 1e7ac4bc1872f5..908c9498eed370 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -3205,10 +3205,10 @@ "urlsearchparams-constructor.any.html": true, "urlsearchparams-constructor.any.worker.html": true, "urlsearchparams-delete.any.html": [ - "Changing the query of a URL with an opaque path can impact the path", + "Changing the query of a URL with an opaque path can impact the path" ], "urlsearchparams-delete.any.worker.html": [ - "Changing the query of a URL with an opaque path can impact the path", + "Changing the query of a URL with an opaque path can impact the path" ], "urlsearchparams-foreach.any.html": true, "urlsearchparams-foreach.any.worker.html": true, From 4ae54772f838bcd2b51acc5925d472d9a098ae8d Mon Sep 17 00:00:00 2001 From: Lino Le Van <11367844+lino-levan@users.noreply.github.com> Date: Thu, 29 Jun 2023 10:24:59 -0700 Subject: [PATCH 4/4] fix: default to undefined --- ext/url/00_url.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/url/00_url.js b/ext/url/00_url.js index 44845bb9ddbb97..65cde2ce27e376 100644 --- a/ext/url/00_url.js +++ b/ext/url/00_url.js @@ -171,7 +171,7 @@ class URLSearchParams { * @param {string} name * @param {string} [value] */ - delete(name, value) { + delete(name, value = undefined) { webidl.assertBranded(this, URLSearchParamsPrototype); const prefix = "Failed to execute 'append' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 1, prefix); @@ -243,7 +243,7 @@ class URLSearchParams { * @param {string} [value] * @return {boolean} */ - has(name, value) { + has(name, value = undefined) { webidl.assertBranded(this, URLSearchParamsPrototype); const prefix = "Failed to execute 'has' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 1, prefix);