Skip to content

Commit 0bbeded

Browse files
committed
Bumping the version of wgxpath, which also means bumping the android apk.
1 parent 822467e commit 0bbeded

File tree

9 files changed

+200
-18
lines changed

9 files changed

+200
-18
lines changed

android/prebuilt/android-server.apk

0 Bytes
Binary file not shown.

third_party/js/wgxpath/binaryExpr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ wgxpath.BinaryExpr.stringToOpMap_ = {};
243243
*/
244244
wgxpath.BinaryExpr.createOp_ = function(opString, precedence, dataType,
245245
evaluate) {
246-
if (opString in wgxpath.BinaryExpr.stringToOpMap_) {
246+
if (wgxpath.BinaryExpr.stringToOpMap_.hasOwnProperty(opString)) {
247247
throw new Error('Binary operator already created: ' + opString);
248248
}
249249
// The upcast and then downcast for the JSCompiler.

third_party/js/wgxpath/functionCall.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ wgxpath.FunctionCall.nameToFuncMap_ = {};
219219
wgxpath.FunctionCall.createFunc_ = function(name, dataType,
220220
needContextPosition, needContextNodeWithoutArgs, needContextNodeWithArgs,
221221
evaluate, minArgs, opt_maxArgs, opt_nodesetsRequired) {
222-
if (name in wgxpath.FunctionCall.nameToFuncMap_) {
222+
if (wgxpath.FunctionCall.nameToFuncMap_.hasOwnProperty(name)) {
223223
throw new Error('Function already created: ' + name + '.');
224224
}
225225
var func = new wgxpath.FunctionCall.Func_(name, dataType,
@@ -331,7 +331,7 @@ wgxpath.FunctionCall.Func = {
331331
LANG: wgxpath.FunctionCall.createFunc_('lang',
332332
wgxpath.DataType.BOOLEAN, false, false, false,
333333
function(ctx, expr) {
334-
// TODO(user): Fully implement this.
334+
// TODO: Fully implement this.
335335
return false;
336336
}, 1),
337337
LAST: wgxpath.FunctionCall.createFunc_('last',
@@ -351,14 +351,14 @@ wgxpath.FunctionCall.Func = {
351351
NAME: wgxpath.FunctionCall.createFunc_('name',
352352
wgxpath.DataType.STRING, false, true, false,
353353
function(ctx, opt_expr) {
354-
// TODO(user): Fully implement this.
354+
// TODO: Fully implement this.
355355
var node = opt_expr ? opt_expr.evaluate(ctx).getFirst() : ctx.getNode();
356356
return node ? node.nodeName.toLowerCase() : '';
357357
}, 0, 1, true),
358358
NAMESPACE_URI: wgxpath.FunctionCall.createFunc_('namespace-uri',
359359
wgxpath.DataType.STRING, true, false, false,
360360
function(ctx, opt_expr) {
361-
// TODO(user): Fully implement this.
361+
// TODO: Fully implement this.
362362
return '';
363363
}, 0, 1, true),
364364
NORMALIZE_SPACE: wgxpath.FunctionCall.createFunc_('normalize-space',

third_party/js/wgxpath/kindTest_test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<body>
1717
<div id="div-1">Test node</div>
1818
<script>
19-
// TODO(user): Add test case for PI nodes.
19+
// TODO: Add test case for PI nodes.
2020
function testIsValid() {
2121
var nodeTypeName = 'test()';
2222
assert(!wgxpath.KindTest.isValidType(nodeTypeName));

third_party/js/wgxpath/node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ wgxpath.Node.attrMatches = function(node, name, value) {
113113
if (goog.isNull(name)) {
114114
return true;
115115
}
116-
// TODO(user): If possible, figure out why this throws an exception in some
116+
// TODO: If possible, figure out why this throws an exception in some
117117
// cases on IE < 9.
118118
try {
119119
if (!node.getAttribute) {
@@ -298,7 +298,7 @@ wgxpath.Node.getChildNodesIEPre9_ = function(test, node,
298298
}
299299
}
300300
if (attrName) {
301-
// TODO(user): See if an optimization is possible.
301+
// TODO: See if an optimization is possible.
302302
children = goog.array.filter(children, function(n) {
303303
return wgxpath.Node.attrMatches(n, attrName, attrValue);
304304
});

third_party/js/wgxpath/nsResolver.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @fileoverview Namespace resolver functions.
3+
*/
4+
5+
goog.provide('wgxpath.nsResolver');
6+
7+
goog.require('goog.dom.NodeType');
8+
9+
10+
/**
11+
* Returns a namespace resolve function for the given node.
12+
*
13+
* @param {!Node} node The context node.
14+
* @return {function(?string):?string} A lookupNamespaceURI function.
15+
*/
16+
wgxpath.nsResolver.getResolver = function(node) {
17+
// Adopted from W3C psuedocode specification:
18+
// http://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html
19+
20+
switch (node.nodeType) {
21+
case goog.dom.NodeType.ELEMENT:
22+
return goog.partial(wgxpath.nsResolver.resolveForElement_, node);
23+
24+
case goog.dom.NodeType.DOCUMENT:
25+
return wgxpath.nsResolver.getResolver(node.documentElement);
26+
27+
case goog.dom.NodeType.ATTRIBUTE:
28+
if (node.ownerElement) {
29+
return wgxpath.nsResolver.getResolver(node.ownerElement);
30+
}
31+
return wgxpath.nsResolver.nullResolver_;
32+
33+
case goog.dom.NodeType.DOCUMENT_FRAGMENT:
34+
case goog.dom.NodeType.DOCUMENT_TYPE:
35+
case goog.dom.NodeType.ENTITY:
36+
case goog.dom.NodeType.NOTATION:
37+
return wgxpath.nsResolver.nullResolver_;
38+
39+
default:
40+
if (node.parentNode) {
41+
return wgxpath.nsResolver.getResolver(node.parentNode);
42+
}
43+
return wgxpath.nsResolver.nullResolver_;
44+
}
45+
};
46+
47+
48+
/**
49+
* A resolver function that always returns null.
50+
*
51+
* @param {?string} prefix Namespace prefix or null for default namespace.
52+
* @return {?string} Null.
53+
* @private
54+
*/
55+
wgxpath.nsResolver.nullResolver_ = function(prefix) {
56+
return null;
57+
};
58+
59+
60+
/**
61+
* The default namespace URI for XHTML nodes.
62+
*
63+
* @const
64+
* @type {string}
65+
* @private
66+
*/
67+
wgxpath.nsResolver.HTML_NAMESPACE_URI_ = 'http://www.w3.org/1999/xhtml';
68+
69+
70+
/**
71+
* Looks up the namespace URI for the given prefix and given element context.
72+
*
73+
* @param {!Element} elem Context element for the namespace resolution.
74+
* @param {?string} prefix Namespace prefix or null for default namespace.
75+
* @return {?string} The namespace URI for the given prefix, or null if none.
76+
* @private
77+
*/
78+
wgxpath.nsResolver.resolveForElement_ = function(elem, prefix) {
79+
if (elem.prefix == prefix) {
80+
return elem.namespaceURI || wgxpath.nsResolver.HTML_NAMESPACE_URI_;
81+
}
82+
83+
var attr = elem.getAttributeNode('xmlns:' + prefix);
84+
if (attr && attr.specified) {
85+
return attr.value || null;
86+
}
87+
88+
if (elem.parentNode &&
89+
elem.parentNode.nodeType != goog.dom.NodeType.DOCUMENT) {
90+
return wgxpath.nsResolver.resolveForElement_(
91+
/** @type {!Element} */ (elem.parentNode), prefix);
92+
}
93+
94+
return null;
95+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<html xmlns:a="http://www.example.org/a" xmlns:b="http://www.example.org/b">
3+
<head>
4+
<title>nsResolver_test</title>
5+
<script src="../closure-library/closure/goog/base.js"></script>
6+
<script src="./test_js_deps.js"></script>
7+
<script>
8+
goog.require('goog.testing.jsunit');
9+
goog.require('goog.userAgent');
10+
goog.require('wgxpath.nsResolver');
11+
</script>
12+
</head>
13+
<body>
14+
<script>
15+
// On IE < 10, additional prefixed namespaces are not applied.
16+
function docPrefixNsUri(str) {
17+
return goog.userAgent.IE && !goog.userAgent.isVersion(10) ? null : str;
18+
}
19+
20+
function testDocumentResolver() {
21+
var resolver = wgxpath.nsResolver.getResolver(document);
22+
assertEquals('http://www.w3.org/1999/xhtml', resolver(null));
23+
assertEquals(docPrefixNsUri('http://www.example.org/a'), resolver('a'));
24+
assertEquals(docPrefixNsUri('http://www.example.org/b'), resolver('b'));
25+
assertEquals(null, resolver('c'));
26+
}
27+
28+
function testElementResolver() {
29+
var elem = document.getElementById('elem');
30+
var resolver = wgxpath.nsResolver.getResolver(elem);
31+
assertEquals('http://www.w3.org/1999/xhtml', resolver(null));
32+
assertEquals('http://www.example.org/a2', resolver('a'));
33+
assertEquals(docPrefixNsUri('http://www.example.org/b'), resolver('b'));
34+
assertEquals(null, resolver('c'));
35+
}
36+
37+
function testAttributeResolver() {
38+
var attr = document.getElementById('elem').attributes[0];
39+
var resolver = wgxpath.nsResolver.getResolver(attr);
40+
41+
// Attribute nodes do not provide ownerElement on IE < 8.
42+
if (goog.userAgent.IE && !goog.userAgent.isVersion(8)) {
43+
assertEquals(null, resolver(null));
44+
assertEquals(null, resolver('a'));
45+
assertEquals(null, resolver('b'));
46+
} else {
47+
assertEquals('http://www.w3.org/1999/xhtml', resolver(null));
48+
assertEquals('http://www.example.org/a2', resolver('a'));
49+
assertEquals(docPrefixNsUri('http://www.example.org/b'), resolver('b'));
50+
}
51+
52+
assertEquals(null, resolver('c'));
53+
}
54+
55+
function testDocumentFragmentResolver() {
56+
var docFragment = document.createDocumentFragment();
57+
var resolver = wgxpath.nsResolver.getResolver(docFragment);
58+
assertEquals(null, resolver(null));
59+
assertEquals(null, resolver('a'));
60+
assertEquals(null, resolver('b'));
61+
assertEquals(null, resolver('c'));
62+
}
63+
</script>
64+
65+
<div id="elem" xmlns:a="http://www.example.org/a2">div</div>
66+
</body>
67+
</html>

third_party/js/wgxpath/step.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ wgxpath.Step.nameToAxisMap_ = {};
272272
*/
273273
wgxpath.Step.createAxis_ =
274274
function(name, func, reverse, opt_supportsQuickAttr) {
275-
if (name in wgxpath.Step.nameToAxisMap_) {
275+
if (wgxpath.Step.nameToAxisMap_.hasOwnProperty(name)) {
276276
throw Error('Axis already created: ' + name);
277277
}
278278
// The upcast and then downcast for the JSCompiler.

third_party/js/wgxpath/wgxpath.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ goog.require('wgxpath.IEAttrWrapper');
2424
goog.require('wgxpath.Lexer');
2525
goog.require('wgxpath.NodeSet');
2626
goog.require('wgxpath.Parser');
27+
goog.require('wgxpath.nsResolver');
2728

2829

2930
/**
@@ -187,6 +188,20 @@ wgxpath.XPathResult_['FIRST_ORDERED_NODE_TYPE'] =
187188
wgxpath.XPathResultType_.FIRST_ORDERED_NODE_TYPE;
188189

189190

191+
192+
/**
193+
* The exported XPathNSResolver type.
194+
*
195+
* @constructor
196+
* @extends {XPathNSResolver}
197+
* @param {!Node} node Context node for the namespace resolution.
198+
* @private
199+
*/
200+
wgxpath.XPathNSResolver_ = function(node) {
201+
this['lookupNamespaceURI'] = wgxpath.nsResolver.getResolver(node);
202+
};
203+
204+
190205
/**
191206
* Installs the library. This is a noop if native XPath is available.
192207
*
@@ -197,14 +212,19 @@ wgxpath.install = function(opt_win) {
197212
var doc = win.document;
198213

199214
// Installation is a noop if native XPath is available.
200-
if (!doc['evaluate']) {
201-
win['XPathResult'] = wgxpath.XPathResult_;
202-
doc['evaluate'] = function(expr, context, nsResolver, type, result) {
203-
return new wgxpath.XPathExpression_(expr, nsResolver).
204-
evaluate(context, type);
205-
};
206-
doc['createExpression'] = function(expr, nsResolver) {
207-
return new wgxpath.XPathExpression_(expr, nsResolver);
208-
};
215+
if (doc['evaluate']) {
216+
return;
209217
}
218+
219+
win['XPathResult'] = wgxpath.XPathResult_;
220+
doc['evaluate'] = function(expr, context, nsResolver, type, result) {
221+
return new wgxpath.XPathExpression_(expr, nsResolver).
222+
evaluate(context, type);
223+
};
224+
doc['createExpression'] = function(expr, nsResolver) {
225+
return new wgxpath.XPathExpression_(expr, nsResolver);
226+
};
227+
doc['createNSResolver'] = function(node) {
228+
return new wgxpath.XPathNSResolver_(node);
229+
};
210230
};

0 commit comments

Comments
 (0)