1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

Issue/2170 (#2175)

* Consistency using requiredArguments method

Replaced tuple length check in Headers class with requiredArguments
method.

* Consistency using requiredArguments method

Replaced tuple length check in UrlSearchParams class with
requiredArguments method.

* fmt
This commit is contained in:
Tomislav Fabeta 2019-04-21 20:40:15 +01:00 committed by Ryan Dahl
parent f77b112797
commit 6cded14bdf
2 changed files with 10 additions and 10 deletions

View file

@ -57,11 +57,11 @@ class HeadersBase {
// If header does not contain exactly two items, // If header does not contain exactly two items,
// then throw a TypeError. // then throw a TypeError.
// ref: https://fetch.spec.whatwg.org/#concept-headers-fill // ref: https://fetch.spec.whatwg.org/#concept-headers-fill
if (tuple.length !== 2) { requiredArguments(
throw new TypeError( "Headers.constructor tuple array argument",
"Failed to construct 'Headers'; Each header pair must be an iterable [name, value] tuple" tuple.length,
2
); );
}
const [name, value] = this._normalizeParams(tuple[0], tuple[1]); const [name, value] = this._normalizeParams(tuple[0], tuple[1]);
this._validateName(name); this._validateName(name);

View file

@ -27,11 +27,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.
if (tuple.length !== 2) { requiredArguments(
const errMsg = "URLSearchParams.constructor tuple array argument",
"Each query pair must be an iterable [name, value] tuple"; tuple.length,
throw new TypeError(errMsg); 2
} );
this.append(tuple[0], tuple[1]); this.append(tuple[0], tuple[1]);
} }
} else if (Object(init) === init) { } else if (Object(init) === init) {