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() {
// to be part of the single-line comment; it is recognized
// separately by the lexical grammar and becomes part of the
// 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_)) {
Advance();
}
......@@ -160,13 +160,14 @@ Token::Value JavaScriptScanner::SkipMultiLineComment() {
while (c0_ >= 0) {
char ch = c0_;
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
// consume the '/' and insert a whitespace. This way all
// multi-line comments are treated as whitespace - even the ones
// 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.
// multi-line comments are treated as whitespace.
if (ch == '*' && c0_ == '/') {
c0_ = ' ';
return Token::WHITESPACE;
......
......@@ -26,25 +26,23 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function f() {
return/* useless*/1;
return/* Counts as non-line-terminating whitespace */1;
};
// According to ECMA-262, this comment should actually be parsed as a
// line terminator making g() return undefined, but this is not the
// way it's handled by Spidermonkey or KJS.
// According to ECMA-262, this comment should be parsed as a
// line terminator making g() return undefined.
function g() {
return/* useless
return/* Counts as line-terminator whitespace.
*/2;
};
function h() {
return// meaningful
return// Comment doesn't include line-terminator at end.
3;
};
assertEquals(1, f());
assertEquals(2, g());
assertTrue(typeof h() == 'undefined', 'h');
assertEquals(undefined, g());
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