Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: test/cctest/test-parsing.cc

Issue 2009963002: [modules] Disable HTML-like comments Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Unify behavior for optimized and non-optimized executions Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/scanner.cc ('k') | test/mjsunit/harmony/modules-html-comments.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 36f729344f94e2fc931bfe43fa42f2d46cfcbb12..aa0771af9393c10863926e77b068b3a2116669bc 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -71,7 +71,7 @@ TEST(ScanKeywords) {
{
i::Utf8ToUtf16CharacterStream stream(keyword, length);
i::Scanner scanner(&unicode_cache);
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
CHECK_EQ(key_token.token, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next());
}
@@ -79,7 +79,7 @@ TEST(ScanKeywords) {
{
i::Utf8ToUtf16CharacterStream stream(keyword, length - 1);
i::Scanner scanner(&unicode_cache);
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next());
}
@@ -90,7 +90,7 @@ TEST(ScanKeywords) {
buffer[length] = chars_to_append[j];
i::Utf8ToUtf16CharacterStream stream(buffer, length + 1);
i::Scanner scanner(&unicode_cache);
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next());
}
@@ -100,7 +100,7 @@ TEST(ScanKeywords) {
buffer[length - 1] = '_';
i::Utf8ToUtf16CharacterStream stream(buffer, length);
i::Scanner scanner(&unicode_cache);
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next());
}
@@ -108,83 +108,6 @@ TEST(ScanKeywords) {
}
-TEST(ScanHTMLEndComments) {
- v8::V8::Initialize();
- v8::Isolate* isolate = CcTest::isolate();
- v8::HandleScope handles(isolate);
-
- // 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 (with comments considered as
- // whitespace, even a multiline-comment containing a newline).
- // 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
- };
-
- const char* fail_tests[] = {
- "x --> 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\n */ --> 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
- };
-
- // Parser/Scanner needs a stack limit.
- CcTest::i_isolate()->stack_guard()->SetStackLimit(
- i::GetCurrentStackPosition() - 128 * 1024);
- uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
- for (int i = 0; tests[i]; i++) {
- const i::byte* source =
- reinterpret_cast<const i::byte*>(tests[i]);
- i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i]));
- i::CompleteParserRecorder log;
- i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(&stream);
- i::Zone zone(CcTest::i_isolate()->allocator());
- i::AstValueFactory ast_value_factory(
- &zone, CcTest::i_isolate()->heap()->HashSeed());
- i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
- stack_limit);
- preparser.set_allow_lazy(true);
- i::PreParser::PreParseResult result = preparser.PreParseProgram();
- CHECK_EQ(i::PreParser::kPreParseSuccess, result);
- CHECK(!log.HasError());
- }
-
- for (int i = 0; fail_tests[i]; i++) {
- const i::byte* source =
- reinterpret_cast<const i::byte*>(fail_tests[i]);
- i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
- i::CompleteParserRecorder log;
- i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(&stream);
- i::Zone zone(CcTest::i_isolate()->allocator());
- i::AstValueFactory ast_value_factory(
- &zone, CcTest::i_isolate()->heap()->HashSeed());
- i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
- stack_limit);
- preparser.set_allow_lazy(true);
- i::PreParser::PreParseResult result = preparser.PreParseProgram();
- // Even in the case of a syntax error, kPreParseSuccess is returned.
- CHECK_EQ(i::PreParser::kPreParseSuccess, result);
- CHECK(log.HasError());
- }
-}
-
-
class ScriptResource : public v8::String::ExternalOneByteStringResource {
public:
ScriptResource(const char* data, size_t length)
@@ -330,7 +253,7 @@ TEST(StandAlonePreParser) {
static_cast<unsigned>(strlen(program)));
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
i::Zone zone(CcTest::i_isolate()->allocator());
i::AstValueFactory ast_value_factory(
@@ -366,7 +289,7 @@ TEST(StandAlonePreParserNoNatives) {
static_cast<unsigned>(strlen(program)));
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
// Preparser defaults to disallowing natives syntax.
i::Zone zone(CcTest::i_isolate()->allocator());
@@ -437,7 +360,7 @@ TEST(RegressChromium62639) {
static_cast<unsigned>(strlen(program)));
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
i::Zone zone(CcTest::i_isolate()->allocator());
i::AstValueFactory ast_value_factory(&zone,
CcTest::i_isolate()->heap()->HashSeed());
@@ -472,7 +395,7 @@ TEST(Regress928) {
i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
i::Zone zone(CcTest::i_isolate()->allocator());
i::AstValueFactory ast_value_factory(&zone,
CcTest::i_isolate()->heap()->HashSeed());
@@ -524,7 +447,7 @@ TEST(PreParseOverflow) {
static_cast<unsigned>(kProgramSize));
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
i::Zone zone(CcTest::i_isolate()->allocator());
i::AstValueFactory ast_value_factory(&zone,
@@ -754,7 +677,7 @@ void TestStreamScanner(i::Utf16CharacterStream* stream,
int skip_pos = 0, // Zero means not skipping.
int skip_to = 0) {
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(stream);
+ scanner.Initialize(stream, true);
int i = 0;
do {
@@ -837,7 +760,7 @@ void TestScanRegExp(const char* re_source, const char* expected) {
static_cast<unsigned>(strlen(re_source)));
i::HandleScope scope(CcTest::i_isolate());
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, true);
i::Token::Value start = scanner.peek();
CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV);
@@ -1558,7 +1481,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
stack_limit);
SetParserFlags(&preparser, flags);
- scanner.Initialize(&stream);
+ scanner.Initialize(&stream, !is_module);
i::PreParser::PreParseResult result =
preparser.PreParseProgram(&preparser_materialized_literals, is_module);
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
@@ -5680,6 +5603,92 @@ TEST(ImportExportParsingErrors) {
}
}
+TEST(ScanHTMLEndComments) {
+ v8::V8::Initialize();
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope handles(isolate);
+
+ // 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 (with comments considered as
+ // whitespace, even a multiline-comment containing a newline).
+ // 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
+ };
+
+ const char* fail_tests[] = {
+ "x --> 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\n */ --> 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
+ };
+
+ // Parser/Scanner needs a stack limit.
+ CcTest::i_isolate()->stack_guard()->SetStackLimit(
+ i::GetCurrentStackPosition() - 128 * 1024);
+ uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
+ for (int i = 0; tests[i]; i++) {
+ const i::byte* source =
+ reinterpret_cast<const i::byte*>(tests[i]);
+ i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i]));
+ i::CompleteParserRecorder log;
+ i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
+ scanner.Initialize(&stream, true);
+ i::Zone zone(CcTest::i_isolate()->allocator());
+ i::AstValueFactory ast_value_factory(
+ &zone, CcTest::i_isolate()->heap()->HashSeed());
+ i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
+ stack_limit);
+ preparser.set_allow_lazy(true);
+ i::PreParser::PreParseResult result = preparser.PreParseProgram();
+ CHECK_EQ(i::PreParser::kPreParseSuccess, result);
+ CHECK(!log.HasError());
+ }
+
+ for (int i = 0; fail_tests[i]; i++) {
+ const i::byte* source =
+ reinterpret_cast<const i::byte*>(fail_tests[i]);
+ i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
+ i::CompleteParserRecorder log;
+ i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
+ scanner.Initialize(&stream, true);
+ i::Zone zone(CcTest::i_isolate()->allocator());
+ i::AstValueFactory ast_value_factory(
+ &zone, CcTest::i_isolate()->heap()->HashSeed());
+ i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
+ stack_limit);
+ preparser.set_allow_lazy(true);
+ i::PreParser::PreParseResult result = preparser.PreParseProgram();
+ // Even in the case of a syntax error, kPreParseSuccess is returned.
+ CHECK_EQ(i::PreParser::kPreParseSuccess, result);
+ CHECK(log.HasError());
+ }
+
+ // ES2015 B.1.3 HTML-like Comments:
+ //
+ // > The syntax and semantics of 11.4 is extended as follows except that this
+ // > extension is not allowed when parsing source code using the goal symbol
+ // > Module
+ const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
+
+ RunModuleParserSyncTest(context_data, tests, kError);
+ RunModuleParserSyncTest(context_data, fail_tests, kError);
+}
+
TEST(ModuleTopLevelFunctionDecl) {
// clang-format off
const char* kErrorSources[] = {
« no previous file with comments | « src/parsing/scanner.cc ('k') | test/mjsunit/harmony/modules-html-comments.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698