WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
Bug 11001
WebKit doesn't support RegExp.compile method
https://bugs.webkit.org/show_bug.cgi?id=11001
Summary
WebKit doesn't support RegExp.compile method
evariste
Reported
2006-09-23 16:56:01 PDT
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.
Attachments
proposed fix
(85.75 KB, patch)
2007-10-30 10:48 PDT
,
Alexey Proskuryakov
darin
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Alexey Proskuryakov
Comment 1
2007-10-30 10:48:30 PDT
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 :)
Darin Adler
Comment 2
2007-10-30 11:09:45 PDT
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.
David Kilzer (:ddkilzer)
Comment 3
2007-10-30 11:38:44 PDT
(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?
Alexey Proskuryakov
Comment 4
2007-10-30 11:47:16 PDT
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.
Darin Adler
Comment 5
2007-10-30 11:52:04 PDT
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.
Steven Levithan
Comment 6
2007-10-30 12:54:44 PDT
(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.
Darin Adler
Comment 7
2007-10-30 13:08:49 PDT
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.
Steven Levithan
Comment 8
2007-10-30 17:32:25 PDT
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.
Alexey Proskuryakov
Comment 9
2007-10-31 01:46:15 PDT
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.
Geoffrey Garen
Comment 10
2007-11-06 13:31:53 PST
To add to what ap said above, his patch fixed an oft-duped compatibility problem with bmwusa.com.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug