| OLD | NEW |
| 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 4296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4307 Set set; | 4307 Set set; |
| 4308 set.add(new int(42)); | 4308 set.add(new int(42)); |
| 4309 set.add(new int(42)); | 4309 set.add(new int(42)); |
| 4310 EXPECT_EQ(2u, set.size()); | 4310 EXPECT_EQ(2u, set.size()); |
| 4311 for (typename Set::iterator it = set.begin(); it != set.end(); ++it) { | 4311 for (typename Set::iterator it = set.begin(); it != set.end(); ++it) { |
| 4312 EXPECT_EQ(42, **it); | 4312 EXPECT_EQ(42, **it); |
| 4313 delete *it; | 4313 delete *it; |
| 4314 } | 4314 } |
| 4315 } | 4315 } |
| 4316 | 4316 |
| 4317 TEST(HeapTest, RawPtrInHash) | |
| 4318 { | |
| 4319 rawPtrInHashHelper<HashSet<RawPtr<int>>>(); | |
| 4320 rawPtrInHashHelper<ListHashSet<RawPtr<int>>>(); | |
| 4321 rawPtrInHashHelper<LinkedHashSet<RawPtr<int>>>(); | |
| 4322 } | |
| 4323 | |
| 4324 TEST(HeapTest, HeapTerminatedArray) | 4317 TEST(HeapTest, HeapTerminatedArray) |
| 4325 { | 4318 { |
| 4326 clearOutOldGarbage(); | 4319 clearOutOldGarbage(); |
| 4327 IntWrapper::s_destructorCalls = 0; | 4320 IntWrapper::s_destructorCalls = 0; |
| 4328 | 4321 |
| 4329 HeapTerminatedArray<TerminatedArrayItem>* arr = 0; | 4322 HeapTerminatedArray<TerminatedArrayItem>* arr = 0; |
| 4330 | 4323 |
| 4331 const size_t prefixSize = 4; | 4324 const size_t prefixSize = 4; |
| 4332 const size_t suffixSize = 4; | 4325 const size_t suffixSize = 4; |
| 4333 | 4326 |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4975 Persistent<HeapHashMap<int, WeakMember<IntWrapper>>> map = new HeapHashMap<i
nt, WeakMember<IntWrapper>>(); | 4968 Persistent<HeapHashMap<int, WeakMember<IntWrapper>>> map = new HeapHashMap<i
nt, WeakMember<IntWrapper>>(); |
| 4976 addElementsToWeakMap(map); | 4969 addElementsToWeakMap(map); |
| 4977 HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = map->add(800, n
ullptr); | 4970 HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = map->add(800, n
ullptr); |
| 4978 conservativelyCollectGarbage(); | 4971 conservativelyCollectGarbage(); |
| 4979 result.storedValue->value = IntWrapper::create(42); | 4972 result.storedValue->value = IntWrapper::create(42); |
| 4980 } | 4973 } |
| 4981 | 4974 |
| 4982 TEST(HeapTest, Bind) | 4975 TEST(HeapTest, Bind) |
| 4983 { | 4976 { |
| 4984 OwnPtr<SameThreadClosure> closure = bind(static_cast<void (Bar::*)(Visitor*)
>(&Bar::trace), Bar::create(), static_cast<Visitor*>(0)); | 4977 OwnPtr<SameThreadClosure> closure = bind(static_cast<void (Bar::*)(Visitor*)
>(&Bar::trace), Bar::create(), static_cast<Visitor*>(0)); |
| 4978 // OffHeapInt* should not make Persistent. |
| 4979 OwnPtr<SameThreadClosure> closure2 = bind(&OffHeapInt::voidFunction, OffHeap
Int::create(1)); |
| 4985 preciselyCollectGarbage(); | 4980 preciselyCollectGarbage(); |
| 4986 // The closure should have a persistent handle to the Bar. | 4981 // The closure should have a persistent handle to the Bar. |
| 4987 EXPECT_EQ(1u, Bar::s_live); | 4982 EXPECT_EQ(1u, Bar::s_live); |
| 4988 | 4983 |
| 4989 OwnPtr<SameThreadClosure> closure2 = bind(static_cast<void (Bar::*)(Visitor*
)>(&Bar::trace), RawPtr<Bar>(Bar::create()), static_cast<Visitor*>(0)); | |
| 4990 preciselyCollectGarbage(); | |
| 4991 // The closure should have a persistent handle to the Bar. | |
| 4992 EXPECT_EQ(2u, Bar::s_live); | |
| 4993 // RawPtr<OffHeapInt> should not make Persistent. | |
| 4994 OwnPtr<SameThreadClosure> closure3 = bind(&OffHeapInt::voidFunction, RawPtr<
OffHeapInt>(OffHeapInt::create(1).get())); | |
| 4995 | |
| 4996 UseMixin::s_traceCount = 0; | 4984 UseMixin::s_traceCount = 0; |
| 4997 Mixin* mixin = UseMixin::create(); | 4985 Mixin* mixin = UseMixin::create(); |
| 4998 OwnPtr<SameThreadClosure> mixinClosure = bind(static_cast<void (Mixin::*)(Vi
sitor*)>(&Mixin::trace), mixin, static_cast<Visitor*>(0)); | 4986 OwnPtr<SameThreadClosure> mixinClosure = bind(static_cast<void (Mixin::*)(Vi
sitor*)>(&Mixin::trace), mixin, static_cast<Visitor*>(0)); |
| 4999 preciselyCollectGarbage(); | 4987 preciselyCollectGarbage(); |
| 5000 // The closure should have a persistent handle to the mixin. | 4988 // The closure should have a persistent handle to the mixin. |
| 5001 EXPECT_EQ(1, UseMixin::s_traceCount); | 4989 EXPECT_EQ(1, UseMixin::s_traceCount); |
| 5002 } | 4990 } |
| 5003 | 4991 |
| 5004 typedef HeapHashSet<WeakMember<IntWrapper>> WeakSet; | 4992 typedef HeapHashSet<WeakMember<IntWrapper>> WeakSet; |
| 5005 | 4993 |
| (...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5971 | 5959 |
| 5972 class TraceTypeNonEagerly1 { }; | 5960 class TraceTypeNonEagerly1 { }; |
| 5973 WILL_NOT_BE_EAGERLY_TRACED_CLASS(TraceTypeNonEagerly1); | 5961 WILL_NOT_BE_EAGERLY_TRACED_CLASS(TraceTypeNonEagerly1); |
| 5974 class TraceTypeNonEagerly2 : public TraceTypeNonEagerly1 { }; | 5962 class TraceTypeNonEagerly2 : public TraceTypeNonEagerly1 { }; |
| 5975 | 5963 |
| 5976 TEST(HeapTest, TraceTypesEagerly) | 5964 TEST(HeapTest, TraceTypesEagerly) |
| 5977 { | 5965 { |
| 5978 static_assert(TraceEagerlyTrait<TraceTypeEagerly1>::value, "should be true")
; | 5966 static_assert(TraceEagerlyTrait<TraceTypeEagerly1>::value, "should be true")
; |
| 5979 static_assert(TraceEagerlyTrait<Member<TraceTypeEagerly1>>::value, "should b
e true"); | 5967 static_assert(TraceEagerlyTrait<Member<TraceTypeEagerly1>>::value, "should b
e true"); |
| 5980 static_assert(TraceEagerlyTrait<WeakMember<TraceTypeEagerly1>>::value, "shou
ld be true"); | 5968 static_assert(TraceEagerlyTrait<WeakMember<TraceTypeEagerly1>>::value, "shou
ld be true"); |
| 5981 static_assert(TraceEagerlyTrait<RawPtr<TraceTypeEagerly1>>::value, "should b
e true"); | |
| 5982 static_assert(TraceEagerlyTrait<HeapVector<Member<TraceTypeEagerly1>>>::valu
e, "should be true"); | 5969 static_assert(TraceEagerlyTrait<HeapVector<Member<TraceTypeEagerly1>>>::valu
e, "should be true"); |
| 5983 static_assert(TraceEagerlyTrait<HeapVector<WeakMember<TraceTypeEagerly1>>>::
value, "should be true"); | 5970 static_assert(TraceEagerlyTrait<HeapVector<WeakMember<TraceTypeEagerly1>>>::
value, "should be true"); |
| 5984 static_assert(TraceEagerlyTrait<HeapHashSet<Member<TraceTypeEagerly1>>>::val
ue, "should be true"); | 5971 static_assert(TraceEagerlyTrait<HeapHashSet<Member<TraceTypeEagerly1>>>::val
ue, "should be true"); |
| 5985 static_assert(TraceEagerlyTrait<HeapHashSet<Member<TraceTypeEagerly1>>>::val
ue, "should be true"); | 5972 static_assert(TraceEagerlyTrait<HeapHashSet<Member<TraceTypeEagerly1>>>::val
ue, "should be true"); |
| 5986 using HashMapIntToObj = HeapHashMap<int, Member<TraceTypeEagerly1>>; | 5973 using HashMapIntToObj = HeapHashMap<int, Member<TraceTypeEagerly1>>; |
| 5987 static_assert(TraceEagerlyTrait<HashMapIntToObj>::value, "should be true"); | 5974 static_assert(TraceEagerlyTrait<HashMapIntToObj>::value, "should be true"); |
| 5988 using HashMapObjToInt = HeapHashMap<Member<TraceTypeEagerly1>, int>; | 5975 using HashMapObjToInt = HeapHashMap<Member<TraceTypeEagerly1>, int>; |
| 5989 static_assert(TraceEagerlyTrait<HashMapObjToInt>::value, "should be true"); | 5976 static_assert(TraceEagerlyTrait<HashMapObjToInt>::value, "should be true"); |
| 5990 | 5977 |
| 5991 static_assert(TraceEagerlyTrait<TraceTypeEagerly2>::value, "should be true")
; | 5978 static_assert(TraceEagerlyTrait<TraceTypeEagerly2>::value, "should be true")
; |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6490 persistentHeapVectorIntWrapper.append(&intWrapper); | 6477 persistentHeapVectorIntWrapper.append(&intWrapper); |
| 6491 heapVectorIntWrapper.append(&intWrapper); | 6478 heapVectorIntWrapper.append(&intWrapper); |
| 6492 EXPECT_EQ(1u, persistentHeapVectorIntWrapper.size()); | 6479 EXPECT_EQ(1u, persistentHeapVectorIntWrapper.size()); |
| 6493 EXPECT_EQ(1u, heapVectorIntWrapper.size()); | 6480 EXPECT_EQ(1u, heapVectorIntWrapper.size()); |
| 6494 | 6481 |
| 6495 EXPECT_EQ(persistentHeapVectorIntWrapper[0], heapVectorIntWrapper[0]); | 6482 EXPECT_EQ(persistentHeapVectorIntWrapper[0], heapVectorIntWrapper[0]); |
| 6496 EXPECT_EQ(33, heapVectorIntWrapper[0]->value()); | 6483 EXPECT_EQ(33, heapVectorIntWrapper[0]->value()); |
| 6497 } | 6484 } |
| 6498 | 6485 |
| 6499 } // namespace blink | 6486 } // namespace blink |
| OLD | NEW |