Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ext/url): URLSearchParams two-argument delete() and has() #19654

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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