This is a bit of a conundrum, I have an idea of how I might be able to fix it but I'm wondering if there's a (much) easier way.
In short, whenever a regular expression is executed in JavaScript, certain properties are assigned values on the RegExp constructor. For instance:
/foo/.test('football')
//-> true
RegExp.input
//-> "football"
RegExp.rightContext
//-> "tball"
I'd like to execute a regular expression without affecting these properties. If that's not possible (and I don't think it is), I'd like to at least restore them to their previous values afterwards.
I know input/$_ is writeable, but most of the others aren't, it seems. One option might be to reconstruct a regular expression that would reapply all these values, but I think that would be quite difficult.
The reason I want this is because I'm writing a shim of a native API, and testing it using the test262 suite. The test262 suite fails on certain tests where it checks to see if the RegExp object has unexpected values for these properties.