OLD | NEW |
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
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 5475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
| 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); |
| 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 Loading... |
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 } |
OLD | NEW |