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

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

Issue 11360082: Pass Isolate to MakeWeak(), IsWeak(), and AddObjectGroup(). (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 8 years, 1 month 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/api.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 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 LocalContext env; 2362 LocalContext env;
2363 2363
2364 WeakCallCounter counter(1234); 2364 WeakCallCounter counter(1234);
2365 2365
2366 Persistent<Object> g1s1; 2366 Persistent<Object> g1s1;
2367 Persistent<Object> g1s2; 2367 Persistent<Object> g1s2;
2368 Persistent<Object> g2s1; 2368 Persistent<Object> g2s1;
2369 Persistent<Object> g2s2; 2369 Persistent<Object> g2s2;
2370 Persistent<Object> g3s1; 2370 Persistent<Object> g3s1;
2371 Persistent<Object> g3s2; 2371 Persistent<Object> g3s2;
2372 Persistent<Object> g4s1;
2373 Persistent<Object> g4s2;
2372 2374
2375 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2373 { 2376 {
2374 HandleScope scope; 2377 HandleScope scope;
2375 g1s1 = Persistent<Object>::New(Object::New()); 2378 g1s1 = Persistent<Object>::New(Object::New());
2376 g1s2 = Persistent<Object>::New(Object::New()); 2379 g1s2 = Persistent<Object>::New(Object::New());
2377 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2380 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2378 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2381 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2382 CHECK(g1s1.IsWeak());
2383 CHECK(g1s2.IsWeak());
2379 2384
2380 g2s1 = Persistent<Object>::New(Object::New()); 2385 g2s1 = Persistent<Object>::New(Object::New());
2381 g2s2 = Persistent<Object>::New(Object::New()); 2386 g2s2 = Persistent<Object>::New(Object::New());
2382 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2387 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2383 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2388 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2389 CHECK(g2s1.IsWeak());
2390 CHECK(g2s2.IsWeak());
2384 2391
2385 g3s1 = Persistent<Object>::New(Object::New()); 2392 g3s1 = Persistent<Object>::New(Object::New());
2386 g3s2 = Persistent<Object>::New(Object::New()); 2393 g3s2 = Persistent<Object>::New(Object::New());
2387 g3s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2394 g3s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2388 g3s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2395 g3s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2396 CHECK(g3s1.IsWeak());
2397 CHECK(g3s2.IsWeak());
2398
2399 g4s1 = Persistent<Object>::New(Object::New());
2400 g4s2 = Persistent<Object>::New(Object::New());
2401 g4s1.MakeWeak(isolate,
2402 reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2403 g4s2.MakeWeak(isolate,
2404 reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2405 CHECK(g4s1.IsWeak(isolate));
2406 CHECK(g4s2.IsWeak(isolate));
2389 } 2407 }
2390 2408
2391 Persistent<Object> root = Persistent<Object>::New(g1s1); // make a root. 2409 Persistent<Object> root = Persistent<Object>::New(g1s1); // make a root.
2392 2410
2393 // Connect groups. We're building the following cycle: 2411 // Connect groups. We're building the following cycle:
2394 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other 2412 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
2395 // groups. 2413 // groups.
2396 { 2414 {
2397 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2415 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2398 Persistent<Value> g1_children[] = { g2s1 }; 2416 Persistent<Value> g1_children[] = { g2s1 };
2399 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2417 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2400 Persistent<Value> g2_children[] = { g3s1 }; 2418 Persistent<Value> g2_children[] = { g3s1 };
2401 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; 2419 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2402 Persistent<Value> g3_children[] = { g1s1 }; 2420 Persistent<Value> g3_children[] = { g4s1 };
2421 Persistent<Value> g4_objects[] = { g4s1, g4s2 };
2422 Persistent<Value> g4_children[] = { g1s1 };
2403 V8::AddObjectGroup(g1_objects, 2); 2423 V8::AddObjectGroup(g1_objects, 2);
2404 V8::AddImplicitReferences(g1s1, g1_children, 1); 2424 V8::AddImplicitReferences(g1s1, g1_children, 1);
2405 V8::AddObjectGroup(g2_objects, 2); 2425 V8::AddObjectGroup(g2_objects, 2);
2406 V8::AddImplicitReferences(g2s1, g2_children, 1); 2426 V8::AddImplicitReferences(g2s1, g2_children, 1);
2407 V8::AddObjectGroup(g3_objects, 2); 2427 V8::AddObjectGroup(g3_objects, 2);
2408 V8::AddImplicitReferences(g3s1, g3_children, 1); 2428 V8::AddImplicitReferences(g3s1, g3_children, 1);
2429 V8::AddObjectGroup(isolate, g4_objects, 2);
2430 V8::AddImplicitReferences(g4s1, g4_children, 1);
2409 } 2431 }
2410 // Do a single full GC 2432 // Do a single full GC
2411 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2433 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2412 2434
2413 // All object should be alive. 2435 // All object should be alive.
2414 CHECK_EQ(0, counter.NumberOfWeakCalls()); 2436 CHECK_EQ(0, counter.NumberOfWeakCalls());
2415 2437
2416 // Weaken the root. 2438 // Weaken the root.
2417 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2439 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2418 2440
2419 // Groups are deleted, rebuild groups. 2441 // Groups are deleted, rebuild groups.
2420 { 2442 {
2421 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2443 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2422 Persistent<Value> g1_children[] = { g2s1 }; 2444 Persistent<Value> g1_children[] = { g2s1 };
2423 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2445 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2424 Persistent<Value> g2_children[] = { g3s1 }; 2446 Persistent<Value> g2_children[] = { g3s1 };
2425 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; 2447 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2426 Persistent<Value> g3_children[] = { g1s1 }; 2448 Persistent<Value> g3_children[] = { g4s1 };
2449 Persistent<Value> g4_objects[] = { g4s1, g4s2 };
2450 Persistent<Value> g4_children[] = { g1s1 };
2427 V8::AddObjectGroup(g1_objects, 2); 2451 V8::AddObjectGroup(g1_objects, 2);
2428 V8::AddImplicitReferences(g1s1, g1_children, 1); 2452 V8::AddImplicitReferences(g1s1, g1_children, 1);
2429 V8::AddObjectGroup(g2_objects, 2); 2453 V8::AddObjectGroup(g2_objects, 2);
2430 V8::AddImplicitReferences(g2s1, g2_children, 1); 2454 V8::AddImplicitReferences(g2s1, g2_children, 1);
2431 V8::AddObjectGroup(g3_objects, 2); 2455 V8::AddObjectGroup(g3_objects, 2);
2432 V8::AddImplicitReferences(g3s1, g3_children, 1); 2456 V8::AddImplicitReferences(g3s1, g3_children, 1);
2457 V8::AddObjectGroup(g4_objects, 2);
2458 V8::AddImplicitReferences(g4s1, g4_children, 1);
2433 } 2459 }
2434 2460
2435 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2461 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2436 2462
2437 // All objects should be gone. 7 global handles in total. 2463 // All objects should be gone. 9 global handles in total.
2438 CHECK_EQ(7, counter.NumberOfWeakCalls()); 2464 CHECK_EQ(9, counter.NumberOfWeakCalls());
2439 } 2465 }
2440 2466
2441 2467
2442 THREADED_TEST(ScriptException) { 2468 THREADED_TEST(ScriptException) {
2443 v8::HandleScope scope; 2469 v8::HandleScope scope;
2444 LocalContext env; 2470 LocalContext env;
2445 Local<Script> script = Script::Compile(v8_str("throw 'panama!';")); 2471 Local<Script> script = Script::Compile(v8_str("throw 'panama!';"));
2446 v8::TryCatch try_catch; 2472 v8::TryCatch try_catch;
2447 Local<Value> result = script->Run(); 2473 Local<Value> result = script->Run();
2448 CHECK(result.IsEmpty()); 2474 CHECK(result.IsEmpty());
(...skipping 15328 matching lines...) Expand 10 before | Expand all | Expand 10 after
17777 17803
17778 i::Semaphore* sem_; 17804 i::Semaphore* sem_;
17779 volatile int sem_value_; 17805 volatile int sem_value_;
17780 }; 17806 };
17781 17807
17782 17808
17783 THREADED_TEST(SemaphoreInterruption) { 17809 THREADED_TEST(SemaphoreInterruption) {
17784 ThreadInterruptTest().RunTest(); 17810 ThreadInterruptTest().RunTest();
17785 } 17811 }
17786 #endif // WIN32 17812 #endif // WIN32
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698