diff --git a/xpath.js b/xpath.js index c3b298f..c08f391 100644 --- a/xpath.js +++ b/xpath.js @@ -1312,9 +1312,10 @@ var xpath = (typeof exports === 'undefined') ? {} : exports; var rhs = []; for (var i = 0; i < num; i++) { tokenType.pop(); - rhs.unshift(tokenValue.pop()); + rhs.push(tokenValue.pop()); state.pop(); } + rhs.reverse(); var s_ = state[state.length - 1]; tokenType.push(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0]); if (this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32] == undefined) { @@ -2011,13 +2012,14 @@ var xpath = (typeof exports === 'undefined') ? {} : exports; } var st = []; if (xpc.contextNode.firstChild != null) { - st.unshift(xpc.contextNode.firstChild); + st.push(xpc.contextNode.firstChild); } else { - st.unshift(xpc.contextNode.nextSibling); + st.push(xpc.contextNode.nextSibling); } for (var m = xpc.contextNode.parentNode; m != null && m.nodeType != NodeTypes.DOCUMENT_NODE && m !== xpc.virtualRoot; m = m.parentNode) { - st.unshift(m.nextSibling); + st.push(m.nextSibling); } + st.reverse(); do { for (var m = st.pop(); m != null;) { if (step.nodeTest.matches(m, xpc)) { @@ -2102,7 +2104,7 @@ var xpath = (typeof exports === 'undefined') ? {} : exports; break outer; } if (step.nodeTest.matches(m, xpc)) { - newNodes.unshift(m); + newNodes.push(m); } if (m.firstChild != null) { st.push(m.nextSibling); @@ -2112,6 +2114,7 @@ var xpath = (typeof exports === 'undefined') ? {} : exports; } } } + newNodes.reverse(); break; case Step.PRECEDINGSIBLING: