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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::PendingCompilationErrorHandler pending_error_handler; | 176 i::PendingCompilationErrorHandler pending_error_handler; |
177 i::PreParser preparser(&zone, &scanner, &ast_value_factory, | 177 i::PreParser preparser( |
178 &pending_error_handler, stack_limit); | 178 &zone, &scanner, &ast_value_factory, &pending_error_handler, |
| 179 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); |
179 preparser.set_allow_lazy(true); | 180 preparser.set_allow_lazy(true); |
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(&zone, &scanner, &ast_value_factory, | 195 i::PreParser preparser( |
195 &pending_error_handler, stack_limit); | 196 &zone, &scanner, &ast_value_factory, &pending_error_handler, |
| 197 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); |
196 preparser.set_allow_lazy(true); | 198 preparser.set_allow_lazy(true); |
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 { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 360 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
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(&zone, &scanner, &ast_value_factory, | 370 i::PreParser preparser( |
369 &pending_error_handler, stack_limit); | 371 &zone, &scanner, &ast_value_factory, &pending_error_handler, |
| 372 CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit); |
370 preparser.set_allow_lazy(true); | 373 preparser.set_allow_lazy(true); |
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(); |
381 | 384 |
| 385 i::Isolate* isolate = CcTest::i_isolate(); |
382 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 386 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
383 i::GetCurrentStackPosition() - 128 * 1024); | 387 i::GetCurrentStackPosition() - 128 * 1024); |
384 | 388 |
385 const char* programs[] = { | 389 const char* programs[] = { |
386 "%ArgleBargle(glop);", | 390 "%ArgleBargle(glop);", |
387 "var x = %_IsSmi(42);", | 391 "var x = %_IsSmi(42);", |
388 NULL | 392 NULL |
389 }; | 393 }; |
390 | 394 |
391 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 395 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
392 for (int i = 0; programs[i]; i++) { | 396 for (int i = 0; programs[i]; i++) { |
393 auto stream = i::ScannerStream::ForTesting(programs[i]); | 397 auto stream = i::ScannerStream::ForTesting(programs[i]); |
394 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 398 i::Scanner scanner(isolate->unicode_cache()); |
395 scanner.Initialize(stream.get()); | 399 scanner.Initialize(stream.get()); |
396 | 400 |
397 // Preparser defaults to disallowing natives syntax. | 401 // Preparser defaults to disallowing natives syntax. |
398 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 402 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
399 i::AstValueFactory ast_value_factory( | 403 i::AstValueFactory ast_value_factory( |
400 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 404 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
401 i::PendingCompilationErrorHandler pending_error_handler; | 405 i::PendingCompilationErrorHandler pending_error_handler; |
402 i::PreParser preparser(&zone, &scanner, &ast_value_factory, | 406 i::PreParser preparser( |
403 &pending_error_handler, stack_limit); | 407 &zone, &scanner, &ast_value_factory, &pending_error_handler, |
| 408 isolate->counters()->runtime_call_stats(), stack_limit); |
404 preparser.set_allow_lazy(true); | 409 preparser.set_allow_lazy(true); |
405 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 410 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
406 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 411 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
407 CHECK(pending_error_handler.has_pending_error()); | 412 CHECK(pending_error_handler.has_pending_error()); |
408 } | 413 } |
409 } | 414 } |
410 | 415 |
411 | 416 |
412 TEST(PreparsingObjectLiterals) { | 417 TEST(PreparsingObjectLiterals) { |
413 // Regression test for a bug where the symbol stream produced by PreParser | 418 // Regression test for a bug where the symbol stream produced by PreParser |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 466 |
462 auto stream = i::ScannerStream::ForTesting(program); | 467 auto stream = i::ScannerStream::ForTesting(program); |
463 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 468 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
464 scanner.Initialize(stream.get()); | 469 scanner.Initialize(stream.get()); |
465 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 470 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
466 i::AstValueFactory ast_value_factory(&zone, | 471 i::AstValueFactory ast_value_factory(&zone, |
467 CcTest::i_isolate()->heap()->HashSeed()); | 472 CcTest::i_isolate()->heap()->HashSeed()); |
468 i::PendingCompilationErrorHandler pending_error_handler; | 473 i::PendingCompilationErrorHandler pending_error_handler; |
469 i::PreParser preparser(&zone, &scanner, &ast_value_factory, | 474 i::PreParser preparser(&zone, &scanner, &ast_value_factory, |
470 &pending_error_handler, | 475 &pending_error_handler, |
| 476 isolate->counters()->runtime_call_stats(), |
471 CcTest::i_isolate()->stack_guard()->real_climit()); | 477 CcTest::i_isolate()->stack_guard()->real_climit()); |
472 preparser.set_allow_lazy(true); | 478 preparser.set_allow_lazy(true); |
473 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 479 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
474 // Even in the case of a syntax error, kPreParseSuccess is returned. | 480 // Even in the case of a syntax error, kPreParseSuccess is returned. |
475 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 481 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
476 CHECK(pending_error_handler.has_pending_error()); | 482 CHECK(pending_error_handler.has_pending_error()); |
477 } | 483 } |
478 | 484 |
479 | 485 |
480 TEST(Regress928) { | 486 TEST(Regress928) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 int second_lparen = second_function + i::StrLength("function "); | 521 int second_lparen = second_function + i::StrLength("function "); |
516 CHECK_EQ('(', program[second_lparen]); | 522 CHECK_EQ('(', program[second_lparen]); |
517 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lparen); | 523 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lparen); |
518 CHECK(entry2.is_valid()); | 524 CHECK(entry2.is_valid()); |
519 CHECK_EQ('}', program[entry2.end_pos() - 1]); | 525 CHECK_EQ('}', program[entry2.end_pos() - 1]); |
520 } | 526 } |
521 | 527 |
522 | 528 |
523 TEST(PreParseOverflow) { | 529 TEST(PreParseOverflow) { |
524 v8::V8::Initialize(); | 530 v8::V8::Initialize(); |
| 531 i::Isolate* isolate = CcTest::i_isolate(); |
525 | 532 |
526 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 533 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
527 i::GetCurrentStackPosition() - 128 * 1024); | 534 128 * 1024); |
528 | 535 |
529 size_t kProgramSize = 1024 * 1024; | 536 size_t kProgramSize = 1024 * 1024; |
530 std::unique_ptr<char[]> program(i::NewArray<char>(kProgramSize + 1)); | 537 std::unique_ptr<char[]> program(i::NewArray<char>(kProgramSize + 1)); |
531 memset(program.get(), '(', kProgramSize); | 538 memset(program.get(), '(', kProgramSize); |
532 program[kProgramSize] = '\0'; | 539 program[kProgramSize] = '\0'; |
533 | 540 |
534 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 541 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
535 | 542 |
536 auto stream = i::ScannerStream::ForTesting(program.get(), kProgramSize); | 543 auto stream = i::ScannerStream::ForTesting(program.get(), kProgramSize); |
537 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 544 i::Scanner scanner(isolate->unicode_cache()); |
538 scanner.Initialize(stream.get()); | 545 scanner.Initialize(stream.get()); |
539 | 546 |
540 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 547 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
541 i::AstValueFactory ast_value_factory(&zone, | 548 i::AstValueFactory ast_value_factory(&zone, |
542 CcTest::i_isolate()->heap()->HashSeed()); | 549 CcTest::i_isolate()->heap()->HashSeed()); |
543 i::PendingCompilationErrorHandler pending_error_handler; | 550 i::PendingCompilationErrorHandler pending_error_handler; |
544 i::PreParser preparser(&zone, &scanner, &ast_value_factory, | 551 i::PreParser preparser( |
545 &pending_error_handler, stack_limit); | 552 &zone, &scanner, &ast_value_factory, &pending_error_handler, |
| 553 isolate->counters()->runtime_call_stats(), stack_limit); |
546 preparser.set_allow_lazy(true); | 554 preparser.set_allow_lazy(true); |
547 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 555 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
548 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); | 556 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); |
549 } | 557 } |
550 | 558 |
551 | 559 |
552 void TestStreamScanner(i::Utf16CharacterStream* stream, | 560 void TestStreamScanner(i::Utf16CharacterStream* stream, |
553 i::Token::Value* expected_tokens, | 561 i::Token::Value* expected_tokens, |
554 int skip_pos = 0, // Zero means not skipping. | 562 int skip_pos = 0, // Zero means not skipping. |
555 int skip_to = 0) { | 563 int skip_to = 0) { |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 | 1338 |
1331 // Preparse the data. | 1339 // Preparse the data. |
1332 i::PendingCompilationErrorHandler pending_error_handler; | 1340 i::PendingCompilationErrorHandler pending_error_handler; |
1333 if (test_preparser) { | 1341 if (test_preparser) { |
1334 i::Scanner scanner(isolate->unicode_cache()); | 1342 i::Scanner scanner(isolate->unicode_cache()); |
1335 std::unique_ptr<i::Utf16CharacterStream> stream( | 1343 std::unique_ptr<i::Utf16CharacterStream> stream( |
1336 i::ScannerStream::For(source)); | 1344 i::ScannerStream::For(source)); |
1337 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); | 1345 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
1338 i::AstValueFactory ast_value_factory( | 1346 i::AstValueFactory ast_value_factory( |
1339 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 1347 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
1340 i::PreParser preparser(&zone, &scanner, &ast_value_factory, | 1348 i::PreParser preparser( |
1341 &pending_error_handler, stack_limit); | 1349 &zone, &scanner, &ast_value_factory, &pending_error_handler, |
| 1350 isolate->counters()->runtime_call_stats(), stack_limit); |
1342 SetParserFlags(&preparser, flags); | 1351 SetParserFlags(&preparser, flags); |
1343 scanner.Initialize(stream.get()); | 1352 scanner.Initialize(stream.get()); |
1344 i::PreParser::PreParseResult result = | 1353 i::PreParser::PreParseResult result = |
1345 preparser.PreParseProgram(&preparser_materialized_literals, is_module); | 1354 preparser.PreParseProgram(&preparser_materialized_literals, is_module); |
1346 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1355 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
1347 } | 1356 } |
1348 | 1357 |
1349 // Parse the data | 1358 // Parse the data |
1350 i::FunctionLiteral* function; | 1359 i::FunctionLiteral* function; |
1351 { | 1360 { |
(...skipping 6958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8310 const char* data[] = { | 8319 const char* data[] = { |
8311 "const arguments = 1", | 8320 "const arguments = 1", |
8312 "let arguments", | 8321 "let arguments", |
8313 "var arguments", | 8322 "var arguments", |
8314 NULL | 8323 NULL |
8315 }; | 8324 }; |
8316 // clang-format on | 8325 // clang-format on |
8317 RunParserSyncTest(context_data, data, kSuccess); | 8326 RunParserSyncTest(context_data, data, kSuccess); |
8318 } | 8327 } |
8319 } | 8328 } |
OLD | NEW |