I was trying to answer this question on SO. After a lot of mucking around in the debugger , I isolated the problem. I investigated it further and compared browsers, finally determining that it was an issue with Chrome V8 (I also filed a bug report).
My answer there contains a concise analysis and a link to a bug report. I also suggested an alternate method, but I couldn't give details since I hadn't understood the OP's algorithm.
Since "It's a bug" doesn't really solve the problem, am I out of line for answering it?