From 5628d3c482fb8c8fc989b84364ab2a31ea3cf0de Mon Sep 17 00:00:00 2001 From: "lrn@chromium.org" Date: Thu, 2 Sep 2010 07:36:30 +0000 Subject: [PATCH] Fix parsing of /**/--> on first line of input. BUG=53548 TEST= Review URL: http://codereview.chromium.org/3330001 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5400 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/scanner.cc | 6 +++++- test/cctest/test-parsing.cc | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/scanner.cc b/src/scanner.cc index 1a8d721..334aff9 100755 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -430,6 +430,7 @@ Token::Value Scanner::Next() { stack_overflow_ = true; next_.token = Token::ILLEGAL; } else { + has_line_terminator_before_next_ = false; Scan(); } return current_.token; @@ -772,7 +773,6 @@ Token::Value Scanner::ScanJsonIdentifier(const char* text, void Scanner::ScanJavaScript() { next_.literal_chars = Vector(); Token::Value token; - has_line_terminator_before_next_ = false; do { // Remember the position of the next token next_.location.beg_pos = source_pos(); @@ -1013,6 +1013,10 @@ void Scanner::ScanJavaScript() { void Scanner::SeekForward(int pos) { source_->SeekForward(pos - 1); Advance(); + // This function is only called to seek to the location + // of the end of a function (at the "}" token). It doesn't matter + // whether there was a line terminator in the part we skip. + has_line_terminator_before_next_ = false; Scan(); } diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index d62b6a5..ed0c8b5 100755 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -32,6 +32,7 @@ #include "token.h" #include "scanner.h" #include "utils.h" +#include "execution.h" #include "cctest.h" @@ -127,3 +128,35 @@ TEST(KeywordMatcher) { CHECK_EQ(i::Token::IDENTIFIER, full_stop.token()); } + +TEST(ScanHTMLEndComments) { + // Regression test. See: + // http://code.google.com/p/chromium/issues/detail?id=53548 + // Tests that --> is correctly interpreted as comment-to-end-of-line if there + // is only whitespace before it on the line, even after a multiline-comment + // comment. This was not the case if it occurred before the first real token + // in the input. + const char* tests[] = { + // Before first real token. + "--> is eol-comment\nvar y = 37;\n", + "\n --> is eol-comment\nvar y = 37;\n", + "/* precomment */ --> is eol-comment\nvar y = 37;\n", + "\n/* precomment */ --> is eol-comment\nvar y = 37;\n", + // After first real token. + "var x = 42;\n--> is eol-comment\nvar y = 37;\n", + "var x = 42;\n/* precomment */ --> is eol-comment\nvar y = 37;\n", + NULL + }; + + // Parser needs a stack limit. + int marker; + i::StackGuard::SetStackLimit( + reinterpret_cast(&marker) - 128 * 1024); + + for (int i = 0; tests[i]; i++) { + v8::ScriptData* data = + v8::ScriptData::PreCompile(tests[i], strlen(tests[i])); + CHECK(data != NULL && !data->HasError()); + delete data; + } +} -- 2.7.4