| 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 4950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4961 { | 4961 { |
| 4962 Persistent<HeapHashMap<int, WeakMember<IntWrapper>>> map = new HeapHashMap<i
nt, WeakMember<IntWrapper>>(); | 4962 Persistent<HeapHashMap<int, WeakMember<IntWrapper>>> map = new HeapHashMap<i
nt, WeakMember<IntWrapper>>(); |
| 4963 addElementsToWeakMap(map); | 4963 addElementsToWeakMap(map); |
| 4964 HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = map->add(800, n
ullptr); | 4964 HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = map->add(800, n
ullptr); |
| 4965 conservativelyCollectGarbage(); | 4965 conservativelyCollectGarbage(); |
| 4966 result.storedValue->value = IntWrapper::create(42); | 4966 result.storedValue->value = IntWrapper::create(42); |
| 4967 } | 4967 } |
| 4968 | 4968 |
| 4969 TEST(HeapTest, Bind) | 4969 TEST(HeapTest, Bind) |
| 4970 { | 4970 { |
| 4971 OwnPtr<SameThreadClosure> closure = bind(static_cast<void (Bar::*)(Visitor*)
>(&Bar::trace), Bar::create(), unretained(static_cast<Visitor*>(0))); | 4971 OwnPtr<SameThreadClosure> closure = bind(static_cast<void (Bar::*)(Visitor*)
>(&Bar::trace), retainedRef(Bar::create()), unretained(static_cast<Visitor*>(0))
); |
| 4972 // OffHeapInt* should not make Persistent. | 4972 // OffHeapInt* should not make Persistent. |
| 4973 OwnPtr<SameThreadClosure> closure2 = bind(&OffHeapInt::voidFunction, OffHeap
Int::create(1)); | 4973 OwnPtr<SameThreadClosure> closure2 = bind(&OffHeapInt::voidFunction, OffHeap
Int::create(1)); |
| 4974 preciselyCollectGarbage(); | 4974 preciselyCollectGarbage(); |
| 4975 // The closure should have a persistent handle to the Bar. | 4975 // The closure should have a persistent handle to the Bar. |
| 4976 EXPECT_EQ(1u, Bar::s_live); | 4976 EXPECT_EQ(1u, Bar::s_live); |
| 4977 | 4977 |
| 4978 UseMixin::s_traceCount = 0; | 4978 UseMixin::s_traceCount = 0; |
| 4979 Mixin* mixin = UseMixin::create(); | 4979 Mixin* mixin = UseMixin::create(); |
| 4980 OwnPtr<SameThreadClosure> mixinClosure = bind(static_cast<void (Mixin::*)(Vi
sitor*)>(&Mixin::trace), mixin, unretained(static_cast<Visitor*>(0))); | 4980 OwnPtr<SameThreadClosure> mixinClosure = bind(static_cast<void (Mixin::*)(Vi
sitor*)>(&Mixin::trace), retainedRef(mixin), unretained(static_cast<Visitor*>(0)
)); |
| 4981 preciselyCollectGarbage(); | 4981 preciselyCollectGarbage(); |
| 4982 // The closure should have a persistent handle to the mixin. | 4982 // The closure should have a persistent handle to the mixin. |
| 4983 EXPECT_EQ(1, UseMixin::s_traceCount); | 4983 EXPECT_EQ(1, UseMixin::s_traceCount); |
| 4984 } | 4984 } |
| 4985 | 4985 |
| 4986 typedef HeapHashSet<WeakMember<IntWrapper>> WeakSet; | 4986 typedef HeapHashSet<WeakMember<IntWrapper>> WeakSet; |
| 4987 | 4987 |
| 4988 // These special traits will remove a set from a map when the set is empty. | 4988 // These special traits will remove a set from a map when the set is empty. |
| 4989 struct EmptyClearingHashSetTraits : HashTraits<WeakSet> { | 4989 struct EmptyClearingHashSetTraits : HashTraits<WeakSet> { |
| 4990 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol
lections; | 4990 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol
lections; |
| (...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6553 conservativelyCollectGarbage(); | 6553 conservativelyCollectGarbage(); |
| 6554 EXPECT_EQ(wrapper, weakWrapper->value()); | 6554 EXPECT_EQ(wrapper, weakWrapper->value()); |
| 6555 // Stub out any stack reference. | 6555 // Stub out any stack reference. |
| 6556 wrapper = nullptr; | 6556 wrapper = nullptr; |
| 6557 } | 6557 } |
| 6558 preciselyCollectGarbage(); | 6558 preciselyCollectGarbage(); |
| 6559 EXPECT_EQ(nullptr, weakWrapper->value()); | 6559 EXPECT_EQ(nullptr, weakWrapper->value()); |
| 6560 } | 6560 } |
| 6561 | 6561 |
| 6562 } // namespace blink | 6562 } // namespace blink |
| OLD | NEW |