Skip to content

Deduplicate global variables #801

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

Merged
merged 2 commits into from
Dec 31, 2019
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
22 changes: 1 addition & 21 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9348,10 +9348,6 @@ declare var IDBDatabase: {
new(): IDBDatabase;
};

interface IDBEnvironment {
readonly indexedDB: IDBFactory;
}

/** In the following code snippet, we make a request to open a database, and include handlers for the success and error cases. For a full working example, see our To-do Notifications app (view example live.) */
interface IDBFactory {
/**
Expand Down Expand Up @@ -18533,12 +18529,10 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
}

/** A window containing a DOM document; the document property points to the DOM document loaded in that window. */
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, IDBEnvironment, WindowBase64, WindowConsole, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowConsole, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
readonly applicationCache: ApplicationCache;
readonly caches: CacheStorage;
readonly clientInformation: Navigator;
readonly closed: boolean;
readonly crypto: Crypto;
customElements: CustomElementRegistry;
defaultStatus: string;
readonly devicePixelRatio: number;
Expand Down Expand Up @@ -18603,7 +18597,6 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler
readonly pageXOffset: number;
readonly pageYOffset: number;
readonly parent: Window;
readonly performance: Performance;
readonly personalbar: BarProp;
readonly screen: Screen;
readonly screenLeft: number;
Expand Down Expand Up @@ -18667,11 +18660,6 @@ declare var Window: {
new(): Window;
};

interface WindowBase64 {
atob(encodedString: string): string;
btoa(rawString: string): string;
}

interface WindowConsole {
readonly console: Console;
}
Expand Down Expand Up @@ -19533,10 +19521,8 @@ declare var Option: {
new(text?: string, value?: string, defaultSelected?: boolean, selected?: boolean): HTMLOptionElement;
};
declare var applicationCache: ApplicationCache;
declare var caches: CacheStorage;
declare var clientInformation: Navigator;
declare var closed: boolean;
declare var crypto: Crypto;
declare var customElements: CustomElementRegistry;
declare var defaultStatus: string;
declare var devicePixelRatio: number;
Expand Down Expand Up @@ -19601,7 +19587,6 @@ declare var outerWidth: number;
declare var pageXOffset: number;
declare var pageYOffset: number;
declare var parent: Window;
declare var performance: Performance;
declare var personalbar: BarProp;
declare var screen: Screen;
declare var screenLeft: number;
Expand Down Expand Up @@ -19926,9 +19911,6 @@ declare var onvolumechange: ((this: Window, ev: Event) => any) | null;
*/
declare var onwaiting: ((this: Window, ev: Event) => any) | null;
declare var onwheel: ((this: Window, ev: WheelEvent) => any) | null;
declare var indexedDB: IDBFactory;
declare function atob(encodedString: string): string;
declare function btoa(rawString: string): string;
declare function cancelAnimationFrame(handle: number): void;
declare function requestAnimationFrame(callback: FrameRequestCallback): number;
declare var caches: CacheStorage;
Expand All @@ -19946,8 +19928,6 @@ declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response
declare function queueMicrotask(callback: VoidFunction): void;
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
declare function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
declare var sessionStorage: Storage;
declare var localStorage: Storage;
declare var onafterprint: ((this: Window, ev: Event) => any) | null;
declare var onbeforeprint: ((this: Window, ev: Event) => any) | null;
declare var onbeforeunload: ((this: Window, ev: BeforeUnloadEvent) => any) | null;
Expand Down
9 changes: 2 additions & 7 deletions inputfiles/addedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,7 @@
}
}
},
"extends": "SVGElement",
"implements": [
"SVGFilterPrimitiveStandardAttributes"
]
"extends": "SVGElement"
},
"AbortSignal": {
"events": {
Expand Down Expand Up @@ -1063,9 +1060,7 @@
},
"SVGElement": {
"implements": [
"ElementCSSInlineStyle",
"GlobalEventHandlers",
"DocumentAndElementEventHandlers"
"ElementCSSInlineStyle"
]
},
"Text": {
Expand Down
7 changes: 6 additions & 1 deletion inputfiles/removedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,14 @@
"properties": {
"property": {
"browser": null,
"caches": null,
"crypto": null,
"msCredentials": null,
"ontouchcancel": null,
"ontouchend": null,
"ontouchmove": null,
"ontouchstart": null
"ontouchstart": null,
"performance": null
}
},
"methods": {
Expand All @@ -328,6 +331,8 @@
},
"implements": [
"GlobalFetch",
"IDBEnvironment",
"WindowBase64",
"WindowTimers"
]
},
Expand Down
5 changes: 3 additions & 2 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,10 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {

printer.print(`interface ${getNameWithTypeParameter(i, processedIName)}`);

const finalExtends = distinct([i.extends || "Object"].concat((i.implements || []).sort())
const finalExtends = [i.extends || "Object"]
.concat((i.implements || []).sort())
.filter(i => i !== "Object")
.map(processIName));
.map(processIName);

if (finalExtends.length) {
printer.print(` extends ${finalExtends.join(", ")}`);
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ function emitDom() {
for (const include of w.includes) {
const target = webidl.interfaces!.interface[include.target];
if (target) {
if (target.implements) {
target.implements.push(include.includes);
}
else {
if (!target.implements) {
target.implements = [include.includes];
} else if (!target.implements.includes(include.includes)) {
// This makes sure that browser.webidl.preprocessed.json
// does not already have the mixin reference
target.implements.push(include.includes);
}
}
}
Expand Down