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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 447 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
448 i::CompleteParserRecorder log; | 448 i::CompleteParserRecorder log; |
449 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 449 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
450 scanner.Initialize(&stream); | 450 scanner.Initialize(&stream); |
451 i::PreParser preparser(&scanner, &log, | 451 i::PreParser preparser(&scanner, &log, |
452 CcTest::i_isolate()->stack_guard()->real_climit()); | 452 CcTest::i_isolate()->stack_guard()->real_climit()); |
453 preparser.set_allow_lazy(true); | 453 preparser.set_allow_lazy(true); |
454 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 454 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
455 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 455 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
456 i::ScriptData* sd = log.GetScriptData(); | 456 i::ScriptData* sd = log.GetScriptData(); |
457 i::ParseData pd(sd); | 457 i::ParseData* pd = i::ParseData::FromCachedData(sd); |
458 pd.Initialize(); | 458 pd->Initialize(); |
459 | 459 |
460 int first_function = | 460 int first_function = |
461 static_cast<int>(strstr(program, "function") - program); | 461 static_cast<int>(strstr(program, "function") - program); |
462 int first_lbrace = first_function + i::StrLength("function () "); | 462 int first_lbrace = first_function + i::StrLength("function () "); |
463 CHECK_EQ('{', program[first_lbrace]); | 463 CHECK_EQ('{', program[first_lbrace]); |
464 i::FunctionEntry entry1 = pd.GetFunctionEntry(first_lbrace); | 464 i::FunctionEntry entry1 = pd->GetFunctionEntry(first_lbrace); |
465 CHECK(!entry1.is_valid()); | 465 CHECK(!entry1.is_valid()); |
466 | 466 |
467 int second_function = | 467 int second_function = |
468 static_cast<int>(strstr(program + first_lbrace, "function") - program); | 468 static_cast<int>(strstr(program + first_lbrace, "function") - program); |
469 int second_lbrace = | 469 int second_lbrace = |
470 second_function + i::StrLength("function () "); | 470 second_function + i::StrLength("function () "); |
471 CHECK_EQ('{', program[second_lbrace]); | 471 CHECK_EQ('{', program[second_lbrace]); |
472 i::FunctionEntry entry2 = pd.GetFunctionEntry(second_lbrace); | 472 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lbrace); |
473 CHECK(entry2.is_valid()); | 473 CHECK(entry2.is_valid()); |
474 CHECK_EQ('}', program[entry2.end_pos() - 1]); | 474 CHECK_EQ('}', program[entry2.end_pos() - 1]); |
475 delete sd; | 475 delete sd; |
| 476 delete pd; |
476 } | 477 } |
477 | 478 |
478 | 479 |
479 TEST(PreParseOverflow) { | 480 TEST(PreParseOverflow) { |
480 v8::V8::Initialize(); | 481 v8::V8::Initialize(); |
481 | 482 |
482 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 483 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
483 i::GetCurrentStackPosition() - 128 * 1024); | 484 i::GetCurrentStackPosition() - 128 * 1024); |
484 | 485 |
485 size_t kProgramSize = 1024 * 1024; | 486 size_t kProgramSize = 1024 * 1024; |
(...skipping 1961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2447 for (int i = 0; test_cases[i].program; i++) { | 2448 for (int i = 0; test_cases[i].program; i++) { |
2448 const char* program = test_cases[i].program; | 2449 const char* program = test_cases[i].program; |
2449 i::Factory* factory = CcTest::i_isolate()->factory(); | 2450 i::Factory* factory = CcTest::i_isolate()->factory(); |
2450 i::Handle<i::String> source = | 2451 i::Handle<i::String> source = |
2451 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2452 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
2452 i::Handle<i::Script> script = factory->NewScript(source); | 2453 i::Handle<i::Script> script = factory->NewScript(source); |
2453 i::CompilationInfoWithZone info(script); | 2454 i::CompilationInfoWithZone info(script); |
2454 i::ScriptData* sd = NULL; | 2455 i::ScriptData* sd = NULL; |
2455 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); | 2456 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); |
2456 i::Parser::Parse(&info, true); | 2457 i::Parser::Parse(&info, true); |
2457 i::ParseData pd(sd); | 2458 i::ParseData* pd = i::ParseData::FromCachedData(sd); |
2458 | 2459 |
2459 if (pd.FunctionCount() != test_cases[i].functions) { | 2460 if (pd->FunctionCount() != test_cases[i].functions) { |
2460 v8::base::OS::Print( | 2461 v8::base::OS::Print( |
2461 "Expected preparse data for program:\n" | 2462 "Expected preparse data for program:\n" |
2462 "\t%s\n" | 2463 "\t%s\n" |
2463 "to contain %d functions, however, received %d functions.\n", | 2464 "to contain %d functions, however, received %d functions.\n", |
2464 program, test_cases[i].functions, pd.FunctionCount()); | 2465 program, test_cases[i].functions, pd->FunctionCount()); |
2465 CHECK(false); | 2466 CHECK(false); |
2466 } | 2467 } |
2467 delete sd; | 2468 delete sd; |
| 2469 delete pd; |
2468 } | 2470 } |
2469 } | 2471 } |
2470 | 2472 |
2471 | 2473 |
2472 TEST(FunctionDeclaresItselfStrict) { | 2474 TEST(FunctionDeclaresItselfStrict) { |
2473 // Tests that we produce the right kinds of errors when a function declares | 2475 // Tests that we produce the right kinds of errors when a function declares |
2474 // itself strict (we cannot produce there errors as soon as we see the | 2476 // itself strict (we cannot produce there errors as soon as we see the |
2475 // offending identifiers, because we don't know at that point whether the | 2477 // offending identifiers, because we don't know at that point whether the |
2476 // function is strict or not). | 2478 // function is strict or not). |
2477 const char* context_data[][2] = { | 2479 const char* context_data[][2] = { |
(...skipping 1945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4423 "`foo${\n a`", | 4425 "`foo${\n a`", |
4424 "`foo${\r\n a`", | 4426 "`foo${\r\n a`", |
4425 "`foo${\r a`", | 4427 "`foo${\r a`", |
4426 "`foo${fn(}`", | 4428 "`foo${fn(}`", |
4427 "`foo${1 if}`", | 4429 "`foo${1 if}`", |
4428 NULL}; | 4430 NULL}; |
4429 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; | 4431 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
4430 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 4432 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
4431 arraysize(always_flags)); | 4433 arraysize(always_flags)); |
4432 } | 4434 } |
OLD | NEW |