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

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapTest.cpp

Issue 2049003002: Wrap GCed raw pointer parameters of WTF::bind with Persistent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert "unretained" part and "disallow pointers" part Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 5212 matching lines...) Expand 10 before | Expand all | Expand 10 after
5223 { 5223 {
5224 Persistent<HeapHashMap<int, WeakMember<IntWrapper>>> map = new HeapHashMap<i nt, WeakMember<IntWrapper>>(); 5224 Persistent<HeapHashMap<int, WeakMember<IntWrapper>>> map = new HeapHashMap<i nt, WeakMember<IntWrapper>>();
5225 addElementsToWeakMap(map); 5225 addElementsToWeakMap(map);
5226 HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = map->add(800, n ullptr); 5226 HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = map->add(800, n ullptr);
5227 conservativelyCollectGarbage(); 5227 conservativelyCollectGarbage();
5228 result.storedValue->value = IntWrapper::create(42); 5228 result.storedValue->value = IntWrapper::create(42);
5229 } 5229 }
5230 5230
5231 TEST(HeapTest, Bind) 5231 TEST(HeapTest, Bind)
5232 { 5232 {
5233 std::unique_ptr<SameThreadClosure> closure = bind(static_cast<void (Bar::*)( Visitor*)>(&Bar::trace), Bar::create(), static_cast<Visitor*>(0)); 5233 std::unique_ptr<SameThreadClosure> closure = bind(static_cast<void (Bar::*)( Visitor*)>(&Bar::trace), wrapCrossThreadPersistent(Bar::create()), nullptr);
5234 // OffHeapInt* should not make Persistent. 5234 // OffHeapInt* should not make Persistent.
5235 std::unique_ptr<SameThreadClosure> closure2 = bind(&OffHeapInt::voidFunction , OffHeapInt::create(1)); 5235 std::unique_ptr<SameThreadClosure> closure2 = bind(&OffHeapInt::voidFunction , OffHeapInt::create(1));
5236 preciselyCollectGarbage(); 5236 preciselyCollectGarbage();
5237 // The closure should have a persistent handle to the Bar. 5237 // The closure should have a persistent handle to the Bar.
5238 EXPECT_EQ(1u, Bar::s_live); 5238 EXPECT_EQ(1u, Bar::s_live);
5239 5239
5240 UseMixin::s_traceCount = 0; 5240 UseMixin::s_traceCount = 0;
5241 Mixin* mixin = UseMixin::create(); 5241 Mixin* mixin = UseMixin::create();
5242 std::unique_ptr<SameThreadClosure> mixinClosure = bind(static_cast<void (Mix in::*)(Visitor*)>(&Mixin::trace), mixin, static_cast<Visitor*>(0)); 5242 std::unique_ptr<SameThreadClosure> mixinClosure = bind(static_cast<void (Mix in::*)(Visitor*)>(&Mixin::trace), wrapCrossThreadPersistent(mixin), nullptr);
5243 preciselyCollectGarbage(); 5243 preciselyCollectGarbage();
5244 // The closure should have a persistent handle to the mixin. 5244 // The closure should have a persistent handle to the mixin.
5245 EXPECT_EQ(1, UseMixin::s_traceCount); 5245 EXPECT_EQ(1, UseMixin::s_traceCount);
5246 } 5246 }
5247 5247
5248 typedef HeapHashSet<WeakMember<IntWrapper>> WeakSet; 5248 typedef HeapHashSet<WeakMember<IntWrapper>> WeakSet;
5249 5249
5250 // These special traits will remove a set from a map when the set is empty. 5250 // These special traits will remove a set from a map when the set is empty.
5251 struct EmptyClearingHashSetTraits : HashTraits<WeakSet> { 5251 struct EmptyClearingHashSetTraits : HashTraits<WeakSet> {
5252 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol lections; 5252 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol lections;
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after
6922 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe r>>>::value, "HeapLinkedHashSet"); 6922 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe r>>>::value, "HeapLinkedHashSet");
6923 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper> >>::value, "HeapListHashSet"); 6923 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper> >>::value, "HeapListHashSet");
6924 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp er>>>::value, "HeapHashCountedSet"); 6924 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp er>>>::value, "HeapHashCountedSet");
6925 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper >>>::value, "HeapHashMap"); 6925 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper >>>::value, "HeapHashMap");
6926 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v alue, "HeapVector"); 6926 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v alue, "HeapVector");
6927 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va lue, "HeapDeque"); 6927 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va lue, "HeapDeque");
6928 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap per>>>::value, "HeapTerminatedArray"); 6928 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap per>>>::value, "HeapTerminatedArray");
6929 } 6929 }
6930 6930
6931 } // namespace blink 6931 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698