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 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2444 for (int i = 0; test_cases[i].program; i++) { | 2445 for (int i = 0; test_cases[i].program; i++) { |
2445 const char* program = test_cases[i].program; | 2446 const char* program = test_cases[i].program; |
2446 i::Factory* factory = CcTest::i_isolate()->factory(); | 2447 i::Factory* factory = CcTest::i_isolate()->factory(); |
2447 i::Handle<i::String> source = | 2448 i::Handle<i::String> source = |
2448 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2449 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
2449 i::Handle<i::Script> script = factory->NewScript(source); | 2450 i::Handle<i::Script> script = factory->NewScript(source); |
2450 i::CompilationInfoWithZone info(script); | 2451 i::CompilationInfoWithZone info(script); |
2451 i::ScriptData* sd = NULL; | 2452 i::ScriptData* sd = NULL; |
2452 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); | 2453 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); |
2453 i::Parser::Parse(&info, true); | 2454 i::Parser::Parse(&info, true); |
2454 i::ParseData pd(sd); | 2455 i::ParseData* pd = i::ParseData::FromCachedData(sd); |
2455 | 2456 |
2456 if (pd.FunctionCount() != test_cases[i].functions) { | 2457 if (pd->FunctionCount() != test_cases[i].functions) { |
2457 v8::base::OS::Print( | 2458 v8::base::OS::Print( |
2458 "Expected preparse data for program:\n" | 2459 "Expected preparse data for program:\n" |
2459 "\t%s\n" | 2460 "\t%s\n" |
2460 "to contain %d functions, however, received %d functions.\n", | 2461 "to contain %d functions, however, received %d functions.\n", |
2461 program, test_cases[i].functions, pd.FunctionCount()); | 2462 program, test_cases[i].functions, pd->FunctionCount()); |
2462 CHECK(false); | 2463 CHECK(false); |
2463 } | 2464 } |
2464 delete sd; | 2465 delete sd; |
| 2466 delete pd; |
2465 } | 2467 } |
2466 } | 2468 } |
2467 | 2469 |
2468 | 2470 |
2469 TEST(FunctionDeclaresItselfStrict) { | 2471 TEST(FunctionDeclaresItselfStrict) { |
2470 // Tests that we produce the right kinds of errors when a function declares | 2472 // Tests that we produce the right kinds of errors when a function declares |
2471 // itself strict (we cannot produce there errors as soon as we see the | 2473 // itself strict (we cannot produce there errors as soon as we see the |
2472 // offending identifiers, because we don't know at that point whether the | 2474 // offending identifiers, because we don't know at that point whether the |
2473 // function is strict or not). | 2475 // function is strict or not). |
2474 const char* context_data[][2] = { | 2476 const char* context_data[][2] = { |
(...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4311 const char* data[] = { | 4313 const char* data[] = { |
4312 "var foob\\u123r = 0;", | 4314 "var foob\\u123r = 0;", |
4313 "var \\u123roo = 0;", | 4315 "var \\u123roo = 0;", |
4314 "\"foob\\u123rr\"", | 4316 "\"foob\\u123rr\"", |
4315 // No escapes allowed in regexp flags | 4317 // No escapes allowed in regexp flags |
4316 "/regex/\\u0069g", | 4318 "/regex/\\u0069g", |
4317 "/regex/\\u006g", | 4319 "/regex/\\u006g", |
4318 NULL}; | 4320 NULL}; |
4319 RunParserSyncTest(context_data, data, kError); | 4321 RunParserSyncTest(context_data, data, kError); |
4320 } | 4322 } |
OLD | NEW |