Skip to content

Commit

Permalink
feat(ext/url): URLSearchParams two-argument delete() and has() (#19654)
Browse files Browse the repository at this point in the history
  • Loading branch information
lino-levan committed Jul 2, 2023
1 parent d8e8e60 commit 17ddf2f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
34 changes: 27 additions & 7 deletions ext/url/00_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 4 additions & 10 deletions tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3205,25 +3205,19 @@
"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",
"Two-argument delete()"
"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",
"Two-argument delete()"
"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,
"urlsearchparams-get.any.html": true,
"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,
Expand Down

0 comments on commit 17ddf2f

Please sign in to comment.