Commit ee59eff1 authored by lrn@chromium.org's avatar lrn@chromium.org

Make line-terminators inside multi-line comments count.

Now follows the specification. Follows WebKit change in revision 89100.

BUG=86431
TEST=regress-892742

Review URL: http://codereview.chromium.org/7184034

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8317 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fbe89ca1
...@@ -144,7 +144,7 @@ Token::Value JavaScriptScanner::SkipSingleLineComment() { ...@@ -144,7 +144,7 @@ Token::Value JavaScriptScanner::SkipSingleLineComment() {
// to be part of the single-line comment; it is recognized // to be part of the single-line comment; it is recognized
// separately by the lexical grammar and becomes part of the // separately by the lexical grammar and becomes part of the
// stream of input elements for the syntactic grammar (see // stream of input elements for the syntactic grammar (see
// ECMA-262, section 7.4, page 12). // ECMA-262, section 7.4).
while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
Advance(); Advance();
} }
...@@ -160,13 +160,14 @@ Token::Value JavaScriptScanner::SkipMultiLineComment() { ...@@ -160,13 +160,14 @@ Token::Value JavaScriptScanner::SkipMultiLineComment() {
while (c0_ >= 0) { while (c0_ >= 0) {
char ch = c0_; char ch = c0_;
Advance(); Advance();
if (unicode_cache_->IsLineTerminator(ch)) {
// Following ECMA-262, section 7.4, a comment containing
// a newline will make the comment count as a line-terminator.
has_line_terminator_before_next_ = true;
}
// If we have reached the end of the multi-line comment, we // If we have reached the end of the multi-line comment, we
// consume the '/' and insert a whitespace. This way all // consume the '/' and insert a whitespace. This way all
// multi-line comments are treated as whitespace - even the ones // multi-line comments are treated as whitespace.
// containing line terminators. This contradicts ECMA-262, section
// 7.4, page 12, that says that multi-line comments containing
// line terminators should be treated as a line terminator, but it
// matches the behaviour of SpiderMonkey and KJS.
if (ch == '*' && c0_ == '/') { if (ch == '*' && c0_ == '/') {
c0_ = ' '; c0_ = ' ';
return Token::WHITESPACE; return Token::WHITESPACE;
......
...@@ -26,25 +26,23 @@ ...@@ -26,25 +26,23 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function f() { function f() {
return/* useless*/1; return/* Counts as non-line-terminating whitespace */1;
}; };
// According to ECMA-262, this comment should be parsed as a
// According to ECMA-262, this comment should actually be parsed as a // line terminator making g() return undefined.
// line terminator making g() return undefined, but this is not the
// way it's handled by Spidermonkey or KJS.
function g() { function g() {
return/* useless return/* Counts as line-terminator whitespace.
*/2; */2;
}; };
function h() { function h() {
return// meaningful return// Comment doesn't include line-terminator at end.
3; 3;
}; };
assertEquals(1, f()); assertEquals(1, f());
assertEquals(2, g()); assertEquals(undefined, g());
assertTrue(typeof h() == 'undefined', 'h'); assertEquals(undefined, h());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment