<http://code.google.com/p/py-dom-xpath/> is a Python implementation of XPath 1.0, and it comes with a test suite that we could convert into JavaScript. The code is under MIT License. Patch forthcoming.
Created attachment 30869 [details] proposed patch This also fixes some minor bugs found with the test suite.
Comment on attachment 30869 [details] proposed patch > + Fix bugs found with this test suite: > + - name and local-name were incorrect for processing instructions (XPath expanded-name > + doesn't match DOM exactly); > + - name, local-name and namespace functions sould crash on attribute nodes; Typo: "sould" > + which doesn't match anything available via DOM exactly. Calculate the expanded name properly. > + (WebCore::XPath::FunNamespaceURI::evaluate): This function could crash if used with an > + attribute node, because it released what was possibly the only reference to attribute node > + before using it. Changed the fucntion to avoid such situation. Typo: "fucntion" > + > + // String::toDouble() supports exponential notation, which is not allowed in XPath. > + unsigned len = str.length(); > + for (unsigned i = 0; i < len; ++i) { > + UChar c = str[i]; > + if ((c < '0' || c > '9') && c != '.' && c != '-') Can we use isASCIIDigit here? r=me
Committed revision 44361. > Can we use isASCIIDigit here? We can!
Comment on attachment 30869 [details] proposed patch > + unsigned len = str.length(); > + for (unsigned i = 0; i < len; ++i) { > + UChar c = str[i]; > + if ((c < '0' || c > '9') && c != '.' && c != '-') > + return numeric_limits<double>::quiet_NaN(); > + } I'd like to see this in a helper function, just because the name of that function might be a useful bit of documentation.