mirror of
https://github.com/denoland/deno.git
synced 2025-09-30 06:04:48 +00:00
check URLSearchParams.constructor
's params (#2488)
This commit is contained in:
parent
a115340288
commit
5871d22d9b
2 changed files with 18 additions and 5 deletions
|
@ -280,11 +280,11 @@ export class URLSearchParams {
|
||||||
// Overload: sequence<sequence<USVString>>
|
// Overload: sequence<sequence<USVString>>
|
||||||
for (const tuple of init) {
|
for (const tuple of init) {
|
||||||
// If pair does not contain exactly two items, then throw a TypeError.
|
// If pair does not contain exactly two items, then throw a TypeError.
|
||||||
requiredArguments(
|
if (tuple.length !== 2) {
|
||||||
"URLSearchParams.constructor tuple array argument",
|
throw new TypeError(
|
||||||
tuple.length,
|
"URLSearchParams.constructor tuple array argument must only contain pair elements"
|
||||||
2
|
);
|
||||||
);
|
}
|
||||||
this.append(tuple[0], tuple[1]);
|
this.append(tuple[0], tuple[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,19 @@ test(function urlSearchParamsShouldThrowTypeError(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(hasThrown, 2);
|
assertEquals(hasThrown, 2);
|
||||||
|
|
||||||
|
try {
|
||||||
|
new URLSearchParams([["1", "2", "3"]]);
|
||||||
|
hasThrown = 1;
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof TypeError) {
|
||||||
|
hasThrown = 2;
|
||||||
|
} else {
|
||||||
|
hasThrown = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(hasThrown, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function urlSearchParamsAppendArgumentsCheck(): void {
|
test(function urlSearchParamsAppendArgumentsCheck(): void {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue