lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.2.0 vs lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.3.0

- old
+ new

@@ -48,35 +48,44 @@ PoltergeistAgent.prototype.currentUrl = function() { return window.location.toString(); }; PoltergeistAgent.prototype.find = function(method, selector, within) { - var el, i, results, xpath, _i, _len, _results; + var el, error, i, results, xpath, _i, _len, _results; if (within == null) { within = document; } - if (method === "xpath") { - xpath = document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); - results = (function() { - var _i, _ref, _results; + try { + if (method === "xpath") { + xpath = document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + results = (function() { + var _i, _ref, _results; - _results = []; - for (i = _i = 0, _ref = xpath.snapshotLength; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - _results.push(xpath.snapshotItem(i)); - } - return _results; - })(); - } else { - results = within.querySelectorAll(selector); + _results = []; + for (i = _i = 0, _ref = xpath.snapshotLength; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + _results.push(xpath.snapshotItem(i)); + } + return _results; + })(); + } else { + results = within.querySelectorAll(selector); + } + _results = []; + for (_i = 0, _len = results.length; _i < _len; _i++) { + el = results[_i]; + _results.push(this.register(el)); + } + return _results; + } catch (_error) { + error = _error; + if (error.code === DOMException.SYNTAX_ERR) { + throw new PoltergeistAgent.InvalidSelector; + } else { + throw error; + } } - _results = []; - for (_i = 0, _len = results.length; _i < _len; _i++) { - el = results[_i]; - _results.push(this.register(el)); - } - return _results; }; PoltergeistAgent.prototype.register = function(element) { this.elements.push(element); return this.elements.length - 1; @@ -123,9 +132,20 @@ ObsoleteNode.prototype.toString = function() { return "PoltergeistAgent.ObsoleteNode"; }; return ObsoleteNode; + +})(); + +PoltergeistAgent.InvalidSelector = (function() { + function InvalidSelector() {} + + InvalidSelector.prototype.toString = function() { + return "PoltergeistAgent.InvalidSelector"; + }; + + return InvalidSelector; })(); PoltergeistAgent.Node = (function() { Node.EVENTS = {