Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(720)

Side by Side Diff: test/cctest/test-api.cc

Issue 781203003: Handle invalid parser cache gracefully (move invalid cache handling to embedder). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: streaminglining the test Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 24361 matching lines...) Expand 10 before | Expand all | Expand 10 after
24372 isolate, &source, v8::ScriptCompiler::kProduceParserCache); 24372 isolate, &source, v8::ScriptCompiler::kProduceParserCache);
24373 24373
24374 // TestSourceStream::GetMoreData won't block, so it's OK to just run the 24374 // TestSourceStream::GetMoreData won't block, so it's OK to just run the
24375 // task here in the main thread. 24375 // task here in the main thread.
24376 task->Run(); 24376 task->Run();
24377 delete task; 24377 delete task;
24378 24378
24379 const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData(); 24379 const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData();
24380 CHECK(cached_data != NULL); 24380 CHECK(cached_data != NULL);
24381 CHECK(cached_data->data != NULL); 24381 CHECK(cached_data->data != NULL);
24382 CHECK(!cached_data->rejected);
24382 CHECK_GT(cached_data->length, 0); 24383 CHECK_GT(cached_data->length, 0);
24383 } 24384 }
24384 24385
24385 24386
24386 TEST(StreamingScriptWithInvalidUtf8) { 24387 TEST(StreamingScriptWithInvalidUtf8) {
24387 // Regression test for a crash: test that invalid UTF-8 bytes in the end of a 24388 // Regression test for a crash: test that invalid UTF-8 bytes in the end of a
24388 // chunk don't produce a crash. 24389 // chunk don't produce a crash.
24389 const char* reference = "\xec\x92\x81\x80\x80"; 24390 const char* reference = "\xec\x92\x81\x80\x80";
24390 char chunk1[] = 24391 char chunk1[] =
24391 "function foo() {\n" 24392 "function foo() {\n"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
24463 24464
24464 TEST(InvalidCacheData) { 24465 TEST(InvalidCacheData) {
24465 v8::V8::Initialize(); 24466 v8::V8::Initialize();
24466 v8::HandleScope scope(CcTest::isolate()); 24467 v8::HandleScope scope(CcTest::isolate());
24467 LocalContext context; 24468 LocalContext context;
24468 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); 24469 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache);
24469 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); 24470 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache);
24470 } 24471 }
24471 24472
24472 24473
24474 TEST(ParserCacheRejectedGracefully) {
24475 i::FLAG_min_preparse_length = 0;
24476 v8::V8::Initialize();
24477 v8::HandleScope scope(CcTest::isolate());
24478 LocalContext context;
24479 // Produce valid cached data.
24480 v8::ScriptOrigin origin(v8_str("origin"));
24481 v8::Local<v8::String> source_str = v8_str("function foo() {}");
24482 v8::ScriptCompiler::Source source(source_str, origin);
24483 v8::Handle<v8::Script> script = v8::ScriptCompiler::Compile(
24484 CcTest::isolate(), &source, v8::ScriptCompiler::kProduceParserCache);
24485 CHECK(!script.IsEmpty());
24486 const v8::ScriptCompiler::CachedData* original_cached_data =
24487 source.GetCachedData();
24488 CHECK(original_cached_data != NULL);
24489 CHECK(original_cached_data->data != NULL);
24490 CHECK(!original_cached_data->rejected);
24491 CHECK_GT(original_cached_data->length, 0);
24492 // Recompiling the same script with it won't reject the data.
24493 {
24494 v8::ScriptCompiler::Source source_with_cached_data(
24495 source_str, origin,
24496 new v8::ScriptCompiler::CachedData(original_cached_data->data,
24497 original_cached_data->length));
24498 v8::Handle<v8::Script> script =
24499 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data,
24500 v8::ScriptCompiler::kConsumeParserCache);
24501 CHECK(!script.IsEmpty());
24502 const v8::ScriptCompiler::CachedData* new_cached_data =
24503 source_with_cached_data.GetCachedData();
24504 CHECK(new_cached_data != NULL);
24505 CHECK(!new_cached_data->rejected);
24506 }
24507 // Compile an incompatible script with the cached data. The new script doesn't
24508 // have the same starting position for the function as the old one, so the old
24509 // cached data will be incompatible with it and will be rejected.
24510 {
24511 v8::Local<v8::String> incompatible_source_str =
24512 v8_str(" function foo() {}");
24513 v8::ScriptCompiler::Source source_with_cached_data(
24514 incompatible_source_str, origin,
24515 new v8::ScriptCompiler::CachedData(original_cached_data->data,
24516 original_cached_data->length));
24517 v8::Handle<v8::Script> script =
24518 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data,
24519 v8::ScriptCompiler::kConsumeParserCache);
24520 CHECK(!script.IsEmpty());
24521 const v8::ScriptCompiler::CachedData* new_cached_data =
24522 source_with_cached_data.GetCachedData();
24523 CHECK(new_cached_data != NULL);
24524 CHECK(new_cached_data->rejected);
24525 }
24526 }
24527
24528
24473 TEST(StringConcatOverflow) { 24529 TEST(StringConcatOverflow) {
24474 v8::V8::Initialize(); 24530 v8::V8::Initialize();
24475 v8::HandleScope scope(CcTest::isolate()); 24531 v8::HandleScope scope(CcTest::isolate());
24476 RandomLengthOneByteResource* r = 24532 RandomLengthOneByteResource* r =
24477 new RandomLengthOneByteResource(i::String::kMaxLength); 24533 new RandomLengthOneByteResource(i::String::kMaxLength);
24478 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); 24534 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r);
24479 CHECK(!str.IsEmpty()); 24535 CHECK(!str.IsEmpty());
24480 v8::TryCatch try_catch; 24536 v8::TryCatch try_catch;
24481 v8::Local<v8::String> result = v8::String::Concat(str, str); 24537 v8::Local<v8::String> result = v8::String::Concat(str, str);
24482 CHECK(result.IsEmpty()); 24538 CHECK(result.IsEmpty());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
24564 24620
24565 v8::Handle<v8::Value> result = CompileRun("%_GetPrototype(object)"); 24621 v8::Handle<v8::Value> result = CompileRun("%_GetPrototype(object)");
24566 CHECK(result->Equals(proto2)); 24622 CHECK(result->Equals(proto2));
24567 24623
24568 result = CompileRun( 24624 result = CompileRun(
24569 "function f() { return %_GetPrototype(object); }" 24625 "function f() { return %_GetPrototype(object); }"
24570 "%OptimizeFunctionOnNextCall(f);" 24626 "%OptimizeFunctionOnNextCall(f);"
24571 "f()"); 24627 "f()");
24572 CHECK(result->Equals(proto2)); 24628 CHECK(result->Equals(proto2));
24573 } 24629 }
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698