summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/buffer.ts5
-rw-r--r--js/console.ts13
-rw-r--r--js/url_search_params.ts80
3 files changed, 59 insertions, 39 deletions
diff --git a/js/buffer.ts b/js/buffer.ts
index 551e8c4d4..15a26fb28 100644
--- a/js/buffer.ts
+++ b/js/buffer.ts
@@ -39,9 +39,10 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
constructor(ab?: ArrayBuffer) {
if (ab == null) {
this.buf = new Uint8Array(0);
- } else {
- this.buf = new Uint8Array(ab);
+ return;
}
+
+ this.buf = new Uint8Array(ab);
}
/** bytes() returns a slice holding the unread portion of the buffer.
diff --git a/js/console.ts b/js/console.ts
index b2f7e7cbb..169ff83fb 100644
--- a/js/console.ts
+++ b/js/console.ts
@@ -53,12 +53,15 @@ function getClassInstanceName(instance: unknown): string {
if (typeof instance !== "object") {
return "";
}
- if (instance) {
- const proto = Object.getPrototypeOf(instance);
- if (proto && proto.constructor) {
- return proto.constructor.name; // could be "Object" or "Array"
- }
+ if (!instance) {
+ return "";
}
+
+ const proto = Object.getPrototypeOf(instance);
+ if (proto && proto.constructor) {
+ return proto.constructor.name; // could be "Object" or "Array"
+ }
+
return "";
}
diff --git a/js/url_search_params.ts b/js/url_search_params.ts
index 8a6d143e4..1b4461ed2 100644
--- a/js/url_search_params.ts
+++ b/js/url_search_params.ts
@@ -6,39 +6,22 @@ export class URLSearchParams {
constructor(init: string | string[][] | Record<string, string> = "") {
if (typeof init === "string") {
- // Overload: USVString
- // If init is a string and starts with U+003F (?),
- // remove the first code point from init.
- if (init.charCodeAt(0) === 0x003f) {
- init = init.slice(1);
- }
+ this._handleStringInitialization(init);
+ return;
+ }
- for (const pair of init.split("&")) {
- // Empty params are ignored
- if (pair.length === 0) {
- continue;
- }
- const position = pair.indexOf("=");
- const name = pair.slice(0, position === -1 ? pair.length : position);
- const value = pair.slice(name.length + 1);
- this.append(decodeURIComponent(name), decodeURIComponent(value));
- }
- } else if (Array.isArray(init)) {
- // Overload: sequence<sequence<USVString>>
- for (const tuple of init) {
- // If pair does not contain exactly two items, then throw a TypeError.
- requiredArguments(
- "URLSearchParams.constructor tuple array argument",
- tuple.length,
- 2
- );
- this.append(tuple[0], tuple[1]);
- }
- } else if (Object(init) === init) {
- // Overload: record<USVString, USVString>
- for (const key of Object.keys(init)) {
- this.append(key, init[key]);
- }
+ if (Array.isArray(init)) {
+ this._handleArrayInitialization(init);
+ return;
+ }
+
+ if (Object(init) !== init) {
+ return;
+ }
+
+ // Overload: record<USVString, USVString>
+ for (const key of Object.keys(init)) {
+ this.append(key, init[key]);
}
}
@@ -249,4 +232,37 @@ export class URLSearchParams {
)
.join("&");
}
+
+ private _handleStringInitialization(init: string): void {
+ // Overload: USVString
+ // If init is a string and starts with U+003F (?),
+ // remove the first code point from init.
+ if (init.charCodeAt(0) === 0x003f) {
+ init = init.slice(1);
+ }
+
+ for (const pair of init.split("&")) {
+ // Empty params are ignored
+ if (pair.length === 0) {
+ continue;
+ }
+ const position = pair.indexOf("=");
+ const name = pair.slice(0, position === -1 ? pair.length : position);
+ const value = pair.slice(name.length + 1);
+ this.append(decodeURIComponent(name), decodeURIComponent(value));
+ }
+ }
+
+ private _handleArrayInitialization(init: string[][]): void {
+ // Overload: sequence<sequence<USVString>>
+ for (const tuple of init) {
+ // If pair does not contain exactly two items, then throw a TypeError.
+ requiredArguments(
+ "URLSearchParams.constructor tuple array argument",
+ tuple.length,
+ 2
+ );
+ this.append(tuple[0], tuple[1]);
+ }
+ }
}