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.
Created attachment 129505 [details] Fix
Fixed in r109275
We should update the spec for this. We should point out that the "source" property cannot be "" due to the toString behavior.
(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. :-)
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
I thought Adam already took care of adding this to the test_expectations?
(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.
(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.
How about: re = new RegExp("\n"); eval(re.toString()); // Syntax error.
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.
(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. :-)