Commit b8668fa8 authored by jwolfe's avatar jwolfe Committed by Commit bot

Recognize HTMLCloseComment after multiline comment

When the scanner finds a '-->', it's either part of an HTMLCloseComment
or a '--' followed by a '>'. Previously, only a preceding newline would
make it an HTMLCloseComment. Now, a preceding multiline comment also
makes it an HTMLCloseComment. The effect is that now the following is
not a SyntaxError:

x/*
*/-->this is now a comment

BUG=v8:5142
LOG=y

Review-Url: https://codereview.chromium.org/2119763003
Cr-Commit-Position: refs/heads/master@{#37656}
parent 77cbe276
...@@ -564,7 +564,7 @@ void Scanner::Scan() { ...@@ -564,7 +564,7 @@ void Scanner::Scan() {
Advance(); Advance();
if (c0_ == '-') { if (c0_ == '-') {
Advance(); Advance();
if (c0_ == '>' && has_line_terminator_before_next_) { if (c0_ == '>' && HasAnyLineTerminatorBeforeNext()) {
// For compatibility with SpiderMonkey, we skip lines that // For compatibility with SpiderMonkey, we skip lines that
// start with an HTML comment end '-->'. // start with an HTML comment end '-->'.
token = SkipSingleLineComment(); token = SkipSingleLineComment();
......
...@@ -120,15 +120,32 @@ TEST(ScanHTMLEndComments) { ...@@ -120,15 +120,32 @@ TEST(ScanHTMLEndComments) {
// whitespace, even a multiline-comment containing a newline). // whitespace, even a multiline-comment containing a newline).
// This was not the case if it occurred before the first real token // This was not the case if it occurred before the first real token
// in the input. // in the input.
// clang-format off
const char* tests[] = { const char* tests[] = {
// Before first real token. // Before first real token.
"-->",
"--> is eol-comment",
"--> is eol-comment\nvar y = 37;\n", "--> is eol-comment\nvar y = 37;\n",
"\n --> is eol-comment\nvar y = 37;\n", "\n --> is eol-comment\nvar y = 37;\n",
"\n-->is eol-comment\nvar y = 37;\n",
"\n-->\nvar y = 37;\n",
"/* precomment */ --> is eol-comment\nvar y = 37;\n", "/* precomment */ --> is eol-comment\nvar y = 37;\n",
"/* precomment */-->eol-comment\nvar y = 37;\n",
"\n/* precomment */ --> is eol-comment\nvar y = 37;\n", "\n/* precomment */ --> is eol-comment\nvar y = 37;\n",
"\n/*precomment*/-->eol-comment\nvar y = 37;\n",
// After first real token. // After first real token.
"var x = 42;\n--> is eol-comment\nvar y = 37;\n", "var x = 42;\n--> is eol-comment\nvar y = 37;\n",
"var x = 42;\n/* precomment */ --> is eol-comment\nvar y = 37;\n", "var x = 42;\n/* precomment */ --> is eol-comment\nvar y = 37;\n",
"x/* precomment\n */ --> is eol-comment\nvar y = 37;\n",
"var x = 42; /* precomment\n */ --> is eol-comment\nvar y = 37;\n",
"var x = 42;/*\n*/-->is eol-comment\nvar y = 37;\n",
// With multiple comments preceding HTMLEndComment
"/* MLC \n */ /* SLDC */ --> is eol-comment\nvar y = 37;\n",
"/* MLC \n */ /* SLDC1 */ /* SLDC2 */ --> is eol-comment\nvar y = 37;\n",
"/* MLC1 \n */ /* MLC2 \n */ --> is eol-comment\nvar y = 37;\n",
"/* SLDC */ /* MLC \n */ --> is eol-comment\nvar y = 37;\n",
"/* MLC1 \n */ /* SLDC1 */ /* MLC2 \n */ /* SLDC2 */ --> is eol-comment\n"
"var y = 37;\n",
NULL NULL
}; };
...@@ -136,11 +153,10 @@ TEST(ScanHTMLEndComments) { ...@@ -136,11 +153,10 @@ TEST(ScanHTMLEndComments) {
"x --> is eol-comment\nvar y = 37;\n", "x --> is eol-comment\nvar y = 37;\n",
"\"\\n\" --> is eol-comment\nvar y = 37;\n", "\"\\n\" --> is eol-comment\nvar y = 37;\n",
"x/* precomment */ --> is eol-comment\nvar y = 37;\n", "x/* precomment */ --> is eol-comment\nvar y = 37;\n",
"x/* precomment\n */ --> is eol-comment\nvar y = 37;\n",
"var x = 42; --> is eol-comment\nvar y = 37;\n", "var x = 42; --> is eol-comment\nvar y = 37;\n",
"var x = 42; /* precomment\n */ --> is eol-comment\nvar y = 37;\n",
NULL NULL
}; };
// clang-format on
// Parser/Scanner needs a stack limit. // Parser/Scanner needs a stack limit.
CcTest::i_isolate()->stack_guard()->SetStackLimit( CcTest::i_isolate()->stack_guard()->SetStackLimit(
......
...@@ -30,7 +30,7 @@ PASS 'should be a syntax error' --> threw exception ReferenceError: Invalid left ...@@ -30,7 +30,7 @@ PASS 'should be a syntax error' --> threw exception ReferenceError: Invalid left
PASS /**/ 1 --> threw exception ReferenceError: Invalid left-hand side expression in postfix operation. PASS /**/ 1 --> threw exception ReferenceError: Invalid left-hand side expression in postfix operation.
PASS 1 /**/ --> threw exception ReferenceError: Invalid left-hand side expression in postfix operation. PASS 1 /**/ --> threw exception ReferenceError: Invalid left-hand side expression in postfix operation.
PASS 1/* PASS 1/*
*/--> threw exception SyntaxError: Unexpected token >. */--> is 1
PASS --> is undefined. PASS --> is undefined.
PASS /**/--> is undefined. PASS /**/--> is undefined.
PASS /* PASS /*
......
...@@ -26,7 +26,7 @@ description("Test to ensure correct handling of --> as a single line comment whe ...@@ -26,7 +26,7 @@ description("Test to ensure correct handling of --> as a single line comment whe
shouldThrow("'should be a syntax error' -->"); shouldThrow("'should be a syntax error' -->");
shouldThrow("/**/ 1 -->"); shouldThrow("/**/ 1 -->");
shouldThrow("1 /**/ -->"); shouldThrow("1 /**/ -->");
shouldThrow("1/*\n*/-->"); shouldBe("1/*\n*/-->", "1");
shouldBeUndefined("-->"); shouldBeUndefined("-->");
shouldBeUndefined("/**/-->"); shouldBeUndefined("/**/-->");
......
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