Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 74edc8f7bf9b8968ecdaec8e2c01d03f987564c1..2e8d4ae94ec1a7a481278a8d8c437f6b460141e4 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -7469,13 +7469,14 @@ struct FlagAndPersistent { |
}; |
-static void SetFlag( |
+static void DisposeAndSetFlag( |
const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) { |
+ data.GetParameter()->handle.Reset(); |
data.GetParameter()->flag = true; |
} |
-static void IndependentWeakHandle(bool global_gc, bool interlinked) { |
+THREADED_TEST(IndependentWeakHandle) { |
v8::Isolate* iso = CcTest::isolate(); |
v8::HandleScope scope(iso); |
v8::Handle<Context> context = Context::New(iso); |
@@ -7483,59 +7484,26 @@ static void IndependentWeakHandle(bool global_gc, bool interlinked) { |
FlagAndPersistent object_a, object_b; |
- intptr_t big_heap_size; |
- |
{ |
v8::HandleScope handle_scope(iso); |
- Local<Object> a(v8::Object::New(iso)); |
- Local<Object> b(v8::Object::New(iso)); |
- object_a.handle.Reset(iso, a); |
- object_b.handle.Reset(iso, b); |
- if (interlinked) { |
- a->Set(v8_str("x"), b); |
- b->Set(v8_str("x"), a); |
- } |
- if (global_gc) { |
- CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
- } else { |
- CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
- } |
- // We are relying on this creating a big flag array and reserving the space |
- // up front. |
- v8::Handle<Value> big_array = CompileRun("new Array(50000)"); |
- a->Set(v8_str("y"), big_array); |
- big_heap_size = CcTest::heap()->SizeOfObjects(); |
+ object_a.handle.Reset(iso, v8::Object::New(iso)); |
+ object_b.handle.Reset(iso, v8::Object::New(iso)); |
} |
object_a.flag = false; |
object_b.flag = false; |
- object_a.handle.SetPhantom(&object_a, &SetFlag); |
- object_b.handle.SetPhantom(&object_b, &SetFlag); |
+ object_a.handle.SetWeak(&object_a, &DisposeAndSetFlag); |
+ object_b.handle.SetWeak(&object_b, &DisposeAndSetFlag); |
CHECK(!object_b.handle.IsIndependent()); |
object_a.handle.MarkIndependent(); |
object_b.handle.MarkIndependent(); |
CHECK(object_b.handle.IsIndependent()); |
- if (global_gc) { |
- CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
- } else { |
- CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
- } |
- // A single GC should be enough to reclaim the memory, since we are using |
- // phantom handles. |
- CHECK_LT(CcTest::heap()->SizeOfObjects(), big_heap_size - 200000); |
+ CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
CHECK(object_a.flag); |
CHECK(object_b.flag); |
} |
-THREADED_TEST(IndependentWeakHandle) { |
- IndependentWeakHandle(false, false); |
- IndependentWeakHandle(false, true); |
- IndependentWeakHandle(true, false); |
- IndependentWeakHandle(true, true); |
-} |
- |
- |
static void InvokeScavenge() { |
CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
} |