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
This commit is contained in:
lrn@chromium.org 2010-09-02 07:36:30 +00:00
parent fce2fad17e
commit 5628d3c482
2 changed files with 38 additions and 1 deletions

View File

@ -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<const char>();
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();
}

View File

@ -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<uintptr_t>(&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;
}
}