Bug 79938

Summary: 'source' property of RegExp instance cannot be ""
Product: WebKit Reporter: Gavin Barraclough <barraclough>
Component: JavaScriptCoreAssignee: Gavin Barraclough <barraclough>
Status: RESOLVED FIXED    
Severity: Normal CC: adamk, arv, erikcorry, haraken, rossberg
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Fix oliver: review+

Gavin Barraclough
Reported 2012-02-29 13:25:43 PST
15.10.6.4 specifies that RegExp.prototype.toString must return '/' + source + '/', and also states that the result must be a valid RegularExpressionLiteral. '//' is not a valid RegularExpressionLiteral (since it is a single line comment), and hence source cannot ever validly be "". If the source is empty, return a different Pattern that would match the same thing.
Attachments
Fix (11.73 KB, patch)
2012-02-29 13:32 PST, Gavin Barraclough
oliver: review+
Gavin Barraclough
Comment 1 2012-02-29 13:32:28 PST
Gavin Barraclough
Comment 2 2012-02-29 15:24:49 PST
Fixed in r109275
Erik Arvidsson
Comment 3 2012-02-29 16:21:03 PST
We should update the spec for this. We should point out that the "source" property cannot be "" due to the toString behavior.
Gavin Barraclough
Comment 4 2012-02-29 17:03:50 PST
(In reply to comment #3) > We should update the spec for this. We should point out that the "source" property cannot be "" due to the toString behavior. Aye, that sounds like a good plan – I got half way through filing a bug against test262 before realizing this. :-)
Kentaro Hara
Comment 5 2012-02-29 17:38:55 PST
Your patch fixed JSC only, and RegExp.html starts to fail on Chromium/V8. - Since this requires a fix in V8, I filed a bug in V8: http://code.google.com/p/v8/issues/detail?id=1983&thanks=1983&ts=1330565749 - I'll add the FAIL line to chromium/test_expectations.txt
Erik Arvidsson
Comment 6 2012-02-29 21:34:21 PST
I thought Adam already took care of adding this to the test_expectations?
Kentaro Hara
Comment 7 2012-02-29 21:35:36 PST
(In reply to comment #6) > I thought Adam already took care of adding this to the test_expectations? Yeah, I found the line:) I just filed a bug in V8. Thanks.
Kentaro Hara
Comment 8 2012-02-29 21:36:20 PST
(In reply to comment #7) > (In reply to comment #6) > > I thought Adam already took care of adding this to the test_expectations? Ah, the V8 bug is already there. Sorry for the confusion.
Erik Corry
Comment 9 2012-03-01 00:57:02 PST
How about: re = new RegExp("\n"); eval(re.toString()); // Syntax error.
Andreas Rossberg
Comment 10 2012-03-01 01:56:19 PST
Note that the spec of toString uses the 'source' property of the regexp object, which Section 15.10.4.1 specifies to be the properly escaped version of the original argument string. The same paragraph in that section also specifies explicitly that 'source' should be set to "(?:)" if the original string is empty.
Gavin Barraclough
Comment 11 2012-03-01 15:52:46 PST
(In reply to comment #10) > Note that the spec of toString uses the 'source' property of the regexp object, which Section 15.10.4.1 specifies to be the properly escaped version of the original argument string. The same paragraph in that section also specifies explicitly that 'source' should be set to "(?:)" if the original string is empty. Ah, I had somehow managed to overlook that, thank you! I guess I can simplify my comment, and just reference this rather than deriving the behavior. :-)
Note You need to log in before you can comment on or make changes to this bug.