OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef HEAP_STUBS_H_ | 5 #ifndef HEAP_STUBS_H_ |
6 #define HEAP_STUBS_H_ | 6 #define HEAP_STUBS_H_ |
7 | 7 |
8 #include "stddef.h" | 8 #include "stddef.h" |
9 | 9 |
10 namespace WTF { | 10 namespace WTF { |
11 | 11 |
12 template<typename T> class RefCounted { }; | 12 template<typename T> class RefCounted { }; |
13 | 13 |
14 template<typename T> class RawPtr { | 14 template<typename T> class RawPtr { |
15 public: | 15 public: |
16 operator T*() const { return 0; } | 16 operator T*() const { return 0; } |
17 }; | 17 }; |
18 | 18 |
19 template<typename T> class RefPtr { | 19 template<typename T> class RefPtr { |
20 public: | 20 public: |
| 21 ~RefPtr() { } |
21 operator T*() const { return 0; } | 22 operator T*() const { return 0; } |
22 }; | 23 }; |
23 | 24 |
24 template<typename T> class OwnPtr { | 25 template<typename T> class OwnPtr { |
25 public: | 26 public: |
| 27 ~OwnPtr() { } |
26 operator T*() const { return 0; } | 28 operator T*() const { return 0; } |
27 }; | 29 }; |
28 | 30 |
29 class DefaultAllocator { }; | 31 class DefaultAllocator { |
| 32 public: |
| 33 static const bool isGarbageCollected = false; |
| 34 }; |
| 35 |
| 36 template<typename T> |
| 37 struct VectorTraits { |
| 38 static const bool needsDestruction = true; |
| 39 }; |
| 40 |
| 41 template<size_t inlineCapacity, bool isGarbageCollected, bool tNeedsDestruction> |
| 42 class VectorDestructorBase { |
| 43 public: |
| 44 ~VectorDestructorBase() {} |
| 45 }; |
| 46 |
| 47 template<size_t inlineCapacity> |
| 48 class VectorDestructorBase<inlineCapacity, true, false> {}; |
| 49 |
| 50 template<> |
| 51 class VectorDestructorBase<0, true, true> {}; |
30 | 52 |
31 template<typename T, | 53 template<typename T, |
32 size_t inlineCapacity = 0, | 54 size_t inlineCapacity = 0, |
33 typename Allocator = DefaultAllocator> | 55 typename Allocator = DefaultAllocator> |
34 class Vector { }; | 56 class Vector : public VectorDestructorBase<inlineCapacity, |
| 57 Allocator::isGarbageCollected, |
| 58 VectorTraits<T>::needsDestruction> { |
| 59 }; |
35 | 60 |
36 } | 61 } |
37 | 62 |
38 namespace WebCore { | 63 namespace WebCore { |
39 | 64 |
40 using namespace WTF; | 65 using namespace WTF; |
41 | 66 |
42 #define DISALLOW_ALLOCATION() \ | 67 #define DISALLOW_ALLOCATION() \ |
43 private: \ | 68 private: \ |
44 void* operator new(size_t) = delete; | 69 void* operator new(size_t) = delete; |
(...skipping 19 matching lines...) Expand all Loading... |
64 template<typename T> class Member { | 89 template<typename T> class Member { |
65 public: | 90 public: |
66 operator T*() const { return 0; } | 91 operator T*() const { return 0; } |
67 }; | 92 }; |
68 | 93 |
69 template<typename T> class Persistent { | 94 template<typename T> class Persistent { |
70 public: | 95 public: |
71 operator T*() const { return 0; } | 96 operator T*() const { return 0; } |
72 }; | 97 }; |
73 | 98 |
74 class HeapAllocator { }; | 99 class HeapAllocator { |
| 100 public: |
| 101 static const bool isGarbageCollected = true; |
| 102 }; |
75 | 103 |
76 template<typename T> | 104 template<typename T, size_t inlineCapacity = 0> |
77 class HeapVector : public Vector<T, 0, HeapAllocator> { }; | 105 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { }; |
78 | 106 |
79 template<typename T> | 107 template<typename T> |
80 class PersistentHeapVector : public Vector<T, 0, HeapAllocator> { }; | 108 class PersistentHeapVector : public Vector<T, 0, HeapAllocator> { }; |
81 | 109 |
82 class Visitor { | 110 class Visitor { |
83 public: | 111 public: |
84 template<typename T> void trace(const T&); | 112 template<typename T> void trace(const T&); |
85 }; | 113 }; |
86 | 114 |
87 class GarbageCollectedMixin { | 115 class GarbageCollectedMixin { |
88 virtual void adjustAndMark(Visitor*) const = 0; | 116 virtual void adjustAndMark(Visitor*) const = 0; |
89 virtual bool isAlive(Visitor*) const = 0; | 117 virtual bool isAlive(Visitor*) const = 0; |
90 }; | 118 }; |
91 | 119 |
92 } | 120 } |
93 | 121 |
| 122 namespace WTF { |
| 123 |
| 124 template<typename T> |
| 125 struct VectorTraits<WebCore::Member<T> > { |
| 126 static const bool needsDestruction = false; |
| 127 }; |
| 128 |
| 129 } |
| 130 |
94 #endif | 131 #endif |
OLD | NEW |