From 358df58e6163df123a14fbf271efade076f0a3c1 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 4 Mar 2019 23:11:58 +0900 Subject: [PATCH] add XPath types --- baselines/dom.generated.d.ts | 33 +++++++++------------ inputfiles/idl/DOM XPath.widl | 52 +++++++++++++++++++++++++++++++++ inputfiles/idlSources.json | 4 +++ inputfiles/overridingTypes.json | 43 --------------------------- inputfiles/removedTypes.json | 17 ++++++++++- 5 files changed, 86 insertions(+), 63 deletions(-) create mode 100644 inputfiles/idl/DOM XPath.widl diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 7a980ebbd..2fba9739b 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -1630,6 +1630,8 @@ interface EventListener { (evt: Event): void; } +type XPathNSResolver = ((prefix: string | null) => string | null) | { lookupNamespaceURI(prefix: string | null): string | null; }; + /** The ANGLE_instanced_arrays extension is part of the WebGL API and allows to draw the same object, or groups of similar objects multiple times, if they share the same vertex data, primitive count and type. */ interface ANGLE_instanced_arrays { drawArraysInstancedANGLE(mode: GLenum, first: GLint, count: GLsizei, primcount: GLsizei): void; @@ -4113,7 +4115,7 @@ interface DocumentEventMap extends GlobalEventHandlersEventMap, DocumentAndEleme } /** The Document interface represents any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree. */ -interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, ParentNode, GlobalEventHandlers, DocumentAndElementEventHandlers { +interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, ParentNode, XPathEvaluatorBase, GlobalEventHandlers, DocumentAndElementEventHandlers { /** * Sets or gets the URL for the current document. */ @@ -4494,7 +4496,6 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par */ elementFromPoint(x: number, y: number): Element | null; elementsFromPoint(x: number, y: number): Element[]; - evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | ((prefix: string) => string | null) | null, type: number, result: XPathResult | null): XPathResult; /** * Executes a command on the current document, current selection, or the given range. * @param commandId String that specifies the command to execute. This command can be any of the command identifiers that can be executed in script. @@ -17375,10 +17376,7 @@ declare var XMLSerializer: { new(): XMLSerializer; }; -interface XPathEvaluator { - createExpression(expression: string, resolver: XPathNSResolver): XPathExpression; - createNSResolver(nodeResolver?: Node): XPathNSResolver; - evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | ((prefix: string) => string | null) | null, type: number, result: XPathResult | null): XPathResult; +interface XPathEvaluator extends XPathEvaluatorBase { } declare var XPathEvaluator: { @@ -17386,9 +17384,15 @@ declare var XPathEvaluator: { new(): XPathEvaluator; }; +interface XPathEvaluatorBase { + createExpression(expression: string, resolver?: XPathNSResolver | null): XPathExpression; + createNSResolver(nodeResolver: Node): XPathNSResolver; + evaluate(expression: string, contextNode: Node, resolver?: XPathNSResolver | null, type?: number, result?: XPathResult | null): XPathResult; +} + /** An XPathExpression is a compiled XPath query returned from document.createExpression(). It has a method evaluate() which can be used to execute the compiled XPath. */ interface XPathExpression { - evaluate(contextNode: Node, type: number, result: XPathResult | null): XPathResult; + evaluate(contextNode: Node, type?: number, result?: XPathResult | null): XPathResult; } declare var XPathExpression: { @@ -17396,26 +17400,17 @@ declare var XPathExpression: { new(): XPathExpression; }; -interface XPathNSResolver { - lookupNamespaceURI(prefix: string): string | null; -} - -declare var XPathNSResolver: { - prototype: XPathNSResolver; - new(): XPathNSResolver; -}; - /** The XPathResult interface represents the results generated by evaluating an XPath 1.0 expression within the context of a given node. */ interface XPathResult { readonly booleanValue: boolean; readonly invalidIteratorState: boolean; readonly numberValue: number; readonly resultType: number; - readonly singleNodeValue: Node; + readonly singleNodeValue: Node | null; readonly snapshotLength: number; readonly stringValue: string; - iterateNext(): Node; - snapshotItem(index: number): Node; + iterateNext(): Node | null; + snapshotItem(index: number): Node | null; readonly ANY_TYPE: number; readonly ANY_UNORDERED_NODE_TYPE: number; readonly BOOLEAN_TYPE: number; diff --git a/inputfiles/idl/DOM XPath.widl b/inputfiles/idl/DOM XPath.widl new file mode 100644 index 000000000..27f1d95a1 --- /dev/null +++ b/inputfiles/idl/DOM XPath.widl @@ -0,0 +1,52 @@ +[Exposed=Window] +interface XPathResult { + const unsigned short ANY_TYPE = 0; + const unsigned short NUMBER_TYPE = 1; + const unsigned short STRING_TYPE = 2; + const unsigned short BOOLEAN_TYPE = 3; + const unsigned short UNORDERED_NODE_ITERATOR_TYPE = 4; + const unsigned short ORDERED_NODE_ITERATOR_TYPE = 5; + const unsigned short UNORDERED_NODE_SNAPSHOT_TYPE = 6; + const unsigned short ORDERED_NODE_SNAPSHOT_TYPE = 7; + const unsigned short ANY_UNORDERED_NODE_TYPE = 8; + const unsigned short FIRST_ORDERED_NODE_TYPE = 9; + + readonly attribute unsigned short resultType; + readonly attribute unrestricted double numberValue; + // Maybe "DOMString?". + readonly attribute DOMString stringValue; + readonly attribute boolean booleanValue; + readonly attribute Node? singleNodeValue; + readonly attribute boolean invalidIteratorState; + readonly attribute unsigned long snapshotLength; + Node? iterateNext(); + Node? snapshotItem(unsigned long index); +}; + +[Exposed=Window] +interface XPathExpression { + XPathResult evaluate(Node contextNode, + optional unsigned short type, + optional XPathResult? result); +}; + +callback interface XPathNSResolver { + DOMString? lookupNamespaceURI(DOMString? prefix); +}; + +interface mixin XPathEvaluatorBase { + XPathExpression createExpression(DOMString expression, + optional XPathNSResolver? resolver); + XPathNSResolver createNSResolver(Node nodeResolver); + XPathResult evaluate(DOMString expression, + Node contextNode, + optional XPathNSResolver? resolver, + optional unsigned short type, + optional XPathResult? result); +}; + +[Exposed=Window, Constructor] +interface XPathEvaluator {}; + +XPathEvaluator includes XPathEvaluatorBase; +Document includes XPathEvaluatorBase; diff --git a/inputfiles/idlSources.json b/inputfiles/idlSources.json index 75c262276..8b2560706 100644 --- a/inputfiles/idlSources.json +++ b/inputfiles/idlSources.json @@ -36,6 +36,10 @@ "url": "https://w3c.github.io/DOM-Parsing/", "title": "DOM Parsing and Serialization" }, + { + "url": "https://wiki.whatwg.org/wiki/DOM_XPath", + "title": "DOM XPath" + }, { "url": "https://encoding.spec.whatwg.org/", "title": "Encoding" diff --git a/inputfiles/overridingTypes.json b/inputfiles/overridingTypes.json index e0798c9e6..0783b5697 100644 --- a/inputfiles/overridingTypes.json +++ b/inputfiles/overridingTypes.json @@ -307,17 +307,6 @@ }, "interfaces": { "interface": { - "XPathNSResolver": { - "methods": { - "method": { - "lookupNamespaceURI": { - "override-signatures": [ - "lookupNamespaceURI(prefix: string): string | null" - ] - } - } - } - }, "CryptoKey": { "properties": { "property": { @@ -512,12 +501,6 @@ "elementsFromPoint(x: number, y: number): Element[]" ] }, - "evaluate": { - "name": "evaluate", - "override-signatures": [ - "evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | ((prefix: string) => string | null) | null, type: number, result: XPathResult | null): XPathResult" - ] - }, "getElementsByTagNameNS": { "name": "getElementsByTagNameNS", "override-signatures": [ @@ -1490,32 +1473,6 @@ } } }, - "XPathEvaluator": { - "name": "XPathEvaluator", - "methods": { - "method": { - "evaluate": { - "name": "evaluate", - "override-signatures": [ - "evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | ((prefix: string) => string | null) | null, type: number, result: XPathResult | null): XPathResult" - ] - } - } - } - }, - "XPathExpression": { - "name": "XPathExpression", - "methods": { - "method": { - "evaluate": { - "name": "evaluate", - "override-signatures": [ - "evaluate(contextNode: Node, type: number, result: XPathResult | null): XPathResult" - ] - } - } - } - }, "DOMStringMap": { "name": "DOMStringMap", "override-index-signatures": [ diff --git a/inputfiles/removedTypes.json b/inputfiles/removedTypes.json index a5b9f9a5a..fe89112b0 100644 --- a/inputfiles/removedTypes.json +++ b/inputfiles/removedTypes.json @@ -58,6 +58,13 @@ } } }, + "Document": { + "methods": { + "method": { + "evaluate": null + } + } + }, "FileReaderProgressEvent": null, "HTMLAreasCollection": null, "HTMLBodyElement": { @@ -211,7 +218,15 @@ "wheelDeltaY": null } } - } + }, + "XPathEvaluator": { + "methods": { + "method": { + "evaluate": null + } + } + }, + "XPathNSResolver": null } }, "dictionaries": {