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

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

Issue 24220003: Remove default isolate usage from almost all tests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 months 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 | Annotate | Revision Log
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 12426 matching lines...) Expand 10 before | Expand all | Expand 10 after
12437 void ApiTestFuzzer::TearDown() { 12437 void ApiTestFuzzer::TearDown() {
12438 fuzzing_ = false; 12438 fuzzing_ = false;
12439 for (int i = 0; i < RegisterThreadedTest::count(); i++) { 12439 for (int i = 0; i < RegisterThreadedTest::count(); i++) {
12440 ApiTestFuzzer *fuzzer = RegisterThreadedTest::nth(i)->fuzzer_; 12440 ApiTestFuzzer *fuzzer = RegisterThreadedTest::nth(i)->fuzzer_;
12441 if (fuzzer != NULL) fuzzer->Join(); 12441 if (fuzzer != NULL) fuzzer->Join();
12442 } 12442 }
12443 } 12443 }
12444 12444
12445 12445
12446 // Lets not be needlessly self-referential. 12446 // Lets not be needlessly self-referential.
12447 TEST(Threading1) { 12447 UNINITIALIZED_TEST(Threading1) {
12448 ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART); 12448 ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART);
12449 ApiTestFuzzer::RunAllTests(); 12449 ApiTestFuzzer::RunAllTests();
12450 ApiTestFuzzer::TearDown(); 12450 ApiTestFuzzer::TearDown();
12451 } 12451 }
12452 12452
12453 12453
12454 TEST(Threading2) { 12454 UNINITIALIZED_TEST(Threading2) {
12455 ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART); 12455 ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART);
12456 ApiTestFuzzer::RunAllTests(); 12456 ApiTestFuzzer::RunAllTests();
12457 ApiTestFuzzer::TearDown(); 12457 ApiTestFuzzer::TearDown();
12458 } 12458 }
12459 12459
12460 12460
12461 TEST(Threading3) { 12461 UNINITIALIZED_TEST(Threading3) {
12462 ApiTestFuzzer::SetUp(ApiTestFuzzer::THIRD_PART); 12462 ApiTestFuzzer::SetUp(ApiTestFuzzer::THIRD_PART);
12463 ApiTestFuzzer::RunAllTests(); 12463 ApiTestFuzzer::RunAllTests();
12464 ApiTestFuzzer::TearDown(); 12464 ApiTestFuzzer::TearDown();
12465 } 12465 }
12466 12466
12467 12467
12468 TEST(Threading4) { 12468 UNINITIALIZED_TEST(Threading4) {
12469 ApiTestFuzzer::SetUp(ApiTestFuzzer::FOURTH_PART); 12469 ApiTestFuzzer::SetUp(ApiTestFuzzer::FOURTH_PART);
12470 ApiTestFuzzer::RunAllTests(); 12470 ApiTestFuzzer::RunAllTests();
12471 ApiTestFuzzer::TearDown(); 12471 ApiTestFuzzer::TearDown();
12472 } 12472 }
12473 12473
12474 12474
12475 void ApiTestFuzzer::CallTest() { 12475 void ApiTestFuzzer::CallTest() {
12476 if (kLogThreading) 12476 if (kLogThreading)
12477 printf("Start test %d\n", test_number_); 12477 printf("Start test %d\n", test_number_);
12478 CallTestNumber(test_number_); 12478 CallTestNumber(test_number_);
(...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after
14305 i::Semaphore block_; 14305 i::Semaphore block_;
14306 int gc_count_; 14306 int gc_count_;
14307 int gc_during_regexp_; 14307 int gc_during_regexp_;
14308 bool regexp_success_; 14308 bool regexp_success_;
14309 bool gc_success_; 14309 bool gc_success_;
14310 }; 14310 };
14311 14311
14312 14312
14313 // Test that a regular expression execution can be interrupted and 14313 // Test that a regular expression execution can be interrupted and
14314 // survive a garbage collection. 14314 // survive a garbage collection.
14315 TEST(RegExpInterruption) { 14315 UNINITIALIZED_TEST(RegExpInterruption) {
14316 v8::Locker lock(CcTest::default_isolate()); 14316 v8::Locker lock(CcTest::default_isolate());
14317 v8::V8::Initialize(); 14317 v8::V8::Initialize();
14318 v8::HandleScope scope(CcTest::default_isolate()); 14318 v8::HandleScope scope(CcTest::default_isolate());
14319 Local<Context> local_env; 14319 Local<Context> local_env;
14320 { 14320 {
14321 LocalContext env; 14321 LocalContext env;
14322 local_env = env.local(); 14322 local_env = env.local();
14323 } 14323 }
14324 14324
14325 // Local context should still be live. 14325 // Local context should still be live.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
14413 i::Semaphore block_; 14413 i::Semaphore block_;
14414 int gc_count_; 14414 int gc_count_;
14415 int gc_during_apply_; 14415 int gc_during_apply_;
14416 bool apply_success_; 14416 bool apply_success_;
14417 bool gc_success_; 14417 bool gc_success_;
14418 }; 14418 };
14419 14419
14420 14420
14421 // Test that nothing bad happens if we get a preemption just when we were 14421 // Test that nothing bad happens if we get a preemption just when we were
14422 // about to do an apply(). 14422 // about to do an apply().
14423 TEST(ApplyInterruption) { 14423 UNINITIALIZED_TEST(ApplyInterruption) {
14424 v8::Locker lock(CcTest::default_isolate()); 14424 v8::Locker lock(CcTest::default_isolate());
14425 v8::V8::Initialize(); 14425 v8::V8::Initialize();
14426 v8::HandleScope scope(CcTest::default_isolate()); 14426 v8::HandleScope scope(CcTest::default_isolate());
14427 Local<Context> local_env; 14427 Local<Context> local_env;
14428 { 14428 {
14429 LocalContext env; 14429 LocalContext env;
14430 local_env = env.local(); 14430 local_env = env.local();
14431 } 14431 }
14432 14432
14433 // Local context should still be live. 14433 // Local context should still be live.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
14730 bool regexp_success_; 14730 bool regexp_success_;
14731 bool morph_success_; 14731 bool morph_success_;
14732 i::Handle<i::String> input_; 14732 i::Handle<i::String> input_;
14733 AsciiVectorResource ascii_resource_; 14733 AsciiVectorResource ascii_resource_;
14734 UC16VectorResource uc16_resource_; 14734 UC16VectorResource uc16_resource_;
14735 }; 14735 };
14736 14736
14737 14737
14738 // Test that a regular expression execution can be interrupted and 14738 // Test that a regular expression execution can be interrupted and
14739 // the string changed without failing. 14739 // the string changed without failing.
14740 TEST(RegExpStringModification) { 14740 UNINITIALIZED_TEST(RegExpStringModification) {
14741 v8::Locker lock(CcTest::default_isolate()); 14741 v8::Locker lock(CcTest::default_isolate());
14742 v8::V8::Initialize(); 14742 v8::V8::Initialize();
14743 v8::HandleScope scope(CcTest::default_isolate()); 14743 v8::HandleScope scope(CcTest::default_isolate());
14744 Local<Context> local_env; 14744 Local<Context> local_env;
14745 { 14745 {
14746 LocalContext env; 14746 LocalContext env;
14747 local_env = env.local(); 14747 local_env = env.local();
14748 } 14748 }
14749 14749
14750 // Local context should still be live. 14750 // Local context should still be live.
(...skipping 3439 matching lines...) Expand 10 before | Expand all | Expand 10 after
18190 CHECK_EQ(false, global0->HasRealIndexedProperty(0)); 18190 CHECK_EQ(false, global0->HasRealIndexedProperty(0));
18191 CHECK_EQ(false, global0->HasRealNamedProperty(v8_str("x"))); 18191 CHECK_EQ(false, global0->HasRealNamedProperty(v8_str("x")));
18192 CHECK_EQ(false, global0->HasRealNamedCallbackProperty(v8_str("x"))); 18192 CHECK_EQ(false, global0->HasRealNamedCallbackProperty(v8_str("x")));
18193 18193
18194 // Reset the failed access check callback so it does not influence 18194 // Reset the failed access check callback so it does not influence
18195 // the other tests. 18195 // the other tests.
18196 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); 18196 v8::V8::SetFailedAccessCheckCallbackFunction(NULL);
18197 } 18197 }
18198 18198
18199 18199
18200 TEST(DefaultIsolateGetCurrent) {
18201 CHECK(v8::Isolate::GetCurrent() != NULL);
18202 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18203 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
18204 printf("*** %s\n", "DefaultIsolateGetCurrent success");
18205 }
18206
18207
18208 TEST(IsolateNewDispose) { 18200 TEST(IsolateNewDispose) {
18209 v8::Isolate* current_isolate = v8::Isolate::GetCurrent(); 18201 v8::Isolate* current_isolate = v8::Isolate::GetCurrent();
18210 v8::Isolate* isolate = v8::Isolate::New(); 18202 v8::Isolate* isolate = v8::Isolate::New();
18211 CHECK(isolate != NULL); 18203 CHECK(isolate != NULL);
18212 CHECK(!reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate()); 18204 CHECK(!reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
18213 CHECK(current_isolate != isolate); 18205 CHECK(current_isolate != isolate);
18214 CHECK(current_isolate == v8::Isolate::GetCurrent()); 18206 CHECK(current_isolate == v8::Isolate::GetCurrent());
18215 18207
18216 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 18208 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18217 last_location = last_message = NULL; 18209 last_location = last_message = NULL;
18218 isolate->Dispose(); 18210 isolate->Dispose();
18219 CHECK_EQ(last_location, NULL); 18211 CHECK_EQ(last_location, NULL);
18220 CHECK_EQ(last_message, NULL); 18212 CHECK_EQ(last_message, NULL);
18221 } 18213 }
18222 18214
18223 18215
18224 TEST(IsolateEnterExitDefault) { 18216 UNINITIALIZED_TEST(DisposeIsolateWhenInUse) {
18225 v8::Isolate* current_isolate = v8::Isolate::GetCurrent();
18226 CHECK(current_isolate != NULL); // Default isolate.
18227 v8::HandleScope scope(current_isolate);
18228 LocalContext context;
18229 ExpectString("'hello'", "hello");
18230 current_isolate->Enter();
18231 ExpectString("'still working'", "still working");
18232 current_isolate->Exit();
18233 ExpectString("'still working 2'", "still working 2");
18234 current_isolate->Exit();
18235 // Default isolate is always, well, 'default current'.
18236 CHECK_EQ(v8::Isolate::GetCurrent(), current_isolate);
18237 // Still working since default isolate is auto-entering any thread
18238 // that has no isolate and attempts to execute V8 APIs.
18239 ExpectString("'still working 3'", "still working 3");
18240 }
18241
18242
18243 TEST(DisposeDefaultIsolate) {
18244 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18245
18246 // Run some V8 code to trigger default isolate to become 'current'.
18247 v8::HandleScope scope(v8::Isolate::GetCurrent());
18248 LocalContext context;
18249 ExpectString("'run some V8'", "run some V8");
18250
18251 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18252 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
18253 last_location = last_message = NULL;
18254 isolate->Dispose();
18255 // It is not possible to dispose default isolate via Isolate API.
18256 CHECK_NE(last_location, NULL);
18257 CHECK_NE(last_message, NULL);
18258 }
18259
18260
18261 TEST(RunDefaultAndAnotherIsolate) {
18262 v8::HandleScope scope(v8::Isolate::GetCurrent());
18263 LocalContext context;
18264
18265 // Enter new isolate.
18266 v8::Isolate* isolate = v8::Isolate::New(); 18217 v8::Isolate* isolate = v8::Isolate::New();
18267 CHECK(isolate); 18218 CHECK(isolate);
18268 isolate->Enter(); 18219 isolate->Enter();
18269 { // Need this block because subsequent Exit() will deallocate Heap,
18270 // so we need all scope objects to be deconstructed when it happens.
18271 v8::HandleScope scope_new(isolate);
18272 LocalContext context_new;
18273
18274 // Run something in new isolate.
18275 CompileRun("var foo = 153;");
18276 ExpectTrue("function f() { return foo == 153; }; f()");
18277 }
18278 isolate->Exit();
18279
18280 // This runs automatically in default isolate.
18281 // Variables in another isolate should be not available.
18282 ExpectTrue("function f() {"
18283 " try {"
18284 " foo;"
18285 " return false;"
18286 " } catch(e) {"
18287 " return true;"
18288 " }"
18289 "};"
18290 "var bar = 371;"
18291 "f()");
18292
18293 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18294 last_location = last_message = NULL;
18295 isolate->Dispose();
18296 CHECK_EQ(last_location, NULL);
18297 CHECK_EQ(last_message, NULL);
18298
18299 // Check that default isolate still runs.
18300 ExpectTrue("function f() { return bar == 371; }; f()");
18301 }
18302
18303
18304 TEST(DisposeIsolateWhenInUse) {
18305 v8::Isolate* isolate = v8::Isolate::New();
18306 CHECK(isolate);
18307 isolate->Enter();
18308 v8::HandleScope scope(isolate); 18220 v8::HandleScope scope(isolate);
18309 LocalContext context; 18221 LocalContext context;
18310 // Run something in this isolate. 18222 // Run something in this isolate.
18311 ExpectTrue("true"); 18223 ExpectTrue("true");
18312 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 18224 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
18313 last_location = last_message = NULL; 18225 last_location = last_message = NULL;
18314 // Still entered, should fail. 18226 // Still entered, should fail.
18315 isolate->Dispose(); 18227 isolate->Dispose();
18316 CHECK_NE(last_location, NULL); 18228 CHECK_NE(last_location, NULL);
18317 CHECK_NE(last_message, NULL); 18229 CHECK_NE(last_message, NULL);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
18541 SetCreateHistogramFunction, 18453 SetCreateHistogramFunction,
18542 SetAddHistogramSampleFunction 18454 SetAddHistogramSampleFunction
18543 }; 18455 };
18544 18456
18545 explicit InitDefaultIsolateThread(TestCase testCase) 18457 explicit InitDefaultIsolateThread(TestCase testCase)
18546 : Thread("InitDefaultIsolateThread"), 18458 : Thread("InitDefaultIsolateThread"),
18547 testCase_(testCase), 18459 testCase_(testCase),
18548 result_(false) { } 18460 result_(false) { }
18549 18461
18550 void Run() { 18462 void Run() {
18463 v8::Isolate* isolate = v8::Isolate::New();
18464 isolate->Enter();
18551 switch (testCase_) { 18465 switch (testCase_) {
18552 case IgnoreOOM: 18466 case IgnoreOOM:
18553 v8::V8::IgnoreOutOfMemoryException(); 18467 v8::V8::IgnoreOutOfMemoryException();
18554 break; 18468 break;
18555 18469
18556 case SetResourceConstraints: { 18470 case SetResourceConstraints: {
18557 static const int K = 1024; 18471 static const int K = 1024;
18558 v8::ResourceConstraints constraints; 18472 v8::ResourceConstraints constraints;
18559 constraints.set_max_young_space_size(256 * K); 18473 constraints.set_max_young_space_size(256 * K);
18560 constraints.set_max_old_space_size(4 * K * K); 18474 constraints.set_max_old_space_size(4 * K * K);
(...skipping 10 matching lines...) Expand all
18571 break; 18485 break;
18572 18486
18573 case SetCreateHistogramFunction: 18487 case SetCreateHistogramFunction:
18574 v8::V8::SetCreateHistogramFunction(NULL); 18488 v8::V8::SetCreateHistogramFunction(NULL);
18575 break; 18489 break;
18576 18490
18577 case SetAddHistogramSampleFunction: 18491 case SetAddHistogramSampleFunction:
18578 v8::V8::SetAddHistogramSampleFunction(NULL); 18492 v8::V8::SetAddHistogramSampleFunction(NULL);
18579 break; 18493 break;
18580 } 18494 }
18495 isolate->Exit();
18496 isolate->Dispose();
18581 result_ = true; 18497 result_ = true;
18582 } 18498 }
18583 18499
18584 bool result() { return result_; } 18500 bool result() { return result_; }
18585 18501
18586 private: 18502 private:
18587 TestCase testCase_; 18503 TestCase testCase_;
18588 bool result_; 18504 bool result_;
18589 }; 18505 };
18590 18506
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
19811 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value); 19727 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value);
19812 i::Handle<i::Object> true_value = factory->true_value(); 19728 i::Handle<i::Object> true_value = factory->true_value();
19813 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value); 19729 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value);
19814 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value); 19730 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value);
19815 i::Handle<i::Object> false_value = factory->false_value(); 19731 i::Handle<i::Object> false_value = factory->false_value();
19816 CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value); 19732 CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value);
19817 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value); 19733 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value);
19818 } 19734 }
19819 19735
19820 19736
19821 TEST(IsolateEmbedderData) { 19737 UNINITIALIZED_TEST(IsolateEmbedderData) {
19822 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 19738 v8::Isolate* isolate = v8::Isolate::GetCurrent();
19823 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 19739 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
19824 CHECK_EQ(NULL, isolate->GetData()); 19740 CHECK_EQ(NULL, isolate->GetData());
19825 CHECK_EQ(NULL, i_isolate->GetData()); 19741 CHECK_EQ(NULL, i_isolate->GetData());
19826 static void* data1 = reinterpret_cast<void*>(0xacce55ed); 19742 static void* data1 = reinterpret_cast<void*>(0xacce55ed);
19827 isolate->SetData(data1); 19743 isolate->SetData(data1);
19828 CHECK_EQ(data1, isolate->GetData()); 19744 CHECK_EQ(data1, isolate->GetData());
19829 CHECK_EQ(data1, i_isolate->GetData()); 19745 CHECK_EQ(data1, i_isolate->GetData());
19830 static void* data2 = reinterpret_cast<void*>(0xdecea5ed); 19746 static void* data2 = reinterpret_cast<void*>(0xdecea5ed);
19831 i_isolate->SetData(data2); 19747 i_isolate->SetData(data2);
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
20674 Local<Object> data2 = v8::Object::New(); 20590 Local<Object> data2 = v8::Object::New();
20675 function_new_expected_env = data2; 20591 function_new_expected_env = data2;
20676 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); 20592 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2);
20677 CHECK(!func2->IsNull()); 20593 CHECK(!func2->IsNull());
20678 CHECK_NE(func, func2); 20594 CHECK_NE(func, func2);
20679 env->Global()->Set(v8_str("func2"), func2); 20595 env->Global()->Set(v8_str("func2"), func2);
20680 Local<Value> result2 = CompileRun("func2();"); 20596 Local<Value> result2 = CompileRun("func2();");
20681 CHECK_EQ(v8::Integer::New(17, isolate), result2); 20597 CHECK_EQ(v8::Integer::New(17, isolate), result2);
20682 } 20598 }
20683 20599
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698