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

dedup URLSearchParams, URL, Location, DOMStringList #4719

Merged
merged 1 commit into from
Apr 11, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/js/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ export const windowOrWorkerGlobalScopeProperties = {
DOMException: nonEnumerable(domException.DOMExceptionImpl),
Event: nonEnumerable(event.EventImpl),
EventTarget: nonEnumerable(eventTarget.EventTargetImpl),
URL: nonEnumerable(url.URL),
URLSearchParams: nonEnumerable(urlSearchParams.URLSearchParams),
URL: nonEnumerable(url.URLImpl),
URLSearchParams: nonEnumerable(urlSearchParams.URLSearchParamsImpl),
Headers: nonEnumerable(headers.Headers),
FormData: nonEnumerable(formData.FormData),
TextEncoder: nonEnumerable(textEncoding.TextEncoder),
Expand Down
2 changes: 1 addition & 1 deletion cli/js/web/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type BodySource =
| Blob
| BufferSource
| domTypes.FormData
| domTypes.URLSearchParams
| URLSearchParams
| domTypes.ReadableStream
| string;

Expand Down
68 changes: 0 additions & 68 deletions cli/js/web/dom_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,6 @@ export interface ProgressEventInit extends EventInit {
total?: number;
}

export class URLSearchParams {
constructor(
init?: string[][] | Record<string, string> | string | URLSearchParams
);
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string): boolean;
set(name: string, value: string): void;
sort(): void;
toString(): string;
forEach(
callbackfn: (value: string, key: string, parent: this) => void,
thisArg?: any
): void;
[Symbol.iterator](): IterableIterator<[string, string]>;
entries(): IterableIterator<[string, string]>;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
static toString(): string;
}

export interface UIEventInit extends EventInit {
detail?: number;
// adjust Window -> Node
Expand Down Expand Up @@ -654,48 +631,3 @@ export interface ResponseConstructor {
error(): Response;
redirect(url: string, status?: number): Response;
}

export class DOMStringList {
readonly length: number;
contains(string: string): boolean;
item(index: number): string | null;
[index: number]: string;
[Symbol.iterator](): IterableIterator<string>;
}

export class Location {
readonly ancestorOrigins: DOMStringList;
hash: string;
host: string;
hostname: string;
href: string;
toString(): string;
readonly origin: string;
pathname: string;
port: string;
protocol: string;
search: string;
assign(url: string): void;
reload(): void;
replace(url: string): void;
}

export class URL {
constructor(url: string, base?: string | URL);
hash: string;
host: string;
hostname: string;
href: string;
toString(): string;
readonly origin: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
readonly searchParams: URLSearchParams;
username: string;
toJSON(): string;
static createObjectURL(object: any): string;
static revokeObjectURL(url: string): void;
}
6 changes: 2 additions & 4 deletions cli/js/web/dom_util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

import * as domTypes from "./dom_types.d.ts";

export function getDOMStringList(arr: string[]): domTypes.DOMStringList {
export function getDOMStringList(arr: string[]): DOMStringList {
Object.defineProperties(arr, {
contains: {
value(searchElement: string): boolean {
Expand All @@ -16,5 +14,5 @@ export function getDOMStringList(arr: string[]): domTypes.DOMStringList {
},
},
});
return arr as string[] & domTypes.DOMStringList;
return arr as string[] & DOMStringList;
}
2 changes: 0 additions & 2 deletions cli/js/web/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { read } from "../ops/io.ts";
import { close } from "../ops/resources.ts";
import { Buffer } from "../buffer.ts";
import { FormData } from "./form_data.ts";
import { URL } from "./url.ts";
import { URLSearchParams } from "./url_search_params.ts";
import { fetch as opFetch, FetchResponse } from "../ops/fetch.ts";
import { DomFileImpl } from "./dom_file.ts";

Expand Down
2 changes: 0 additions & 2 deletions cli/js/web/location.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { URL } from "./url.ts";
import { notImplemented } from "../util.ts";
import { DOMStringList, Location } from "./dom_types.d.ts";
import { getDOMStringList } from "./dom_util.ts";

export class LocationImpl implements Location {
Expand Down
5 changes: 2 additions & 3 deletions cli/js/web/url.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { customInspect } from "./console.ts";
import * as domTypes from "./dom_types.d.ts";
import { urls, URLSearchParams } from "./url_search_params.ts";
import { urls } from "./url_search_params.ts";
import { getRandomValues } from "../ops/get_random_values.ts";

interface URLParts {
Expand Down Expand Up @@ -139,7 +138,7 @@ function resolvePathFromBase(path: string, basePath: string): string {
/** @internal */
export const parts = new WeakMap<URL, URLParts>();

export class URL implements domTypes.URL {
export class URLImpl implements URL {
#searchParams!: URLSearchParams;

[customInspect](): string {
Expand Down
7 changes: 3 additions & 4 deletions cli/js/web/url_search_params.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import * as domTypes from "./dom_types.d.ts";
import { URL, parts } from "./url.ts";
import { parts } from "./url.ts";
import { isIterable, requiredArguments } from "./util.ts";

/** @internal */
Expand Down Expand Up @@ -45,7 +44,7 @@ function handleArrayInitialization(
}
}

export class URLSearchParams implements domTypes.URLSearchParams {
export class URLSearchParamsImpl implements URLSearchParams {
#params: Array<[string, string]> = [];

constructor(init: string | string[][] | Record<string, string> = "") {
Expand All @@ -63,7 +62,7 @@ export class URLSearchParams implements domTypes.URLSearchParams {
return;
}

if (init instanceof URLSearchParams) {
if (init instanceof URLSearchParamsImpl) {
this.#params = [...init.#params];
return;
}
Expand Down