From 0b08c879293c847ef33204054186774543e0aaf1 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 11 Jun 2018 17:57:36 +0900 Subject: [PATCH] adds HTML scripts/custom elements types --- baselines/dom.generated.d.ts | 44 ++-- inputfiles/addedTypes.json | 196 +++--------------- .../HTML - Custom elements.commentmap.json | 3 + inputfiles/idl/HTML - Custom elements.widl | 13 ++ ...TML - Interactive elements.commentmap.json | 6 + .../idl/HTML - Interactive elements.widl | 15 ++ .../idl/HTML - Scripting.commentmap.json | 7 + inputfiles/idl/HTML - Scripting.widl | 32 +++ inputfiles/idlSources.json | 12 ++ inputfiles/removedTypes.json | 1 + src/emitter.ts | 1 + 11 files changed, 141 insertions(+), 189 deletions(-) create mode 100644 inputfiles/idl/HTML - Custom elements.commentmap.json create mode 100644 inputfiles/idl/HTML - Custom elements.widl create mode 100644 inputfiles/idl/HTML - Interactive elements.commentmap.json create mode 100644 inputfiles/idl/HTML - Interactive elements.widl create mode 100644 inputfiles/idl/HTML - Scripting.commentmap.json create mode 100644 inputfiles/idl/HTML - Scripting.widl diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index ab73ecca9..81391dd97 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -71,6 +71,10 @@ interface AssertionOptions { timeoutSeconds?: number; } +interface AssignedNodesOptions { + flatten?: boolean; +} + interface AudioBufferOptions { length: number; numberOfChannels?: number; @@ -374,6 +378,10 @@ interface EffectTiming { iterations?: number; } +interface ElementDefinitionOptions { + extends?: string; +} + interface ErrorEventInit extends EventInit { colno?: number; error?: any; @@ -2117,10 +2125,6 @@ declare var ApplicationCache: { readonly UPDATEREADY: number; }; -interface AssignedNodesOptions { - flatten?: boolean; -} - interface Attr extends Node { readonly name: string; readonly ownerElement: Element | null; @@ -3490,9 +3494,15 @@ declare var CryptoKeyPair: { interface CustomElementRegistry { define(name: string, constructor: Function, options?: ElementDefinitionOptions): void; get(name: string): any; - whenDefined(name: string): PromiseLike; + upgrade(root: Node): void; + whenDefined(name: string): Promise; } +declare var CustomElementRegistry: { + prototype: CustomElementRegistry; + new(): CustomElementRegistry; +}; + interface CustomEvent extends Event { readonly detail: T; initCustomEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, detailArg: T): void; @@ -5137,10 +5147,6 @@ interface ElementCreationOptions { is?: string; } -interface ElementDefinitionOptions { - extends: string; -} - interface ElementTraversal { readonly childElementCount: number; readonly firstElementChild: Element | null; @@ -7877,6 +7883,7 @@ interface HTMLScriptElement extends HTMLElement { htmlFor: string; integrity: string; noModule: boolean; + referrerPolicy: string; /** * Retrieves the URL to an external file that contains the source code or data. */ @@ -8005,6 +8012,7 @@ declare var HTMLSelectElement: { interface HTMLSlotElement extends HTMLElement { name: string; + assignedElements(options?: AssignedNodesOptions): Element[]; assignedNodes(options?: AssignedNodesOptions): Node[]; addEventListener(type: K, listener: (this: HTMLSlotElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; @@ -8012,6 +8020,11 @@ interface HTMLSlotElement extends HTMLElement { removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } +declare var HTMLSlotElement: { + prototype: HTMLSlotElement; + new(): HTMLSlotElement; +}; + interface HTMLSourceElement extends HTMLElement { /** * Gets or sets the intended media type of the media source. @@ -8075,18 +8088,6 @@ declare var HTMLStyleElement: { new(): HTMLStyleElement; }; -interface HTMLSummaryElement extends HTMLElement { - addEventListener(type: K, listener: (this: HTMLSummaryElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; - addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; - removeEventListener(type: K, listener: (this: HTMLSummaryElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void; - removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; -} - -declare var HTMLSummaryElement: { - prototype: HTMLSummaryElement; - new(): HTMLSummaryElement; -}; - interface HTMLTableCaptionElement extends HTMLElement { /** * Sets or retrieves the alignment of the caption or legend. @@ -16740,6 +16741,7 @@ interface HTMLElementTagNameMap { "datalist": HTMLDataListElement; "dd": HTMLElement; "del": HTMLModElement; + "details": HTMLDetailsElement; "dfn": HTMLElement; "dir": HTMLDirectoryElement; "div": HTMLDivElement; diff --git a/inputfiles/addedTypes.json b/inputfiles/addedTypes.json index de0ba635c..1e87ec8aa 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -1200,49 +1200,6 @@ } } }, - "HTMLSlotElement": { - "name": "HTMLSlotElement", - "extends": "HTMLElement", - "exposed": "Window", - "properties": { - "property": { - "name": { - "name": "name", - "override-type": "string" - } - } - }, - "methods": { - "method": { - "assignedNodes": { - "name": "assignedNodes", - "override-signatures": [ - "assignedNodes(options?: AssignedNodesOptions): Node[]" - ] - } - } - }, - "no-interface-object": "1", - "element": [ - { - "name": "slot" - } - ] - }, - "AssignedNodesOptions": { - "name": "AssignedNodesOptions", - "exposed": "Window", - "properties": { - "property": { - "flatten": { - "name": "flatten", - "override-type": "boolean", - "required": 0 - } - } - }, - "no-interface-object": "1" - }, "Event": { "name": "Event", "properties": { @@ -1265,19 +1222,6 @@ } } }, - "ElementDefinitionOptions": { - "name": "ElementDefinitionOptions", - "exposed": "Window", - "properties": { - "property": { - "extends": { - "name": "extends", - "override-type": "string" - } - } - }, - "no-interface-object": "1" - }, "ElementCreationOptions": { "name": "ElementCreationOptions", "exposed": "Window", @@ -1292,33 +1236,6 @@ }, "no-interface-object": "1" }, - "CustomElementRegistry": { - "name": "CustomElementRegistry", - "exposed": "Window", - "methods": { - "method": { - "define": { - "name": "define", - "override-signatures": [ - "define(name: string, constructor: Function, options?: ElementDefinitionOptions): void" - ] - }, - "get": { - "name": "get", - "override-signatures": [ - "get(name: string): any" - ] - }, - "whenDefined": { - "name": "whenDefined", - "override-signatures": [ - "whenDefined(name: string): PromiseLike" - ] - } - } - }, - "no-interface-object": "1" - }, "PromiseRejectionEvent": { "name": "PromiseRejectionEvent", "extends": "Event", @@ -1343,63 +1260,6 @@ } } }, - "ValidityState": { - "name": "ValidityState", - "properties": { - "property": { - "tooShort": { - "name": "tooShort", - "exposed": "Window", - "read-only": 1, - "override-type": "boolean" - } - } - } - }, - "HTMLDialogElement": { - "name": "HTMLDialogElement", - "extends": "HTMLElement", - "exposed": "Window", - "properties": { - "property": { - "open": { - "name": "open", - "override-type": "boolean" - }, - "returnValue": { - "name": "returnValue", - "override-type": "string" - } - } - }, - "methods": { - "method": { - "close": { - "name": "close", - "override-signatures": [ - "close(returnValue?: string): void" - ] - }, - "show": { - "name": "show", - "override-signatures": [ - "show(): void" - ] - }, - "showModal": { - "name": "showModal", - "override-signatures": [ - "showModal(): void" - ] - } - } - }, - "constructor": { - "override-signatures": [ - "new(): HTMLDialogElement" - ] - } - }, "HTMLMainElement": { "name": "HTMLMainElement", "extends": "HTMLElement", @@ -1410,34 +1270,6 @@ ] } }, - "HTMLDetailsElement": { - "name": "HTMLDetailsElement", - "extends": "HTMLElement", - "exposed": "Window", - "properties": { - "property": { - "open": { - "name": "open", - "override-type": "boolean" - } - } - }, - "constructor": { - "override-signatures": [ - "new(): HTMLDetailsElement" - ] - } - }, - "HTMLSummaryElement": { - "name": "HTMLSummaryElement", - "extends": "HTMLElement", - "exposed": "Window", - "constructor": { - "override-signatures": [ - "new(): HTMLSummaryElement" - ] - } - }, "EXT_blend_minmax": { "name": "EXT_blend_minmax", "exposed": "Window", @@ -2123,6 +1955,27 @@ }, "no-interface-object": "1" }, + "HTMLDetailsElement": { + "element": [ + { + "name": "details" + } + ] + }, + "HTMLScriptElement": { + "element": [ + { + "name": "script" + } + ] + }, + "HTMLSlotElement": { + "element": [ + { + "name": "slot" + } + ] + }, "HTMLTableDataCellElement": { "name": "HTMLTableDataCellElement", "extends": "HTMLTableCellElement", @@ -2153,6 +2006,13 @@ } ] }, + "HTMLTemplateElement": { + "element": [ + { + "name": "template" + } + ] + }, "NodeSelector": { "name": "NodeSelector", "extends": "Object", diff --git a/inputfiles/idl/HTML - Custom elements.commentmap.json b/inputfiles/idl/HTML - Custom elements.commentmap.json new file mode 100644 index 000000000..44855d24e --- /dev/null +++ b/inputfiles/idl/HTML - Custom elements.commentmap.json @@ -0,0 +1,3 @@ +{ + "window-customelements": "Tries to upgrade all shadow-including\ninclusive descendant elements of root, even if they are not\nconnected." +} diff --git a/inputfiles/idl/HTML - Custom elements.widl b/inputfiles/idl/HTML - Custom elements.widl new file mode 100644 index 000000000..2e8a55d30 --- /dev/null +++ b/inputfiles/idl/HTML - Custom elements.widl @@ -0,0 +1,13 @@ +[Exposed=Window] +interface CustomElementRegistry { + [CEReactions] void define(DOMString name, CustomElementConstructor constructor, optional ElementDefinitionOptions options); + any get(DOMString name); + Promise whenDefined(DOMString name); + [CEReactions] void upgrade(Node root); +}; + +callback CustomElementConstructor = any (); + +dictionary ElementDefinitionOptions { + DOMString extends; +}; diff --git a/inputfiles/idl/HTML - Interactive elements.commentmap.json b/inputfiles/idl/HTML - Interactive elements.commentmap.json new file mode 100644 index 000000000..2521c01c2 --- /dev/null +++ b/inputfiles/idl/HTML - Interactive elements.commentmap.json @@ -0,0 +1,6 @@ +{ + "dialog-show": "Displays the dialog element.", + "dialog-showmodal": "Displays the dialog element and makes it the top-most modal dialog.\nThis method honors the autofocus attribute.", + "dialog-close": "Closes the dialog element.\nThe argument, if provided, provides a return value.", + "dialog-returnvalue": "Returns the dialog's return value.\nCan be set, to update the return value." +} diff --git a/inputfiles/idl/HTML - Interactive elements.widl b/inputfiles/idl/HTML - Interactive elements.widl new file mode 100644 index 000000000..142aaf480 --- /dev/null +++ b/inputfiles/idl/HTML - Interactive elements.widl @@ -0,0 +1,15 @@ +[Exposed=Window, + HTMLConstructor] +interface HTMLDetailsElement : HTMLElement { + [CEReactions] attribute boolean open; +}; + +[Exposed=Window, + HTMLConstructor] +interface HTMLDialogElement : HTMLElement { + [CEReactions] attribute boolean open; + attribute DOMString returnValue; + [CEReactions] void show(); + [CEReactions] void showModal(); + [CEReactions] void close(optional DOMString returnValue); +}; diff --git a/inputfiles/idl/HTML - Scripting.commentmap.json b/inputfiles/idl/HTML - Scripting.commentmap.json new file mode 100644 index 000000000..af87a409b --- /dev/null +++ b/inputfiles/idl/HTML - Scripting.commentmap.json @@ -0,0 +1,7 @@ +{ + "script-text": "Returns the child text content of the element.\nCan be set, to replace the element's children with the given value.", + "template-content": "Returns the template contents (a DocumentFragment).", + "slot-name": "Can be used to get and set slot's name.", + "slot-assignednodes": "Returns slot's assigned nodes, if any, and slot's children\notherwise, and does the same for any slot elements encountered therein, recursively,\nuntil there are no slot elements left.", + "slot-assignedelements": "Returns the same as assignedNodes({ flatten: true\n}), limited to elements." +} diff --git a/inputfiles/idl/HTML - Scripting.widl b/inputfiles/idl/HTML - Scripting.widl new file mode 100644 index 000000000..758a6a5ac --- /dev/null +++ b/inputfiles/idl/HTML - Scripting.widl @@ -0,0 +1,32 @@ +[Exposed=Window, + HTMLConstructor] +interface HTMLScriptElement : HTMLElement { + [CEReactions] attribute USVString src; + [CEReactions] attribute DOMString type; + [CEReactions] attribute boolean noModule; + [CEReactions] attribute boolean async; + [CEReactions] attribute boolean defer; + [CEReactions] attribute DOMString? crossOrigin; + [CEReactions] attribute DOMString text; + [CEReactions] attribute DOMString integrity; + [CEReactions] attribute DOMString referrerPolicy; + +}; + +[Exposed=Window, + HTMLConstructor] +interface HTMLTemplateElement : HTMLElement { + readonly attribute DocumentFragment content; +}; + +[Exposed=Window, + HTMLConstructor] +interface HTMLSlotElement : HTMLElement { + [CEReactions] attribute DOMString name; + sequence assignedNodes(optional AssignedNodesOptions options); + sequence assignedElements(optional AssignedNodesOptions options); +}; + +dictionary AssignedNodesOptions { + boolean flatten = false; +}; diff --git a/inputfiles/idlSources.json b/inputfiles/idlSources.json index 5984c14fc..ce46e45b6 100644 --- a/inputfiles/idlSources.json +++ b/inputfiles/idlSources.json @@ -35,6 +35,10 @@ "url": "https://html.spec.whatwg.org/multipage/common-dom-interfaces.html", "title": "HTML - Common DOM interfaces" }, + { + "url": "https://html.spec.whatwg.org/multipage/custom-elements.html", + "title": "HTML - Custom elements" + }, { "url": "https://html.spec.whatwg.org/multipage/form-control-infrastructure.html", "title": "HTML - Form control infrastructure" @@ -43,11 +47,19 @@ "url": "https://html.spec.whatwg.org/multipage/form-elements.html", "title": "HTML - Form elements" }, + { + "url": "https://html.spec.whatwg.org/multipage/interactive-elements.html", + "title": "HTML - Interactive elements" + }, { "url": "https://html.spec.whatwg.org/multipage/obsolete.html", "title": "HTML - Obsolete features", "deprecated": true }, + { + "url": "https://html.spec.whatwg.org/multipage/scripting.html", + "title": "HTML - Scripting" + }, { "url": "https://html.spec.whatwg.org/multipage/webstorage.html", "title": "HTML - Web storage" diff --git a/inputfiles/removedTypes.json b/inputfiles/removedTypes.json index 9204f2db3..c0b7c8e4f 100644 --- a/inputfiles/removedTypes.json +++ b/inputfiles/removedTypes.json @@ -1,6 +1,7 @@ { "callback-functions": { "callback-function": { + "CustomElementConstructor": null, "Function": null } }, diff --git a/src/emitter.ts b/src/emitter.ts index 463164f0a..7e8b0341e 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -293,6 +293,7 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { return baseTypeConversionMap.get(objDomType)!; } switch (objDomType) { + case "CustomElementConstructor": return "Function"; case "DOMHighResTimeStamp": return "number"; case "DOMTimeStamp": return "number"; case "EventListener": return "EventListenerOrEventListenerObject";