Skip to content

Commit 45ca1d4

Browse files
saschanazsandersn
authored andcommitted
add XPath types (#666)
1 parent 9ee7163 commit 45ca1d4

File tree

5 files changed

+85
-63
lines changed

5 files changed

+85
-63
lines changed

baselines/dom.generated.d.ts

+13-19
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,8 @@ interface EventListener {
16591659
(evt: Event): void;
16601660
}
16611661

1662+
type XPathNSResolver = ((prefix: string | null) => string | null) | { lookupNamespaceURI(prefix: string | null): string | null; };
1663+
16621664
/** 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. */
16631665
interface ANGLE_instanced_arrays {
16641666
drawArraysInstancedANGLE(mode: GLenum, first: GLint, count: GLsizei, primcount: GLsizei): void;
@@ -4139,7 +4141,7 @@ interface DocumentEventMap extends GlobalEventHandlersEventMap, DocumentAndEleme
41394141
}
41404142

41414143
/** Any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree. */
4142-
interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, ParentNode, GlobalEventHandlers, DocumentAndElementEventHandlers {
4144+
interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, ParentNode, XPathEvaluatorBase, GlobalEventHandlers, DocumentAndElementEventHandlers {
41434145
/**
41444146
* Sets or gets the URL for the current document.
41454147
*/
@@ -4520,7 +4522,6 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par
45204522
*/
45214523
elementFromPoint(x: number, y: number): Element | null;
45224524
elementsFromPoint(x: number, y: number): Element[];
4523-
evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | ((prefix: string) => string | null) | null, type: number, result: XPathResult | null): XPathResult;
45244525
/**
45254526
* Executes a command on the current document, current selection, or the given range.
45264527
* @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,37 +17434,30 @@ declare var XMLSerializer: {
1743317434
};
1743417435

1743517436
/** The XPathEvaluator interface allows to compile and evaluate XPath expressions. */
17436-
interface XPathEvaluator {
17437-
createExpression(expression: string, resolver: XPathNSResolver): XPathExpression;
17438-
createNSResolver(nodeResolver?: Node): XPathNSResolver;
17439-
evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | ((prefix: string) => string | null) | null, type: number, result: XPathResult | null): XPathResult;
17437+
interface XPathEvaluator extends XPathEvaluatorBase {
1744017438
}
1744117439

1744217440
declare var XPathEvaluator: {
1744317441
prototype: XPathEvaluator;
1744417442
new(): XPathEvaluator;
1744517443
};
1744617444

17445+
interface XPathEvaluatorBase {
17446+
createExpression(expression: string, resolver?: XPathNSResolver | null): XPathExpression;
17447+
createNSResolver(nodeResolver: Node): XPathNSResolver;
17448+
evaluate(expression: string, contextNode: Node, resolver?: XPathNSResolver | null, type?: number, result?: XPathResult | null): XPathResult;
17449+
}
17450+
1744717451
/** This interface is a compiled XPath expression that can be evaluated on a document or specific node to return information its DOM tree. */
1744817452
interface XPathExpression {
17449-
evaluate(contextNode: Node, type: number, result: XPathResult | null): XPathResult;
17453+
evaluate(contextNode: Node, type?: number, result?: XPathResult | null): XPathResult;
1745017454
}
1745117455

1745217456
declare var XPathExpression: {
1745317457
prototype: XPathExpression;
1745417458
new(): XPathExpression;
1745517459
};
1745617460

17457-
/** The XPathNSResolver interface permits prefix strings in an XPath expression to be properly bound to namespace URI strings. */
17458-
interface XPathNSResolver {
17459-
lookupNamespaceURI(prefix: string): string | null;
17460-
}
17461-
17462-
declare var XPathNSResolver: {
17463-
prototype: XPathNSResolver;
17464-
new(): XPathNSResolver;
17465-
};
17466-
1746717461
/** The results generated by evaluating an XPath expression within the context of a given node. */
1746817462
interface XPathResult {
1746917463
readonly booleanValue: boolean;
@@ -17473,8 +17467,8 @@ interface XPathResult {
1747317467
readonly singleNodeValue: Node | null;
1747417468
readonly snapshotLength: number;
1747517469
readonly stringValue: string;
17476-
iterateNext(): Node;
17477-
snapshotItem(index: number): Node;
17470+
iterateNext(): Node | null;
17471+
snapshotItem(index: number): Node | null;
1747817472
readonly ANY_TYPE: number;
1747917473
readonly ANY_UNORDERED_NODE_TYPE: number;
1748017474
readonly BOOLEAN_TYPE: number;

inputfiles/idl/DOM XPath.widl

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[Exposed=Window]
2+
interface XPathResult {
3+
const unsigned short ANY_TYPE = 0;
4+
const unsigned short NUMBER_TYPE = 1;
5+
const unsigned short STRING_TYPE = 2;
6+
const unsigned short BOOLEAN_TYPE = 3;
7+
const unsigned short UNORDERED_NODE_ITERATOR_TYPE = 4;
8+
const unsigned short ORDERED_NODE_ITERATOR_TYPE = 5;
9+
const unsigned short UNORDERED_NODE_SNAPSHOT_TYPE = 6;
10+
const unsigned short ORDERED_NODE_SNAPSHOT_TYPE = 7;
11+
const unsigned short ANY_UNORDERED_NODE_TYPE = 8;
12+
const unsigned short FIRST_ORDERED_NODE_TYPE = 9;
13+
14+
readonly attribute unsigned short resultType;
15+
readonly attribute unrestricted double numberValue;
16+
// Maybe "DOMString?".
17+
readonly attribute DOMString stringValue;
18+
readonly attribute boolean booleanValue;
19+
readonly attribute Node? singleNodeValue;
20+
readonly attribute boolean invalidIteratorState;
21+
readonly attribute unsigned long snapshotLength;
22+
Node? iterateNext();
23+
Node? snapshotItem(unsigned long index);
24+
};
25+
26+
[Exposed=Window]
27+
interface XPathExpression {
28+
XPathResult evaluate(Node contextNode,
29+
optional unsigned short type,
30+
optional XPathResult? result);
31+
};
32+
33+
callback interface XPathNSResolver {
34+
DOMString? lookupNamespaceURI(DOMString? prefix);
35+
};
36+
37+
interface mixin XPathEvaluatorBase {
38+
XPathExpression createExpression(DOMString expression,
39+
optional XPathNSResolver? resolver);
40+
XPathNSResolver createNSResolver(Node nodeResolver);
41+
XPathResult evaluate(DOMString expression,
42+
Node contextNode,
43+
optional XPathNSResolver? resolver,
44+
optional unsigned short type,
45+
optional XPathResult? result);
46+
};
47+
48+
[Exposed=Window, Constructor]
49+
interface XPathEvaluator {};
50+
51+
XPathEvaluator includes XPathEvaluatorBase;
52+
Document includes XPathEvaluatorBase;

inputfiles/idlSources.json

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
"url": "https://w3c.github.io/DOM-Parsing/",
4545
"title": "DOM Parsing and Serialization"
4646
},
47+
{
48+
"url": "https://wiki.whatwg.org/wiki/DOM_XPath",
49+
"title": "DOM XPath"
50+
},
4751
{
4852
"url": "https://encoding.spec.whatwg.org/",
4953
"title": "Encoding"

inputfiles/overridingTypes.json

-43
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,6 @@
317317
},
318318
"interfaces": {
319319
"interface": {
320-
"XPathNSResolver": {
321-
"methods": {
322-
"method": {
323-
"lookupNamespaceURI": {
324-
"override-signatures": [
325-
"lookupNamespaceURI(prefix: string): string | null"
326-
]
327-
}
328-
}
329-
}
330-
},
331320
"CryptoKey": {
332321
"properties": {
333322
"property": {
@@ -522,12 +511,6 @@
522511
"elementsFromPoint(x: number, y: number): Element[]"
523512
]
524513
},
525-
"evaluate": {
526-
"name": "evaluate",
527-
"override-signatures": [
528-
"evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | ((prefix: string) => string | null) | null, type: number, result: XPathResult | null): XPathResult"
529-
]
530-
},
531514
"getElementsByTagNameNS": {
532515
"name": "getElementsByTagNameNS",
533516
"override-signatures": [
@@ -1501,32 +1484,6 @@
15011484
}
15021485
}
15031486
},
1504-
"XPathEvaluator": {
1505-
"name": "XPathEvaluator",
1506-
"methods": {
1507-
"method": {
1508-
"evaluate": {
1509-
"name": "evaluate",
1510-
"override-signatures": [
1511-
"evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | ((prefix: string) => string | null) | null, type: number, result: XPathResult | null): XPathResult"
1512-
]
1513-
}
1514-
}
1515-
}
1516-
},
1517-
"XPathExpression": {
1518-
"name": "XPathExpression",
1519-
"methods": {
1520-
"method": {
1521-
"evaluate": {
1522-
"name": "evaluate",
1523-
"override-signatures": [
1524-
"evaluate(contextNode: Node, type: number, result: XPathResult | null): XPathResult"
1525-
]
1526-
}
1527-
}
1528-
}
1529-
},
15301487
"DOMStringMap": {
15311488
"name": "DOMStringMap",
15321489
"override-index-signatures": [

inputfiles/removedTypes.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
}
5959
}
6060
},
61+
"Document": {
62+
"methods": {
63+
"method": {
64+
"evaluate": null
65+
}
66+
}
67+
},
6168
"FileReaderProgressEvent": null,
6269
"HTMLAreasCollection": null,
6370
"HTMLBodyElement": {
@@ -211,7 +218,15 @@
211218
"wheelDeltaY": null
212219
}
213220
}
214-
}
221+
},
222+
"XPathEvaluator": {
223+
"methods": {
224+
"method": {
225+
"evaluate": null
226+
}
227+
}
228+
},
229+
"XPathNSResolver": null
215230
}
216231
},
217232
"dictionaries": {

0 commit comments

Comments
 (0)