I just tried your code, what exactly is your document.evaluate() supposed to return? As in the result and the data type.
Here are my observations testing the JS code via Python bindings of Selenium:
I get what appears to be a browser hang executing your code as is.
If I execute "return document.getElementsByXPath('//a').length;" I get count of links found. This does require executing the snippet of code listed here to call document.getElementsByXPath:
and borrowing on the idea above, if I change your code a bit to use "XPathResult.ORDERED_NODE_SNAPSHOT_TYPE" I get exception that the expression cannot be convertd to return the specified type.
You might want to try document.getElementsByXPath().length (or without length, if you want the whole list of WebElements back) as an alternative to your JS query.
There's also document.getElementsByCssSelector() if you look at the blog post above.
I'm guessing document.evaluate() works in Selenium but depending on what you're evaluating it may hang the browser, so you're better off avoiding it and using different JS code to do what you want.