| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 for (int i = 0; tests[i]; i++) { | 168 for (int i = 0; tests[i]; i++) { |
| 169 const char* source = tests[i]; | 169 const char* source = tests[i]; |
| 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, stack_limit, &ast_value_factory, |
| 179 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); | 179 &pending_error_handler, |
| 180 CcTest::i_isolate()->counters()->runtime_call_stats()); |
| 180 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 181 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 181 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 182 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 182 CHECK(!pending_error_handler.has_pending_error()); | 183 CHECK(!pending_error_handler.has_pending_error()); |
| 183 } | 184 } |
| 184 | 185 |
| 185 for (int i = 0; fail_tests[i]; i++) { | 186 for (int i = 0; fail_tests[i]; i++) { |
| 186 const char* source = fail_tests[i]; | 187 const char* source = fail_tests[i]; |
| 187 auto stream = i::ScannerStream::ForTesting(source); | 188 auto stream = i::ScannerStream::ForTesting(source); |
| 188 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 189 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 189 scanner.Initialize(stream.get()); | 190 scanner.Initialize(stream.get()); |
| 190 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 191 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 191 i::AstValueFactory ast_value_factory( | 192 i::AstValueFactory ast_value_factory( |
| 192 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 193 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 193 i::PendingCompilationErrorHandler pending_error_handler; | 194 i::PendingCompilationErrorHandler pending_error_handler; |
| 194 i::PreParser preparser( | 195 i::PreParser preparser( |
| 195 &zone, &scanner, &ast_value_factory, &pending_error_handler, | 196 &zone, &scanner, stack_limit, &ast_value_factory, |
| 196 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); | 197 &pending_error_handler, |
| 198 CcTest::i_isolate()->counters()->runtime_call_stats()); |
| 197 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 199 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 198 // Even in the case of a syntax error, kPreParseSuccess is returned. | 200 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 199 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 201 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 200 CHECK(pending_error_handler.has_pending_error()); | 202 CHECK(pending_error_handler.has_pending_error()); |
| 201 } | 203 } |
| 202 } | 204 } |
| 203 | 205 |
| 204 | 206 |
| 205 class ScriptResource : public v8::String::ExternalOneByteStringResource { | 207 class ScriptResource : public v8::String::ExternalOneByteStringResource { |
| 206 public: | 208 public: |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 for (int i = 0; programs[i]; i++) { | 361 for (int i = 0; programs[i]; i++) { |
| 360 auto stream = i::ScannerStream::ForTesting(programs[i]); | 362 auto stream = i::ScannerStream::ForTesting(programs[i]); |
| 361 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 363 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 362 scanner.Initialize(stream.get()); | 364 scanner.Initialize(stream.get()); |
| 363 | 365 |
| 364 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 366 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 365 i::AstValueFactory ast_value_factory( | 367 i::AstValueFactory ast_value_factory( |
| 366 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 368 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 367 i::PendingCompilationErrorHandler pending_error_handler; | 369 i::PendingCompilationErrorHandler pending_error_handler; |
| 368 i::PreParser preparser( | 370 i::PreParser preparser( |
| 369 &zone, &scanner, &ast_value_factory, &pending_error_handler, | 371 &zone, &scanner, stack_limit, &ast_value_factory, |
| 370 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); | 372 &pending_error_handler, |
| 373 CcTest::i_isolate()->counters()->runtime_call_stats()); |
| 371 preparser.set_allow_natives(true); | 374 preparser.set_allow_natives(true); |
| 372 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 375 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 373 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 376 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 374 CHECK(!pending_error_handler.has_pending_error()); | 377 CHECK(!pending_error_handler.has_pending_error()); |
| 375 } | 378 } |
| 376 } | 379 } |
| 377 | 380 |
| 378 | 381 |
| 379 TEST(StandAlonePreParserNoNatives) { | 382 TEST(StandAlonePreParserNoNatives) { |
| 380 v8::V8::Initialize(); | 383 v8::V8::Initialize(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 393 for (int i = 0; programs[i]; i++) { | 396 for (int i = 0; programs[i]; i++) { |
| 394 auto stream = i::ScannerStream::ForTesting(programs[i]); | 397 auto stream = i::ScannerStream::ForTesting(programs[i]); |
| 395 i::Scanner scanner(isolate->unicode_cache()); | 398 i::Scanner scanner(isolate->unicode_cache()); |
| 396 scanner.Initialize(stream.get()); | 399 scanner.Initialize(stream.get()); |
| 397 | 400 |
| 398 // Preparser defaults to disallowing natives syntax. | 401 // Preparser defaults to disallowing natives syntax. |
| 399 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 402 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 400 i::AstValueFactory ast_value_factory( | 403 i::AstValueFactory ast_value_factory( |
| 401 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 404 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 402 i::PendingCompilationErrorHandler pending_error_handler; | 405 i::PendingCompilationErrorHandler pending_error_handler; |
| 403 i::PreParser preparser( | 406 i::PreParser preparser(&zone, &scanner, stack_limit, &ast_value_factory, |
| 404 &zone, &scanner, &ast_value_factory, &pending_error_handler, | 407 &pending_error_handler, |
| 405 isolate->counters()->runtime_call_stats(), stack_limit); | 408 isolate->counters()->runtime_call_stats()); |
| 406 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 409 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 407 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 410 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 408 CHECK(pending_error_handler.has_pending_error()); | 411 CHECK(pending_error_handler.has_pending_error()); |
| 409 } | 412 } |
| 410 } | 413 } |
| 411 | 414 |
| 412 | 415 |
| 413 TEST(PreparsingObjectLiterals) { | 416 TEST(PreparsingObjectLiterals) { |
| 414 // Regression test for a bug where the symbol stream produced by PreParser | 417 // Regression test for a bug where the symbol stream produced by PreParser |
| 415 // didn't match what Parser wanted to consume. | 418 // didn't match what Parser wanted to consume. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // and then used the invalid currently scanned literal. This always | 463 // and then used the invalid currently scanned literal. This always |
| 461 // failed in debug mode, and sometimes crashed in release mode. | 464 // failed in debug mode, and sometimes crashed in release mode. |
| 462 | 465 |
| 463 auto stream = i::ScannerStream::ForTesting(program); | 466 auto stream = i::ScannerStream::ForTesting(program); |
| 464 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 467 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 465 scanner.Initialize(stream.get()); | 468 scanner.Initialize(stream.get()); |
| 466 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 469 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 467 i::AstValueFactory ast_value_factory(&zone, | 470 i::AstValueFactory ast_value_factory(&zone, |
| 468 CcTest::i_isolate()->heap()->HashSeed()); | 471 CcTest::i_isolate()->heap()->HashSeed()); |
| 469 i::PendingCompilationErrorHandler pending_error_handler; | 472 i::PendingCompilationErrorHandler pending_error_handler; |
| 470 i::PreParser preparser(&zone, &scanner, &ast_value_factory, | 473 i::PreParser preparser(&zone, &scanner, |
| 471 &pending_error_handler, | 474 CcTest::i_isolate()->stack_guard()->real_climit(), |
| 472 isolate->counters()->runtime_call_stats(), | 475 &ast_value_factory, &pending_error_handler, |
| 473 CcTest::i_isolate()->stack_guard()->real_climit()); | 476 isolate->counters()->runtime_call_stats()); |
| 474 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 477 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 475 // Even in the case of a syntax error, kPreParseSuccess is returned. | 478 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 476 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 479 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 477 CHECK(pending_error_handler.has_pending_error()); | 480 CHECK(pending_error_handler.has_pending_error()); |
| 478 } | 481 } |
| 479 | 482 |
| 480 | 483 |
| 481 TEST(Regress928) { | 484 TEST(Regress928) { |
| 482 // Test only applies when lazy parsing. | 485 // Test only applies when lazy parsing. |
| 483 if (!i::FLAG_lazy) return; | 486 if (!i::FLAG_lazy) return; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 539 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| 537 | 540 |
| 538 auto stream = i::ScannerStream::ForTesting(program.get(), kProgramSize); | 541 auto stream = i::ScannerStream::ForTesting(program.get(), kProgramSize); |
| 539 i::Scanner scanner(isolate->unicode_cache()); | 542 i::Scanner scanner(isolate->unicode_cache()); |
| 540 scanner.Initialize(stream.get()); | 543 scanner.Initialize(stream.get()); |
| 541 | 544 |
| 542 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 545 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 543 i::AstValueFactory ast_value_factory(&zone, | 546 i::AstValueFactory ast_value_factory(&zone, |
| 544 CcTest::i_isolate()->heap()->HashSeed()); | 547 CcTest::i_isolate()->heap()->HashSeed()); |
| 545 i::PendingCompilationErrorHandler pending_error_handler; | 548 i::PendingCompilationErrorHandler pending_error_handler; |
| 546 i::PreParser preparser( | 549 i::PreParser preparser(&zone, &scanner, stack_limit, &ast_value_factory, |
| 547 &zone, &scanner, &ast_value_factory, &pending_error_handler, | 550 &pending_error_handler, |
| 548 isolate->counters()->runtime_call_stats(), stack_limit); | 551 isolate->counters()->runtime_call_stats()); |
| 549 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 552 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 550 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); | 553 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); |
| 551 } | 554 } |
| 552 | 555 |
| 553 | 556 |
| 554 void TestStreamScanner(i::Utf16CharacterStream* stream, | 557 void TestStreamScanner(i::Utf16CharacterStream* stream, |
| 555 i::Token::Value* expected_tokens, | 558 i::Token::Value* expected_tokens, |
| 556 int skip_pos = 0, // Zero means not skipping. | 559 int skip_pos = 0, // Zero means not skipping. |
| 557 int skip_to = 0) { | 560 int skip_to = 0) { |
| 558 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 561 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 | 1323 |
| 1321 // Preparse the data. | 1324 // Preparse the data. |
| 1322 i::PendingCompilationErrorHandler pending_error_handler; | 1325 i::PendingCompilationErrorHandler pending_error_handler; |
| 1323 if (test_preparser) { | 1326 if (test_preparser) { |
| 1324 i::Scanner scanner(isolate->unicode_cache()); | 1327 i::Scanner scanner(isolate->unicode_cache()); |
| 1325 std::unique_ptr<i::Utf16CharacterStream> stream( | 1328 std::unique_ptr<i::Utf16CharacterStream> stream( |
| 1326 i::ScannerStream::For(source)); | 1329 i::ScannerStream::For(source)); |
| 1327 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 1330 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 1328 i::AstValueFactory ast_value_factory( | 1331 i::AstValueFactory ast_value_factory( |
| 1329 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 1332 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 1330 i::PreParser preparser( | 1333 i::PreParser preparser(&zone, &scanner, stack_limit, &ast_value_factory, |
| 1331 &zone, &scanner, &ast_value_factory, &pending_error_handler, | 1334 &pending_error_handler, |
| 1332 isolate->counters()->runtime_call_stats(), stack_limit); | 1335 isolate->counters()->runtime_call_stats()); |
| 1333 SetParserFlags(&preparser, flags); | 1336 SetParserFlags(&preparser, flags); |
| 1334 scanner.Initialize(stream.get()); | 1337 scanner.Initialize(stream.get()); |
| 1335 i::PreParser::PreParseResult result = | 1338 i::PreParser::PreParseResult result = |
| 1336 preparser.PreParseProgram(&preparser_materialized_literals, is_module); | 1339 preparser.PreParseProgram(&preparser_materialized_literals, is_module); |
| 1337 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1340 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 1338 } | 1341 } |
| 1339 | 1342 |
| 1340 // Parse the data | 1343 // Parse the data |
| 1341 i::FunctionLiteral* function; | 1344 i::FunctionLiteral* function; |
| 1342 { | 1345 { |
| (...skipping 6959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8302 const char* data[] = { | 8305 const char* data[] = { |
| 8303 "const arguments = 1", | 8306 "const arguments = 1", |
| 8304 "let arguments", | 8307 "let arguments", |
| 8305 "var arguments", | 8308 "var arguments", |
| 8306 NULL | 8309 NULL |
| 8307 }; | 8310 }; |
| 8308 // clang-format on | 8311 // clang-format on |
| 8309 RunParserSyncTest(context_data, data, kSuccess); | 8312 RunParserSyncTest(context_data, data, kSuccess); |
| 8310 } | 8313 } |
| 8311 } | 8314 } |
| OLD | NEW |