heygrady/transform

Exec Pointer Reset fails in Chrome

Closed this issue · 4 comments

In your library you use the following snippet to reset regex pointer:
rfuncvalue.exec(''); // hacky, reset the regex pointer

Chrome sometimes appears to not evaluate this statement causing animation errors.

Using a blank space appears to reset the pointer properly and fix the problem:
rfuncvalue.exec(' ');

is there a blog article or other resource that explains this better? I'll make your change in the next release but I'd like to read more about the correct way to reset a regex pointer.

I have seen no previous public reference to this,

I don't have time to make a test now but in Chrome the '/g" flag does not appear to be reset when using a blank exec statement. It is probably a browser optimization on parsing empty strings. I know of no other way to reset the pointer except the hack you are using, but it appears it requires at least some string value to reset in Chrome

I'm using the dev flavor of Chrome (7.0.536.2 dev,) but I have heard similar reports from standard channel as well.

I take that back, a little bit further reading it looks like the Regexp has a listIndex property which can be reset.

When exec( ) is called for a regular expression that has the g flag, it sets the lastIndex property of the regular expression object to the character position immediately following the matched substring.
http://docstore.mik.ua/orelly/webprog/jscript/ch10_03.htm

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/exec

Thanks so much for digging deeper. I read that Mozilla article over and over when I was writing that code. I'll test it out.