mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat(ext/url): URLSearchParams two-argument delete() and has() (#19654)
This commit is contained in:
parent
d8e8e60f9f
commit
17ddf2f97c
2 changed files with 31 additions and 17 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3205,12 +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",
|
||||
"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,
|
||||
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue