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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 2506613002: Move allow_lazy from ParserBase to Parser and remove accessors (Closed)
Patch Set: fix Created 4 years, 1 month 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/parser-base.h ('k') | no next file » | 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 auto stream = i::ScannerStream::ForTesting(source); 170 auto stream = i::ScannerStream::ForTesting(source);
171 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 171 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
172 scanner.Initialize(stream.get()); 172 scanner.Initialize(stream.get());
173 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 173 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
174 i::AstValueFactory ast_value_factory( 174 i::AstValueFactory ast_value_factory(
175 &zone, CcTest::i_isolate()->heap()->HashSeed()); 175 &zone, CcTest::i_isolate()->heap()->HashSeed());
176 i::PendingCompilationErrorHandler pending_error_handler; 176 i::PendingCompilationErrorHandler pending_error_handler;
177 i::PreParser preparser( 177 i::PreParser preparser(
178 &zone, &scanner, &ast_value_factory, &pending_error_handler, 178 &zone, &scanner, &ast_value_factory, &pending_error_handler,
179 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); 179 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit);
180 preparser.set_allow_lazy(true);
181 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 180 i::PreParser::PreParseResult result = preparser.PreParseProgram();
182 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 181 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
183 CHECK(!pending_error_handler.has_pending_error()); 182 CHECK(!pending_error_handler.has_pending_error());
184 } 183 }
185 184
186 for (int i = 0; fail_tests[i]; i++) { 185 for (int i = 0; fail_tests[i]; i++) {
187 const char* source = fail_tests[i]; 186 const char* source = fail_tests[i];
188 auto stream = i::ScannerStream::ForTesting(source); 187 auto stream = i::ScannerStream::ForTesting(source);
189 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 188 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
190 scanner.Initialize(stream.get()); 189 scanner.Initialize(stream.get());
191 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 190 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
192 i::AstValueFactory ast_value_factory( 191 i::AstValueFactory ast_value_factory(
193 &zone, CcTest::i_isolate()->heap()->HashSeed()); 192 &zone, CcTest::i_isolate()->heap()->HashSeed());
194 i::PendingCompilationErrorHandler pending_error_handler; 193 i::PendingCompilationErrorHandler pending_error_handler;
195 i::PreParser preparser( 194 i::PreParser preparser(
196 &zone, &scanner, &ast_value_factory, &pending_error_handler, 195 &zone, &scanner, &ast_value_factory, &pending_error_handler,
197 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); 196 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit);
198 preparser.set_allow_lazy(true);
199 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 197 i::PreParser::PreParseResult result = preparser.PreParseProgram();
200 // Even in the case of a syntax error, kPreParseSuccess is returned. 198 // Even in the case of a syntax error, kPreParseSuccess is returned.
201 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 199 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
202 CHECK(pending_error_handler.has_pending_error()); 200 CHECK(pending_error_handler.has_pending_error());
203 } 201 }
204 } 202 }
205 203
206 204
207 class ScriptResource : public v8::String::ExternalOneByteStringResource { 205 class ScriptResource : public v8::String::ExternalOneByteStringResource {
208 public: 206 public:
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 361 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
364 scanner.Initialize(stream.get()); 362 scanner.Initialize(stream.get());
365 363
366 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 364 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
367 i::AstValueFactory ast_value_factory( 365 i::AstValueFactory ast_value_factory(
368 &zone, CcTest::i_isolate()->heap()->HashSeed()); 366 &zone, CcTest::i_isolate()->heap()->HashSeed());
369 i::PendingCompilationErrorHandler pending_error_handler; 367 i::PendingCompilationErrorHandler pending_error_handler;
370 i::PreParser preparser( 368 i::PreParser preparser(
371 &zone, &scanner, &ast_value_factory, &pending_error_handler, 369 &zone, &scanner, &ast_value_factory, &pending_error_handler,
372 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); 370 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit);
373 preparser.set_allow_lazy(true);
374 preparser.set_allow_natives(true); 371 preparser.set_allow_natives(true);
375 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 372 i::PreParser::PreParseResult result = preparser.PreParseProgram();
376 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 373 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
377 CHECK(!pending_error_handler.has_pending_error()); 374 CHECK(!pending_error_handler.has_pending_error());
378 } 375 }
379 } 376 }
380 377
381 378
382 TEST(StandAlonePreParserNoNatives) { 379 TEST(StandAlonePreParserNoNatives) {
383 v8::V8::Initialize(); 380 v8::V8::Initialize();
(...skipping 15 matching lines...) Expand all
399 scanner.Initialize(stream.get()); 396 scanner.Initialize(stream.get());
400 397
401 // Preparser defaults to disallowing natives syntax. 398 // Preparser defaults to disallowing natives syntax.
402 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 399 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
403 i::AstValueFactory ast_value_factory( 400 i::AstValueFactory ast_value_factory(
404 &zone, CcTest::i_isolate()->heap()->HashSeed()); 401 &zone, CcTest::i_isolate()->heap()->HashSeed());
405 i::PendingCompilationErrorHandler pending_error_handler; 402 i::PendingCompilationErrorHandler pending_error_handler;
406 i::PreParser preparser( 403 i::PreParser preparser(
407 &zone, &scanner, &ast_value_factory, &pending_error_handler, 404 &zone, &scanner, &ast_value_factory, &pending_error_handler,
408 isolate->counters()->runtime_call_stats(), stack_limit); 405 isolate->counters()->runtime_call_stats(), stack_limit);
409 preparser.set_allow_lazy(true);
410 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 406 i::PreParser::PreParseResult result = preparser.PreParseProgram();
411 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 407 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
412 CHECK(pending_error_handler.has_pending_error()); 408 CHECK(pending_error_handler.has_pending_error());
413 } 409 }
414 } 410 }
415 411
416 412
417 TEST(PreparsingObjectLiterals) { 413 TEST(PreparsingObjectLiterals) {
418 // Regression test for a bug where the symbol stream produced by PreParser 414 // Regression test for a bug where the symbol stream produced by PreParser
419 // didn't match what Parser wanted to consume. 415 // didn't match what Parser wanted to consume.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 464 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
469 scanner.Initialize(stream.get()); 465 scanner.Initialize(stream.get());
470 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 466 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
471 i::AstValueFactory ast_value_factory(&zone, 467 i::AstValueFactory ast_value_factory(&zone,
472 CcTest::i_isolate()->heap()->HashSeed()); 468 CcTest::i_isolate()->heap()->HashSeed());
473 i::PendingCompilationErrorHandler pending_error_handler; 469 i::PendingCompilationErrorHandler pending_error_handler;
474 i::PreParser preparser(&zone, &scanner, &ast_value_factory, 470 i::PreParser preparser(&zone, &scanner, &ast_value_factory,
475 &pending_error_handler, 471 &pending_error_handler,
476 isolate->counters()->runtime_call_stats(), 472 isolate->counters()->runtime_call_stats(),
477 CcTest::i_isolate()->stack_guard()->real_climit()); 473 CcTest::i_isolate()->stack_guard()->real_climit());
478 preparser.set_allow_lazy(true);
479 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 474 i::PreParser::PreParseResult result = preparser.PreParseProgram();
480 // Even in the case of a syntax error, kPreParseSuccess is returned. 475 // Even in the case of a syntax error, kPreParseSuccess is returned.
481 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 476 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
482 CHECK(pending_error_handler.has_pending_error()); 477 CHECK(pending_error_handler.has_pending_error());
483 } 478 }
484 479
485 480
486 TEST(Regress928) { 481 TEST(Regress928) {
487 // Test only applies when lazy parsing. 482 // Test only applies when lazy parsing.
488 if (!i::FLAG_lazy) return; 483 if (!i::FLAG_lazy) return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 i::Scanner scanner(isolate->unicode_cache()); 539 i::Scanner scanner(isolate->unicode_cache());
545 scanner.Initialize(stream.get()); 540 scanner.Initialize(stream.get());
546 541
547 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 542 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
548 i::AstValueFactory ast_value_factory(&zone, 543 i::AstValueFactory ast_value_factory(&zone,
549 CcTest::i_isolate()->heap()->HashSeed()); 544 CcTest::i_isolate()->heap()->HashSeed());
550 i::PendingCompilationErrorHandler pending_error_handler; 545 i::PendingCompilationErrorHandler pending_error_handler;
551 i::PreParser preparser( 546 i::PreParser preparser(
552 &zone, &scanner, &ast_value_factory, &pending_error_handler, 547 &zone, &scanner, &ast_value_factory, &pending_error_handler,
553 isolate->counters()->runtime_call_stats(), stack_limit); 548 isolate->counters()->runtime_call_stats(), stack_limit);
554 preparser.set_allow_lazy(true);
555 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 549 i::PreParser::PreParseResult result = preparser.PreParseProgram();
556 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 550 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
557 } 551 }
558 552
559 553
560 void TestStreamScanner(i::Utf16CharacterStream* stream, 554 void TestStreamScanner(i::Utf16CharacterStream* stream,
561 i::Token::Value* expected_tokens, 555 i::Token::Value* expected_tokens,
562 int skip_pos = 0, // Zero means not skipping. 556 int skip_pos = 0, // Zero means not skipping.
563 int skip_to = 0) { 557 int skip_to = 0) {
564 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 558 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 source_data[i].outer_suffix); 1167 source_data[i].outer_suffix);
1174 1168
1175 // Parse program source. 1169 // Parse program source.
1176 i::Handle<i::String> source = factory->NewStringFromUtf8( 1170 i::Handle<i::String> source = factory->NewStringFromUtf8(
1177 i::CStrVector(program.start())).ToHandleChecked(); 1171 i::CStrVector(program.start())).ToHandleChecked();
1178 CHECK_EQ(source->length(), kProgramSize); 1172 CHECK_EQ(source->length(), kProgramSize);
1179 i::Handle<i::Script> script = factory->NewScript(source); 1173 i::Handle<i::Script> script = factory->NewScript(source);
1180 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 1174 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1181 i::ParseInfo info(&zone, script); 1175 i::ParseInfo info(&zone, script);
1182 i::Parser parser(&info); 1176 i::Parser parser(&info);
1183 parser.set_allow_lazy(true);
1184 info.set_language_mode(source_data[i].language_mode); 1177 info.set_language_mode(source_data[i].language_mode);
1178 info.set_allow_lazy_parsing();
1185 parser.Parse(&info); 1179 parser.Parse(&info);
1186 CHECK(info.literal() != NULL); 1180 CHECK_NOT_NULL(info.literal());
1187 1181
1188 // Check scope types and positions. 1182 // Check scope types and positions.
1189 i::Scope* scope = info.literal()->scope(); 1183 i::Scope* scope = info.literal()->scope();
1190 CHECK(scope->is_script_scope()); 1184 CHECK(scope->is_script_scope());
1191 CHECK_EQ(scope->start_position(), 0); 1185 CHECK_EQ(scope->start_position(), 0);
1192 CHECK_EQ(scope->end_position(), kProgramSize); 1186 CHECK_EQ(scope->end_position(), kProgramSize);
1193 1187
1194 i::Scope* inner_scope = scope->inner_scope(); 1188 i::Scope* inner_scope = scope->inner_scope();
1195 DCHECK_NOT_NULL(inner_scope); 1189 DCHECK_NOT_NULL(inner_scope);
1196 DCHECK_NULL(inner_scope->sibling()); 1190 DCHECK_NULL(inner_scope->sibling());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 1285
1292 enum ParserSyncTestResult { 1286 enum ParserSyncTestResult {
1293 kSuccessOrError, 1287 kSuccessOrError,
1294 kSuccess, 1288 kSuccess,
1295 kError 1289 kError
1296 }; 1290 };
1297 1291
1298 template <typename Traits> 1292 template <typename Traits>
1299 void SetParserFlags(i::ParserBase<Traits>* parser, 1293 void SetParserFlags(i::ParserBase<Traits>* parser,
1300 i::EnumSet<ParserFlag> flags) { 1294 i::EnumSet<ParserFlag> flags) {
1301 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1302 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1295 parser->set_allow_natives(flags.Contains(kAllowNatives));
1303 parser->set_allow_harmony_function_sent( 1296 parser->set_allow_harmony_function_sent(
1304 flags.Contains(kAllowHarmonyFunctionSent)); 1297 flags.Contains(kAllowHarmonyFunctionSent));
1305 parser->set_allow_harmony_async_await( 1298 parser->set_allow_harmony_async_await(
1306 flags.Contains(kAllowHarmonyAsyncAwait)); 1299 flags.Contains(kAllowHarmonyAsyncAwait));
1307 parser->set_allow_harmony_restrictive_generators( 1300 parser->set_allow_harmony_restrictive_generators(
1308 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1301 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1309 parser->set_allow_harmony_trailing_commas( 1302 parser->set_allow_harmony_trailing_commas(
1310 flags.Contains(kAllowHarmonyTrailingCommas)); 1303 flags.Contains(kAllowHarmonyTrailingCommas));
1311 parser->set_allow_harmony_class_fields( 1304 parser->set_allow_harmony_class_fields(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 preparser.PreParseProgram(&preparser_materialized_literals, is_module); 1336 preparser.PreParseProgram(&preparser_materialized_literals, is_module);
1344 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1337 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1345 } 1338 }
1346 1339
1347 // Parse the data 1340 // Parse the data
1348 i::FunctionLiteral* function; 1341 i::FunctionLiteral* function;
1349 { 1342 {
1350 i::Handle<i::Script> script = factory->NewScript(source); 1343 i::Handle<i::Script> script = factory->NewScript(source);
1351 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 1344 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1352 i::ParseInfo info(&zone, script); 1345 i::ParseInfo info(&zone, script);
1346 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy));
1353 i::Parser parser(&info); 1347 i::Parser parser(&info);
1354 SetParserFlags(&parser, flags); 1348 SetParserFlags(&parser, flags);
1355 if (is_module) info.set_module(); 1349 if (is_module) info.set_module();
1356 parser.Parse(&info); 1350 parser.Parse(&info);
1357 function = info.literal(); 1351 function = info.literal();
1358 if (function) { 1352 if (function) {
1359 parser_materialized_literals = function->materialized_literal_count(); 1353 parser_materialized_literals = function->materialized_literal_count();
1360 } 1354 }
1361 } 1355 }
1362 1356
(...skipping 6945 matching lines...) Expand 10 before | Expand all | Expand 10 after
8308 const char* data[] = { 8302 const char* data[] = {
8309 "const arguments = 1", 8303 "const arguments = 1",
8310 "let arguments", 8304 "let arguments",
8311 "var arguments", 8305 "var arguments",
8312 NULL 8306 NULL
8313 }; 8307 };
8314 // clang-format on 8308 // clang-format on
8315 RunParserSyncTest(context_data, data, kSuccess); 8309 RunParserSyncTest(context_data, data, kSuccess);
8316 } 8310 }
8317 } 8311 }
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698