Bug 79938 - 'source' property of RegExp instance cannot be ""
Summary: 'source' property of RegExp instance cannot be ""
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Gavin Barraclough
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-29 13:25 PST by Gavin Barraclough
Modified: 2012-03-01 15:52 PST (History)
5 users (show)

See Also:


Attachments
Fix (11.73 KB, patch)
2012-02-29 13:32 PST, Gavin Barraclough
oliver: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gavin Barraclough 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.
Comment 1 Gavin Barraclough 2012-02-29 13:32:28 PST
Created attachment 129505 [details]
Fix
Comment 2 Gavin Barraclough 2012-02-29 15:24:49 PST
Fixed in r109275
Comment 3 Erik Arvidsson 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.
Comment 4 Gavin Barraclough 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. :-)
Comment 5 Kentaro Hara 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
Comment 6 Erik Arvidsson 2012-02-29 21:34:21 PST
I thought Adam already took care of adding this to the test_expectations?
Comment 7 Kentaro Hara 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.
Comment 8 Kentaro Hara 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.
Comment 9 Erik Corry 2012-03-01 00:57:02 PST
How about:

re = new RegExp("\n");
eval(re.toString());  // Syntax error.
Comment 10 Andreas Rossberg 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.
Comment 11 Gavin Barraclough 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. :-)