Skip to content

Add XPath types #666

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
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 14 additions & 19 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -17375,47 +17376,41 @@ 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: {
prototype: 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: {
prototype: 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;
Expand Down
52 changes: 52 additions & 0 deletions inputfiles/idl/DOM XPath.widl
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 0 additions & 43 deletions inputfiles/overridingTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,6 @@
},
"interfaces": {
"interface": {
"XPathNSResolver": {
"methods": {
"method": {
"lookupNamespaceURI": {
"override-signatures": [
"lookupNamespaceURI(prefix: string): string | null"
]
}
}
}
},
"CryptoKey": {
"properties": {
"property": {
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down
17 changes: 16 additions & 1 deletion inputfiles/removedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
}
}
},
"Document": {
"methods": {
"method": {
"evaluate": null
}
}
},
"FileReaderProgressEvent": null,
"HTMLAreasCollection": null,
"HTMLBodyElement": {
Expand Down Expand Up @@ -211,7 +218,15 @@
"wheelDeltaY": null
}
}
}
},
"XPathEvaluator": {
"methods": {
"method": {
"evaluate": null
}
}
},
"XPathNSResolver": null
}
},
"dictionaries": {
Expand Down