Javascript's RegExp.compile is not in the standard, but it's widely implemented by browsers including MSIE, Opera, and Firefox. Safari/WebKit should implement it too, for compatibile behavior with these browsers on identical code.
Created attachment 16949 [details] proposed fix Maybe I'm missing something about this method, as I don't see any use for it - but tests do pass :)
Comment on attachment 16949 [details] proposed fix Seems fine. r=me We should figure out what good this is! And make tests that cover its value.
(In reply to comment #1) > Maybe I'm missing something about this method, as I don't see any use for it - > but tests do pass :) (In reply to comment #2) > We should figure out what good this is! And make tests that cover its value. The notion of compiling a regular expression makes it possible to save time when using the regex repeatedly in a loop because it's saved in an intermediate format that's immediately useable instead of having to reparse the text representation every time. It's similar to creating a "prepared database statement" in many SQL APIs (such as Perl's DBI and Java's JDBC and the new JavaScript Database API). Perhaps this doesn't matter as much in JavaScript, though, since the expression is compiled with the source?
AFAICT, any RegExp construction compiles it anyway - (new RegExp).compile(...) is the same as new RegExp(...) in this regard. http://blog.stevenlevithan.com/archives/levels-of-javascript-regex-knowledge Level 4 (of 7) Haxz0r: ...Knows that properties of the global RegExp object and the compile() method are deprecated.
Sure, I'm familiar with the broad general notion of compiling a regular expression. But in our JavaScript implementation, at least, that happens when you create a RegExp object. What puzzles me (and presumably, Alexey) is what additional value the compile function provides.
(In reply to comment #5) > what additional value [does] the compile function provide In theory, it should provide absolutely no value, which I presume is why it has been deprecated/removed since JavaScript 1.5 (ECMA-262 3rd Edition). Personally I would recommend that WebKit *not* implement it, to encourage people who use it to stop doing so. The method might have had some relevance in previous versions of JavaScript or previous browser implementations, but there is no reason to use it anymore.
If there are existing websites that use it, we probably should put the implementation in. Leaving it out of Safari, if it's in IE and Firefox, will more likely make them think Safari is broken rather than encouraging them to remove it.
Yeah, I know that makes sense, but I hate to see meaningless cruft like this used by people who come from programming languages where compiling a regex can actually have significant performance impact. Actually, I can think of one thing that is different between using compile and just creating a new RegExp object. AFAIK, using compile on an existing regex will not discard custom properties on the object. However, I hope no one is relying on this feature (if I am in fact correct) since compile() has been deprecated for nearly a decade.
Committed revision 27303. I don't know any sites that use RegExp.compile, but given that it is widely documented and implemented, I'm sure there are quite a few. > AFAIK, using compile on an existing regex will not discard > custom properties on the object. This is correct. Also, I can imagine situations where modifying an object leads to slightly nicer looking code than re-creating it. After all, compile() doesn't cause any architectural problems for anyone AFAICT, so I don't think we need to actively discourage it.
To add to what ap said above, his patch fixed an oft-duped compatibility problem with bmwusa.com.