| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 i::GetCurrentStackPosition() - 128 * 1024); | 166 i::GetCurrentStackPosition() - 128 * 1024); |
| 167 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 167 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 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::PreParser preparser(&zone, &scanner, &ast_value_factory, stack_limit); | 176 i::PreParser preparser( |
| 177 &zone, &scanner, &ast_value_factory, |
| 178 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); |
| 177 preparser.set_allow_lazy(true); | 179 preparser.set_allow_lazy(true); |
| 178 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 180 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 179 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 181 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 180 CHECK(!preparser.logger()->has_error()); | 182 CHECK(!preparser.logger()->has_error()); |
| 181 } | 183 } |
| 182 | 184 |
| 183 for (int i = 0; fail_tests[i]; i++) { | 185 for (int i = 0; fail_tests[i]; i++) { |
| 184 const char* source = fail_tests[i]; | 186 const char* source = fail_tests[i]; |
| 185 auto stream = i::ScannerStream::ForTesting(source); | 187 auto stream = i::ScannerStream::ForTesting(source); |
| 186 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 188 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 187 scanner.Initialize(stream.get()); | 189 scanner.Initialize(stream.get()); |
| 188 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 190 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 189 i::AstValueFactory ast_value_factory( | 191 i::AstValueFactory ast_value_factory( |
| 190 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 192 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 191 i::PreParser preparser(&zone, &scanner, &ast_value_factory, stack_limit); | 193 i::PreParser preparser( |
| 194 &zone, &scanner, &ast_value_factory, |
| 195 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); |
| 192 preparser.set_allow_lazy(true); | 196 preparser.set_allow_lazy(true); |
| 193 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 197 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 194 // Even in the case of a syntax error, kPreParseSuccess is returned. | 198 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 195 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 199 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 196 CHECK(preparser.logger()->has_error()); | 200 CHECK(preparser.logger()->has_error()); |
| 197 } | 201 } |
| 198 } | 202 } |
| 199 | 203 |
| 200 | 204 |
| 201 class ScriptResource : public v8::String::ExternalOneByteStringResource { | 205 class ScriptResource : public v8::String::ExternalOneByteStringResource { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 357 |
| 354 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 358 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 355 for (int i = 0; programs[i]; i++) { | 359 for (int i = 0; programs[i]; i++) { |
| 356 auto stream = i::ScannerStream::ForTesting(programs[i]); | 360 auto stream = i::ScannerStream::ForTesting(programs[i]); |
| 357 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 361 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 358 scanner.Initialize(stream.get()); | 362 scanner.Initialize(stream.get()); |
| 359 | 363 |
| 360 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 364 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 361 i::AstValueFactory ast_value_factory( | 365 i::AstValueFactory ast_value_factory( |
| 362 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 366 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 363 i::PreParser preparser(&zone, &scanner, &ast_value_factory, stack_limit); | 367 i::PreParser preparser( |
| 368 &zone, &scanner, &ast_value_factory, |
| 369 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); |
| 364 preparser.set_allow_lazy(true); | 370 preparser.set_allow_lazy(true); |
| 365 preparser.set_allow_natives(true); | 371 preparser.set_allow_natives(true); |
| 366 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 372 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 367 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 373 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 368 CHECK(!preparser.logger()->has_error()); | 374 CHECK(!preparser.logger()->has_error()); |
| 369 } | 375 } |
| 370 } | 376 } |
| 371 | 377 |
| 372 | 378 |
| 373 TEST(StandAlonePreParserNoNatives) { | 379 TEST(StandAlonePreParserNoNatives) { |
| 374 v8::V8::Initialize(); | 380 v8::V8::Initialize(); |
| 375 | 381 |
| 382 i::Isolate* isolate = CcTest::i_isolate(); |
| 376 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 383 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 377 i::GetCurrentStackPosition() - 128 * 1024); | 384 i::GetCurrentStackPosition() - 128 * 1024); |
| 378 | 385 |
| 379 const char* programs[] = { | 386 const char* programs[] = { |
| 380 "%ArgleBargle(glop);", | 387 "%ArgleBargle(glop);", |
| 381 "var x = %_IsSmi(42);", | 388 "var x = %_IsSmi(42);", |
| 382 NULL | 389 NULL |
| 383 }; | 390 }; |
| 384 | 391 |
| 385 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 392 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| 386 for (int i = 0; programs[i]; i++) { | 393 for (int i = 0; programs[i]; i++) { |
| 387 auto stream = i::ScannerStream::ForTesting(programs[i]); | 394 auto stream = i::ScannerStream::ForTesting(programs[i]); |
| 388 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 395 i::Scanner scanner(isolate->unicode_cache()); |
| 389 scanner.Initialize(stream.get()); | 396 scanner.Initialize(stream.get()); |
| 390 | 397 |
| 391 // Preparser defaults to disallowing natives syntax. | 398 // Preparser defaults to disallowing natives syntax. |
| 392 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 399 i::Zone zone(isolate->allocator(), ZONE_NAME); |
| 393 i::AstValueFactory ast_value_factory( | 400 i::AstValueFactory ast_value_factory(&zone, isolate->heap()->HashSeed()); |
| 394 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 401 i::PreParser preparser(&zone, &scanner, &ast_value_factory, |
| 395 i::PreParser preparser(&zone, &scanner, &ast_value_factory, stack_limit); | 402 isolate->counters()->runtime_call_stats(), |
| 403 stack_limit); |
| 396 preparser.set_allow_lazy(true); | 404 preparser.set_allow_lazy(true); |
| 397 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 405 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 398 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 406 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 399 CHECK(preparser.logger()->has_error()); | 407 CHECK(preparser.logger()->has_error()); |
| 400 } | 408 } |
| 401 } | 409 } |
| 402 | 410 |
| 403 | 411 |
| 404 TEST(PreparsingObjectLiterals) { | 412 TEST(PreparsingObjectLiterals) { |
| 405 // Regression test for a bug where the symbol stream produced by PreParser | 413 // Regression test for a bug where the symbol stream produced by PreParser |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 // and then used the invalid currently scanned literal. This always | 459 // and then used the invalid currently scanned literal. This always |
| 452 // failed in debug mode, and sometimes crashed in release mode. | 460 // failed in debug mode, and sometimes crashed in release mode. |
| 453 | 461 |
| 454 auto stream = i::ScannerStream::ForTesting(program); | 462 auto stream = i::ScannerStream::ForTesting(program); |
| 455 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 463 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 456 scanner.Initialize(stream.get()); | 464 scanner.Initialize(stream.get()); |
| 457 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 465 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 458 i::AstValueFactory ast_value_factory(&zone, | 466 i::AstValueFactory ast_value_factory(&zone, |
| 459 CcTest::i_isolate()->heap()->HashSeed()); | 467 CcTest::i_isolate()->heap()->HashSeed()); |
| 460 i::PreParser preparser(&zone, &scanner, &ast_value_factory, | 468 i::PreParser preparser(&zone, &scanner, &ast_value_factory, |
| 469 isolate->counters()->runtime_call_stats(), |
| 461 CcTest::i_isolate()->stack_guard()->real_climit()); | 470 CcTest::i_isolate()->stack_guard()->real_climit()); |
| 462 preparser.set_allow_lazy(true); | 471 preparser.set_allow_lazy(true); |
| 463 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 472 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 464 // Even in the case of a syntax error, kPreParseSuccess is returned. | 473 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 465 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 474 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 466 CHECK(preparser.logger()->has_error()); | 475 CHECK(preparser.logger()->has_error()); |
| 467 } | 476 } |
| 468 | 477 |
| 469 | 478 |
| 470 TEST(Regress928) { | 479 TEST(Regress928) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 int second_lparen = second_function + i::StrLength("function "); | 514 int second_lparen = second_function + i::StrLength("function "); |
| 506 CHECK_EQ('(', program[second_lparen]); | 515 CHECK_EQ('(', program[second_lparen]); |
| 507 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lparen); | 516 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lparen); |
| 508 CHECK(entry2.is_valid()); | 517 CHECK(entry2.is_valid()); |
| 509 CHECK_EQ('}', program[entry2.end_pos() - 1]); | 518 CHECK_EQ('}', program[entry2.end_pos() - 1]); |
| 510 } | 519 } |
| 511 | 520 |
| 512 | 521 |
| 513 TEST(PreParseOverflow) { | 522 TEST(PreParseOverflow) { |
| 514 v8::V8::Initialize(); | 523 v8::V8::Initialize(); |
| 524 i::Isolate* isolate = CcTest::i_isolate(); |
| 515 | 525 |
| 516 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 526 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 517 i::GetCurrentStackPosition() - 128 * 1024); | 527 128 * 1024); |
| 518 | 528 |
| 519 size_t kProgramSize = 1024 * 1024; | 529 size_t kProgramSize = 1024 * 1024; |
| 520 std::unique_ptr<char[]> program(i::NewArray<char>(kProgramSize + 1)); | 530 std::unique_ptr<char[]> program(i::NewArray<char>(kProgramSize + 1)); |
| 521 memset(program.get(), '(', kProgramSize); | 531 memset(program.get(), '(', kProgramSize); |
| 522 program[kProgramSize] = '\0'; | 532 program[kProgramSize] = '\0'; |
| 523 | 533 |
| 524 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 534 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| 525 | 535 |
| 526 auto stream = i::ScannerStream::ForTesting(program.get(), kProgramSize); | 536 auto stream = i::ScannerStream::ForTesting(program.get(), kProgramSize); |
| 527 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 537 i::Scanner scanner(isolate->unicode_cache()); |
| 528 scanner.Initialize(stream.get()); | 538 scanner.Initialize(stream.get()); |
| 529 | 539 |
| 530 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 540 i::Zone zone(isolate->allocator(), ZONE_NAME); |
| 531 i::AstValueFactory ast_value_factory(&zone, | 541 i::AstValueFactory ast_value_factory(&zone, isolate->heap()->HashSeed()); |
| 532 CcTest::i_isolate()->heap()->HashSeed()); | 542 i::PreParser preparser(&zone, &scanner, &ast_value_factory, |
| 533 i::PreParser preparser(&zone, &scanner, &ast_value_factory, stack_limit); | 543 isolate->counters()->runtime_call_stats(), |
| 544 stack_limit); |
| 534 preparser.set_allow_lazy(true); | 545 preparser.set_allow_lazy(true); |
| 535 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 546 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 536 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); | 547 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); |
| 537 } | 548 } |
| 538 | 549 |
| 539 | 550 |
| 540 void TestStreamScanner(i::Utf16CharacterStream* stream, | 551 void TestStreamScanner(i::Utf16CharacterStream* stream, |
| 541 i::Token::Value* expected_tokens, | 552 i::Token::Value* expected_tokens, |
| 542 int skip_pos = 0, // Zero means not skipping. | 553 int skip_pos = 0, // Zero means not skipping. |
| 543 int skip_to = 0) { | 554 int skip_to = 0) { |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 | 1350 |
| 1340 // Preparse the data. | 1351 // Preparse the data. |
| 1341 i::ParserLogger log; | 1352 i::ParserLogger log; |
| 1342 if (test_preparser) { | 1353 if (test_preparser) { |
| 1343 i::Scanner scanner(isolate->unicode_cache()); | 1354 i::Scanner scanner(isolate->unicode_cache()); |
| 1344 std::unique_ptr<i::Utf16CharacterStream> stream( | 1355 std::unique_ptr<i::Utf16CharacterStream> stream( |
| 1345 i::ScannerStream::For(source)); | 1356 i::ScannerStream::For(source)); |
| 1346 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 1357 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 1347 i::AstValueFactory ast_value_factory( | 1358 i::AstValueFactory ast_value_factory( |
| 1348 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 1359 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 1349 i::PreParser preparser(&zone, &scanner, &ast_value_factory, stack_limit); | 1360 i::PreParser preparser(&zone, &scanner, &ast_value_factory, |
| 1361 isolate->counters()->runtime_call_stats(), |
| 1362 stack_limit); |
| 1350 SetParserFlags(&preparser, flags); | 1363 SetParserFlags(&preparser, flags); |
| 1351 scanner.Initialize(stream.get()); | 1364 scanner.Initialize(stream.get()); |
| 1352 i::PreParser::PreParseResult result = | 1365 i::PreParser::PreParseResult result = |
| 1353 preparser.PreParseProgram(&preparser_materialized_literals, is_module); | 1366 preparser.PreParseProgram(&preparser_materialized_literals, is_module); |
| 1354 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1367 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 1355 i::PreParserLogger* logger = preparser.logger(); | 1368 i::PreParserLogger* logger = preparser.logger(); |
| 1356 // Convert to complete log. | 1369 // Convert to complete log. |
| 1357 if (logger->has_error()) { | 1370 if (logger->has_error()) { |
| 1358 log.LogMessage(logger->start(), logger->end(), logger->message(), | 1371 log.LogMessage(logger->start(), logger->end(), logger->message(), |
| 1359 logger->argument_opt(), logger->error_type()); | 1372 logger->argument_opt(), logger->error_type()); |
| (...skipping 6963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8323 const char* data[] = { | 8336 const char* data[] = { |
| 8324 "const arguments = 1", | 8337 "const arguments = 1", |
| 8325 "let arguments", | 8338 "let arguments", |
| 8326 "var arguments", | 8339 "var arguments", |
| 8327 NULL | 8340 NULL |
| 8328 }; | 8341 }; |
| 8329 // clang-format on | 8342 // clang-format on |
| 8330 RunParserSyncTest(context_data, data, kSuccess); | 8343 RunParserSyncTest(context_data, data, kSuccess); |
| 8331 } | 8344 } |
| 8332 } | 8345 } |
| OLD | NEW |