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

Side by Side 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, 6 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 i::UnicodeCache unicode_cache; 64 i::UnicodeCache unicode_cache;
65 i::byte buffer[32]; 65 i::byte buffer[32];
66 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { 66 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) {
67 const i::byte* keyword = 67 const i::byte* keyword =
68 reinterpret_cast<const i::byte*>(key_token.keyword); 68 reinterpret_cast<const i::byte*>(key_token.keyword);
69 int length = i::StrLength(key_token.keyword); 69 int length = i::StrLength(key_token.keyword);
70 CHECK(static_cast<int>(sizeof(buffer)) >= length); 70 CHECK(static_cast<int>(sizeof(buffer)) >= length);
71 { 71 {
72 i::Utf8ToUtf16CharacterStream stream(keyword, length); 72 i::Utf8ToUtf16CharacterStream stream(keyword, length);
73 i::Scanner scanner(&unicode_cache); 73 i::Scanner scanner(&unicode_cache);
74 scanner.Initialize(&stream); 74 scanner.Initialize(&stream, true);
75 CHECK_EQ(key_token.token, scanner.Next()); 75 CHECK_EQ(key_token.token, scanner.Next());
76 CHECK_EQ(i::Token::EOS, scanner.Next()); 76 CHECK_EQ(i::Token::EOS, scanner.Next());
77 } 77 }
78 // Removing characters will make keyword matching fail. 78 // Removing characters will make keyword matching fail.
79 { 79 {
80 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1); 80 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1);
81 i::Scanner scanner(&unicode_cache); 81 i::Scanner scanner(&unicode_cache);
82 scanner.Initialize(&stream); 82 scanner.Initialize(&stream, true);
83 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); 83 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
84 CHECK_EQ(i::Token::EOS, scanner.Next()); 84 CHECK_EQ(i::Token::EOS, scanner.Next());
85 } 85 }
86 // Adding characters will make keyword matching fail. 86 // Adding characters will make keyword matching fail.
87 static const char chars_to_append[] = { 'z', '0', '_' }; 87 static const char chars_to_append[] = { 'z', '0', '_' };
88 for (int j = 0; j < static_cast<int>(arraysize(chars_to_append)); ++j) { 88 for (int j = 0; j < static_cast<int>(arraysize(chars_to_append)); ++j) {
89 i::MemMove(buffer, keyword, length); 89 i::MemMove(buffer, keyword, length);
90 buffer[length] = chars_to_append[j]; 90 buffer[length] = chars_to_append[j];
91 i::Utf8ToUtf16CharacterStream stream(buffer, length + 1); 91 i::Utf8ToUtf16CharacterStream stream(buffer, length + 1);
92 i::Scanner scanner(&unicode_cache); 92 i::Scanner scanner(&unicode_cache);
93 scanner.Initialize(&stream); 93 scanner.Initialize(&stream, true);
94 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); 94 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
95 CHECK_EQ(i::Token::EOS, scanner.Next()); 95 CHECK_EQ(i::Token::EOS, scanner.Next());
96 } 96 }
97 // Replacing characters will make keyword matching fail. 97 // Replacing characters will make keyword matching fail.
98 { 98 {
99 i::MemMove(buffer, keyword, length); 99 i::MemMove(buffer, keyword, length);
100 buffer[length - 1] = '_'; 100 buffer[length - 1] = '_';
101 i::Utf8ToUtf16CharacterStream stream(buffer, length); 101 i::Utf8ToUtf16CharacterStream stream(buffer, length);
102 i::Scanner scanner(&unicode_cache); 102 i::Scanner scanner(&unicode_cache);
103 scanner.Initialize(&stream); 103 scanner.Initialize(&stream, true);
104 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); 104 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
105 CHECK_EQ(i::Token::EOS, scanner.Next()); 105 CHECK_EQ(i::Token::EOS, scanner.Next());
106 } 106 }
107 } 107 }
108 } 108 }
109 109
110 110
111 TEST(ScanHTMLEndComments) {
112 v8::V8::Initialize();
113 v8::Isolate* isolate = CcTest::isolate();
114 v8::HandleScope handles(isolate);
115
116 // Regression test. See:
117 // http://code.google.com/p/chromium/issues/detail?id=53548
118 // Tests that --> is correctly interpreted as comment-to-end-of-line if there
119 // is only whitespace before it on the line (with comments considered as
120 // whitespace, even a multiline-comment containing a newline).
121 // This was not the case if it occurred before the first real token
122 // in the input.
123 const char* tests[] = {
124 // Before first real token.
125 "--> is eol-comment\nvar y = 37;\n",
126 "\n --> is eol-comment\nvar y = 37;\n",
127 "/* precomment */ --> is eol-comment\nvar y = 37;\n",
128 "\n/* precomment */ --> is eol-comment\nvar y = 37;\n",
129 // After first real token.
130 "var x = 42;\n--> is eol-comment\nvar y = 37;\n",
131 "var x = 42;\n/* precomment */ --> is eol-comment\nvar y = 37;\n",
132 NULL
133 };
134
135 const char* fail_tests[] = {
136 "x --> is eol-comment\nvar y = 37;\n",
137 "\"\\n\" --> is eol-comment\nvar y = 37;\n",
138 "x/* precomment */ --> is eol-comment\nvar y = 37;\n",
139 "x/* precomment\n */ --> is eol-comment\nvar y = 37;\n",
140 "var x = 42; --> is eol-comment\nvar y = 37;\n",
141 "var x = 42; /* precomment\n */ --> is eol-comment\nvar y = 37;\n",
142 NULL
143 };
144
145 // Parser/Scanner needs a stack limit.
146 CcTest::i_isolate()->stack_guard()->SetStackLimit(
147 i::GetCurrentStackPosition() - 128 * 1024);
148 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
149 for (int i = 0; tests[i]; i++) {
150 const i::byte* source =
151 reinterpret_cast<const i::byte*>(tests[i]);
152 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i]));
153 i::CompleteParserRecorder log;
154 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
155 scanner.Initialize(&stream);
156 i::Zone zone(CcTest::i_isolate()->allocator());
157 i::AstValueFactory ast_value_factory(
158 &zone, CcTest::i_isolate()->heap()->HashSeed());
159 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
160 stack_limit);
161 preparser.set_allow_lazy(true);
162 i::PreParser::PreParseResult result = preparser.PreParseProgram();
163 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
164 CHECK(!log.HasError());
165 }
166
167 for (int i = 0; fail_tests[i]; i++) {
168 const i::byte* source =
169 reinterpret_cast<const i::byte*>(fail_tests[i]);
170 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
171 i::CompleteParserRecorder log;
172 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
173 scanner.Initialize(&stream);
174 i::Zone zone(CcTest::i_isolate()->allocator());
175 i::AstValueFactory ast_value_factory(
176 &zone, CcTest::i_isolate()->heap()->HashSeed());
177 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
178 stack_limit);
179 preparser.set_allow_lazy(true);
180 i::PreParser::PreParseResult result = preparser.PreParseProgram();
181 // Even in the case of a syntax error, kPreParseSuccess is returned.
182 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
183 CHECK(log.HasError());
184 }
185 }
186
187
188 class ScriptResource : public v8::String::ExternalOneByteStringResource { 111 class ScriptResource : public v8::String::ExternalOneByteStringResource {
189 public: 112 public:
190 ScriptResource(const char* data, size_t length) 113 ScriptResource(const char* data, size_t length)
191 : data_(data), length_(length) { } 114 : data_(data), length_(length) { }
192 115
193 const char* data() const { return data_; } 116 const char* data() const { return data_; }
194 size_t length() const { return length_; } 117 size_t length() const { return length_; }
195 118
196 private: 119 private:
197 const char* data_; 120 const char* data_;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 }; 246 };
324 247
325 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 248 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
326 for (int i = 0; programs[i]; i++) { 249 for (int i = 0; programs[i]; i++) {
327 const char* program = programs[i]; 250 const char* program = programs[i];
328 i::Utf8ToUtf16CharacterStream stream( 251 i::Utf8ToUtf16CharacterStream stream(
329 reinterpret_cast<const i::byte*>(program), 252 reinterpret_cast<const i::byte*>(program),
330 static_cast<unsigned>(strlen(program))); 253 static_cast<unsigned>(strlen(program)));
331 i::CompleteParserRecorder log; 254 i::CompleteParserRecorder log;
332 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 255 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
333 scanner.Initialize(&stream); 256 scanner.Initialize(&stream, true);
334 257
335 i::Zone zone(CcTest::i_isolate()->allocator()); 258 i::Zone zone(CcTest::i_isolate()->allocator());
336 i::AstValueFactory ast_value_factory( 259 i::AstValueFactory ast_value_factory(
337 &zone, CcTest::i_isolate()->heap()->HashSeed()); 260 &zone, CcTest::i_isolate()->heap()->HashSeed());
338 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 261 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
339 stack_limit); 262 stack_limit);
340 preparser.set_allow_lazy(true); 263 preparser.set_allow_lazy(true);
341 preparser.set_allow_natives(true); 264 preparser.set_allow_natives(true);
342 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 265 i::PreParser::PreParseResult result = preparser.PreParseProgram();
343 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 266 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
(...skipping 15 matching lines...) Expand all
359 }; 282 };
360 283
361 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 284 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
362 for (int i = 0; programs[i]; i++) { 285 for (int i = 0; programs[i]; i++) {
363 const char* program = programs[i]; 286 const char* program = programs[i];
364 i::Utf8ToUtf16CharacterStream stream( 287 i::Utf8ToUtf16CharacterStream stream(
365 reinterpret_cast<const i::byte*>(program), 288 reinterpret_cast<const i::byte*>(program),
366 static_cast<unsigned>(strlen(program))); 289 static_cast<unsigned>(strlen(program)));
367 i::CompleteParserRecorder log; 290 i::CompleteParserRecorder log;
368 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 291 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
369 scanner.Initialize(&stream); 292 scanner.Initialize(&stream, true);
370 293
371 // Preparser defaults to disallowing natives syntax. 294 // Preparser defaults to disallowing natives syntax.
372 i::Zone zone(CcTest::i_isolate()->allocator()); 295 i::Zone zone(CcTest::i_isolate()->allocator());
373 i::AstValueFactory ast_value_factory( 296 i::AstValueFactory ast_value_factory(
374 &zone, CcTest::i_isolate()->heap()->HashSeed()); 297 &zone, CcTest::i_isolate()->heap()->HashSeed());
375 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 298 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
376 stack_limit); 299 stack_limit);
377 preparser.set_allow_lazy(true); 300 preparser.set_allow_lazy(true);
378 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 301 i::PreParser::PreParseResult result = preparser.PreParseProgram();
379 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 302 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // Fails parsing expecting an identifier after "function". 353 // Fails parsing expecting an identifier after "function".
431 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), 354 // Before fix, didn't check *ok after Expect(Token::Identifier, ok),
432 // and then used the invalid currently scanned literal. This always 355 // and then used the invalid currently scanned literal. This always
433 // failed in debug mode, and sometimes crashed in release mode. 356 // failed in debug mode, and sometimes crashed in release mode.
434 357
435 i::Utf8ToUtf16CharacterStream stream( 358 i::Utf8ToUtf16CharacterStream stream(
436 reinterpret_cast<const i::byte*>(program), 359 reinterpret_cast<const i::byte*>(program),
437 static_cast<unsigned>(strlen(program))); 360 static_cast<unsigned>(strlen(program)));
438 i::CompleteParserRecorder log; 361 i::CompleteParserRecorder log;
439 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 362 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
440 scanner.Initialize(&stream); 363 scanner.Initialize(&stream, true);
441 i::Zone zone(CcTest::i_isolate()->allocator()); 364 i::Zone zone(CcTest::i_isolate()->allocator());
442 i::AstValueFactory ast_value_factory(&zone, 365 i::AstValueFactory ast_value_factory(&zone,
443 CcTest::i_isolate()->heap()->HashSeed()); 366 CcTest::i_isolate()->heap()->HashSeed());
444 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 367 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
445 CcTest::i_isolate()->stack_guard()->real_climit()); 368 CcTest::i_isolate()->stack_guard()->real_climit());
446 preparser.set_allow_lazy(true); 369 preparser.set_allow_lazy(true);
447 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 370 i::PreParser::PreParseResult result = preparser.PreParseProgram();
448 // Even in the case of a syntax error, kPreParseSuccess is returned. 371 // Even in the case of a syntax error, kPreParseSuccess is returned.
449 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 372 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
450 CHECK(log.HasError()); 373 CHECK(log.HasError());
(...skipping 14 matching lines...) Expand all
465 388
466 const char* program = 389 const char* program =
467 "try { } catch (e) { var foo = function () { /* first */ } }" 390 "try { } catch (e) { var foo = function () { /* first */ } }"
468 "var bar = function () { /* second */ }"; 391 "var bar = function () { /* second */ }";
469 392
470 v8::HandleScope handles(CcTest::isolate()); 393 v8::HandleScope handles(CcTest::isolate());
471 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); 394 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program);
472 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 395 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
473 i::CompleteParserRecorder log; 396 i::CompleteParserRecorder log;
474 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 397 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
475 scanner.Initialize(&stream); 398 scanner.Initialize(&stream, true);
476 i::Zone zone(CcTest::i_isolate()->allocator()); 399 i::Zone zone(CcTest::i_isolate()->allocator());
477 i::AstValueFactory ast_value_factory(&zone, 400 i::AstValueFactory ast_value_factory(&zone,
478 CcTest::i_isolate()->heap()->HashSeed()); 401 CcTest::i_isolate()->heap()->HashSeed());
479 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 402 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
480 CcTest::i_isolate()->stack_guard()->real_climit()); 403 CcTest::i_isolate()->stack_guard()->real_climit());
481 preparser.set_allow_lazy(true); 404 preparser.set_allow_lazy(true);
482 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 405 i::PreParser::PreParseResult result = preparser.PreParseProgram();
483 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 406 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
484 i::ScriptData* sd = log.GetScriptData(); 407 i::ScriptData* sd = log.GetScriptData();
485 i::ParseData* pd = i::ParseData::FromCachedData(sd); 408 i::ParseData* pd = i::ParseData::FromCachedData(sd);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 memset(program.get(), '(', kProgramSize); 440 memset(program.get(), '(', kProgramSize);
518 program[kProgramSize] = '\0'; 441 program[kProgramSize] = '\0';
519 442
520 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 443 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
521 444
522 i::Utf8ToUtf16CharacterStream stream( 445 i::Utf8ToUtf16CharacterStream stream(
523 reinterpret_cast<const i::byte*>(program.get()), 446 reinterpret_cast<const i::byte*>(program.get()),
524 static_cast<unsigned>(kProgramSize)); 447 static_cast<unsigned>(kProgramSize));
525 i::CompleteParserRecorder log; 448 i::CompleteParserRecorder log;
526 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 449 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
527 scanner.Initialize(&stream); 450 scanner.Initialize(&stream, true);
528 451
529 i::Zone zone(CcTest::i_isolate()->allocator()); 452 i::Zone zone(CcTest::i_isolate()->allocator());
530 i::AstValueFactory ast_value_factory(&zone, 453 i::AstValueFactory ast_value_factory(&zone,
531 CcTest::i_isolate()->heap()->HashSeed()); 454 CcTest::i_isolate()->heap()->HashSeed());
532 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 455 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
533 stack_limit); 456 stack_limit);
534 preparser.set_allow_lazy(true); 457 preparser.set_allow_lazy(true);
535 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 458 i::PreParser::PreParseResult result = preparser.PreParseProgram();
536 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 459 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
537 } 460 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 } 670 }
748 } 671 }
749 672
750 #undef CHECK_EQU 673 #undef CHECK_EQU
751 674
752 void TestStreamScanner(i::Utf16CharacterStream* stream, 675 void TestStreamScanner(i::Utf16CharacterStream* stream,
753 i::Token::Value* expected_tokens, 676 i::Token::Value* expected_tokens,
754 int skip_pos = 0, // Zero means not skipping. 677 int skip_pos = 0, // Zero means not skipping.
755 int skip_to = 0) { 678 int skip_to = 0) {
756 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 679 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
757 scanner.Initialize(stream); 680 scanner.Initialize(stream, true);
758 681
759 int i = 0; 682 int i = 0;
760 do { 683 do {
761 i::Token::Value expected = expected_tokens[i]; 684 i::Token::Value expected = expected_tokens[i];
762 i::Token::Value actual = scanner.Next(); 685 i::Token::Value actual = scanner.Next();
763 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); 686 CHECK_EQ(i::Token::String(expected), i::Token::String(actual));
764 if (scanner.location().end_pos == skip_pos) { 687 if (scanner.location().end_pos == skip_pos) {
765 scanner.SeekForward(skip_to); 688 scanner.SeekForward(skip_to);
766 } 689 }
767 i++; 690 i++;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 } 753 }
831 } 754 }
832 755
833 756
834 void TestScanRegExp(const char* re_source, const char* expected) { 757 void TestScanRegExp(const char* re_source, const char* expected) {
835 i::Utf8ToUtf16CharacterStream stream( 758 i::Utf8ToUtf16CharacterStream stream(
836 reinterpret_cast<const i::byte*>(re_source), 759 reinterpret_cast<const i::byte*>(re_source),
837 static_cast<unsigned>(strlen(re_source))); 760 static_cast<unsigned>(strlen(re_source)));
838 i::HandleScope scope(CcTest::i_isolate()); 761 i::HandleScope scope(CcTest::i_isolate());
839 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 762 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
840 scanner.Initialize(&stream); 763 scanner.Initialize(&stream, true);
841 764
842 i::Token::Value start = scanner.peek(); 765 i::Token::Value start = scanner.peek();
843 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); 766 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV);
844 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); 767 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV));
845 scanner.Next(); // Current token is now the regexp literal. 768 scanner.Next(); // Current token is now the regexp literal.
846 i::Zone zone(CcTest::i_isolate()->allocator()); 769 i::Zone zone(CcTest::i_isolate()->allocator());
847 i::AstValueFactory ast_value_factory(&zone, 770 i::AstValueFactory ast_value_factory(&zone,
848 CcTest::i_isolate()->heap()->HashSeed()); 771 CcTest::i_isolate()->heap()->HashSeed());
849 ast_value_factory.Internalize(CcTest::i_isolate()); 772 ast_value_factory.Internalize(CcTest::i_isolate());
850 i::Handle<i::String> val = 773 i::Handle<i::String> val =
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 i::CompleteParserRecorder log; 1474 i::CompleteParserRecorder log;
1552 if (test_preparser) { 1475 if (test_preparser) {
1553 i::Scanner scanner(isolate->unicode_cache()); 1476 i::Scanner scanner(isolate->unicode_cache());
1554 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1477 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1555 i::Zone zone(CcTest::i_isolate()->allocator()); 1478 i::Zone zone(CcTest::i_isolate()->allocator());
1556 i::AstValueFactory ast_value_factory( 1479 i::AstValueFactory ast_value_factory(
1557 &zone, CcTest::i_isolate()->heap()->HashSeed()); 1480 &zone, CcTest::i_isolate()->heap()->HashSeed());
1558 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 1481 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
1559 stack_limit); 1482 stack_limit);
1560 SetParserFlags(&preparser, flags); 1483 SetParserFlags(&preparser, flags);
1561 scanner.Initialize(&stream); 1484 scanner.Initialize(&stream, !is_module);
1562 i::PreParser::PreParseResult result = 1485 i::PreParser::PreParseResult result =
1563 preparser.PreParseProgram(&preparser_materialized_literals, is_module); 1486 preparser.PreParseProgram(&preparser_materialized_literals, is_module);
1564 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1487 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1565 } 1488 }
1566 bool preparse_error = log.HasError(); 1489 bool preparse_error = log.HasError();
1567 1490
1568 // Parse the data 1491 // Parse the data
1569 i::FunctionLiteral* function; 1492 i::FunctionLiteral* function;
1570 { 1493 {
1571 i::Handle<i::Script> script = factory->NewScript(source); 1494 i::Handle<i::Script> script = factory->NewScript(source);
(...skipping 4101 matching lines...) Expand 10 before | Expand all | Expand 10 after
5673 5596
5674 i::Handle<i::Script> script = factory->NewScript(source); 5597 i::Handle<i::Script> script = factory->NewScript(source);
5675 i::Zone zone(CcTest::i_isolate()->allocator()); 5598 i::Zone zone(CcTest::i_isolate()->allocator());
5676 i::ParseInfo info(&zone, script); 5599 i::ParseInfo info(&zone, script);
5677 i::Parser parser(&info); 5600 i::Parser parser(&info);
5678 info.set_module(); 5601 info.set_module();
5679 CHECK(!parser.Parse(&info)); 5602 CHECK(!parser.Parse(&info));
5680 } 5603 }
5681 } 5604 }
5682 5605
5606 TEST(ScanHTMLEndComments) {
5607 v8::V8::Initialize();
5608 v8::Isolate* isolate = CcTest::isolate();
5609 v8::HandleScope handles(isolate);
5610
5611 // Regression test. See:
5612 // http://code.google.com/p/chromium/issues/detail?id=53548
5613 // Tests that --> is correctly interpreted as comment-to-end-of-line if there
5614 // is only whitespace before it on the line (with comments considered as
5615 // whitespace, even a multiline-comment containing a newline).
5616 // This was not the case if it occurred before the first real token
5617 // in the input.
5618 const char* tests[] = {
5619 // Before first real token.
5620 "--> is eol-comment\nvar y = 37;\n",
5621 "\n --> is eol-comment\nvar y = 37;\n",
5622 "/* precomment */ --> is eol-comment\nvar y = 37;\n",
5623 "\n/* precomment */ --> is eol-comment\nvar y = 37;\n",
5624 // After first real token.
5625 "var x = 42;\n--> is eol-comment\nvar y = 37;\n",
5626 "var x = 42;\n/* precomment */ --> is eol-comment\nvar y = 37;\n",
5627 NULL
5628 };
5629
5630 const char* fail_tests[] = {
5631 "x --> is eol-comment\nvar y = 37;\n",
5632 "\"\\n\" --> is eol-comment\nvar y = 37;\n",
5633 "x/* precomment */ --> is eol-comment\nvar y = 37;\n",
5634 "x/* precomment\n */ --> is eol-comment\nvar y = 37;\n",
5635 "var x = 42; --> is eol-comment\nvar y = 37;\n",
5636 "var x = 42; /* precomment\n */ --> is eol-comment\nvar y = 37;\n",
5637 NULL
5638 };
5639
5640 // Parser/Scanner needs a stack limit.
5641 CcTest::i_isolate()->stack_guard()->SetStackLimit(
5642 i::GetCurrentStackPosition() - 128 * 1024);
5643 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
5644 for (int i = 0; tests[i]; i++) {
5645 const i::byte* source =
5646 reinterpret_cast<const i::byte*>(tests[i]);
5647 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i]));
5648 i::CompleteParserRecorder log;
5649 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
5650 scanner.Initialize(&stream, true);
5651 i::Zone zone(CcTest::i_isolate()->allocator());
5652 i::AstValueFactory ast_value_factory(
5653 &zone, CcTest::i_isolate()->heap()->HashSeed());
5654 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
5655 stack_limit);
5656 preparser.set_allow_lazy(true);
5657 i::PreParser::PreParseResult result = preparser.PreParseProgram();
5658 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
5659 CHECK(!log.HasError());
5660 }
5661
5662 for (int i = 0; fail_tests[i]; i++) {
5663 const i::byte* source =
5664 reinterpret_cast<const i::byte*>(fail_tests[i]);
5665 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
5666 i::CompleteParserRecorder log;
5667 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
5668 scanner.Initialize(&stream, true);
5669 i::Zone zone(CcTest::i_isolate()->allocator());
5670 i::AstValueFactory ast_value_factory(
5671 &zone, CcTest::i_isolate()->heap()->HashSeed());
5672 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
5673 stack_limit);
5674 preparser.set_allow_lazy(true);
5675 i::PreParser::PreParseResult result = preparser.PreParseProgram();
5676 // Even in the case of a syntax error, kPreParseSuccess is returned.
5677 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
5678 CHECK(log.HasError());
5679 }
5680
5681 // ES2015 B.1.3 HTML-like Comments:
5682 //
5683 // > The syntax and semantics of 11.4 is extended as follows except that this
5684 // > extension is not allowed when parsing source code using the goal symbol
5685 // > Module
5686 const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
5687
5688 RunModuleParserSyncTest(context_data, tests, kError);
5689 RunModuleParserSyncTest(context_data, fail_tests, kError);
5690 }
5691
5683 TEST(ModuleTopLevelFunctionDecl) { 5692 TEST(ModuleTopLevelFunctionDecl) {
5684 // clang-format off 5693 // clang-format off
5685 const char* kErrorSources[] = { 5694 const char* kErrorSources[] = {
5686 "function f() {} function f() {}", 5695 "function f() {} function f() {}",
5687 "var f; function f() {}", 5696 "var f; function f() {}",
5688 "function f() {} var f;", 5697 "function f() {} var f;",
5689 "function* f() {} function* f() {}", 5698 "function* f() {} function* f() {}",
5690 "var f; function* f() {}", 5699 "var f; function* f() {}",
5691 "function* f() {} var f;", 5700 "function* f() {} var f;",
5692 "function f() {} function* f() {}", 5701 "function f() {} function* f() {}",
(...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after
7724 "for (const x = 0 in {});", 7733 "for (const x = 0 in {});",
7725 "for (let x = 0 in {});", 7734 "for (let x = 0 in {});",
7726 NULL 7735 NULL
7727 }; 7736 };
7728 // clang-format on 7737 // clang-format on
7729 7738
7730 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; 7739 static const ParserFlag always_flags[] = {kAllowHarmonyForIn};
7731 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, 7740 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags,
7732 arraysize(always_flags)); 7741 arraysize(always_flags));
7733 } 7742 }
OLDNEW
« 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