diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index d5db552d8..15c37fdac 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -1659,6 +1659,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; @@ -4139,7 +4141,7 @@ interface DocumentEventMap extends GlobalEventHandlersEventMap, DocumentAndEleme } /** 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. */ @@ -4520,7 +4522,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. @@ -17433,10 +17434,7 @@ declare var XMLSerializer: { }; /** The XPathEvaluator interface allows to compile and evaluate XPath expressions. */ -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: { @@ -17444,9 +17442,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; +} + /** This interface is a compiled XPath expression that can be evaluated on a document or specific node to return information its DOM tree. */ interface XPathExpression { - evaluate(contextNode: Node, type: number, result: XPathResult | null): XPathResult; + evaluate(contextNode: Node, type?: number, result?: XPathResult | null): XPathResult; } declare var XPathExpression: { @@ -17454,16 +17458,6 @@ declare var XPathExpression: { new(): XPathExpression; }; -/** The XPathNSResolver interface permits prefix strings in an XPath expression to be properly bound to namespace URI strings. */ -interface XPathNSResolver { - lookupNamespaceURI(prefix: string): string | null; -} - -declare var XPathNSResolver: { - prototype: XPathNSResolver; - new(): XPathNSResolver; -}; - /** The results generated by evaluating an XPath expression within the context of a given node. */ interface XPathResult { readonly booleanValue: boolean; @@ -17473,8 +17467,8 @@ interface XPathResult { 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 1a0fe0acd..eeba565c1 100644 --- a/inputfiles/idlSources.json +++ b/inputfiles/idlSources.json @@ -44,6 +44,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 c69fa5dda..a6e142416 100644 --- a/inputfiles/overridingTypes.json +++ b/inputfiles/overridingTypes.json @@ -317,17 +317,6 @@ }, "interfaces": { "interface": { - "XPathNSResolver": { - "methods": { - "method": { - "lookupNamespaceURI": { - "override-signatures": [ - "lookupNamespaceURI(prefix: string): string | null" - ] - } - } - } - }, "CryptoKey": { "properties": { "property": { @@ -522,12 +511,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": [ @@ -1501,32 +1484,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": {