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 3 // found in the LICENSE file. 4 5 #ifndef HEAP_STUBS_H_ 6 #define HEAP_STUBS_H_ 7 8 #include "stddef.h" 9 10 #define WTF_MAKE_FAST_ALLOCATED \ 11 public: \ 12 void* operator new(size_t, void* p); \ 13 void* operator new[](size_t, void* p); \ 14 void* operator new(size_t size); \ 15 private: \ 16 typedef int __thisIsHereToForceASemicolonAfterThisMacro 17 18 namespace WTF { 19 20 template<typename T> class RefCounted { }; 21 22 template<typename T> class RawPtr { 23 public: 24 operator T*() const { return 0; } 25 T* operator->() { return 0; } 26 }; 27 28 template<typename T> class RefPtr { 29 public: 30 ~RefPtr() { } 31 operator T*() const { return 0; } 32 T* operator->() { return 0; } 33 }; 34 35 class DefaultAllocator { 36 public: 37 static const bool isGarbageCollected = false; 38 }; 39 40 template <typename T, 41 size_t inlineCapacity = 0, 42 typename Allocator = DefaultAllocator> 43 class Vector { 44 public: 45 using iterator = T*; 46 using const_iterator = const T*; 47 using reverse_iterator = T*; 48 using const_reverse_iterator = const T*; 49 50 size_t size(); 51 T& operator[](size_t); 52 53 ~Vector() {} 54 }; 55 56 template <typename T, 57 size_t inlineCapacity = 0, 58 typename Allocator = DefaultAllocator> 59 class Deque { 60 public: 61 using iterator = T*; 62 using const_iterator = const T*; 63 using reverse_iterator = T*; 64 using const_reverse_iterator = const T*; 65 66 ~Deque() {} 67 }; 68 69 template <typename ValueArg, 70 typename HashArg = void, 71 typename TraitsArg = void, 72 typename Allocator = DefaultAllocator> 73 class HashSet { 74 public: 75 typedef ValueArg* iterator; 76 typedef const ValueArg* const_iterator; 77 typedef ValueArg* reverse_iterator; 78 typedef const ValueArg* const_reverse_iterator; 79 80 ~HashSet() {} 81 }; 82 83 template <typename ValueArg, 84 typename HashArg = void, 85 typename TraitsArg = void, 86 typename Allocator = DefaultAllocator> 87 class ListHashSet { 88 public: 89 typedef ValueArg* iterator; 90 typedef const ValueArg* const_iterator; 91 typedef ValueArg* reverse_iterator; 92 typedef const ValueArg* const_reverse_iterator; 93 94 ~ListHashSet() {} 95 }; 96 97 template <typename ValueArg, 98 typename HashArg = void, 99 typename TraitsArg = void, 100 typename Allocator = DefaultAllocator> 101 class LinkedHashSet { 102 public: 103 typedef ValueArg* iterator; 104 typedef const ValueArg* const_iterator; 105 typedef ValueArg* reverse_iterator; 106 typedef const ValueArg* const_reverse_iterator; 107 108 ~LinkedHashSet() {} 109 }; 110 111 template <typename ValueArg, 112 typename HashArg = void, 113 typename TraitsArg = void, 114 typename Allocator = DefaultAllocator> 115 class HashCountedSet { 116 public: 117 ~HashCountedSet() {} 118 }; 119 120 template <typename KeyArg, 121 typename MappedArg, 122 typename HashArg = void, 123 typename KeyTraitsArg = void, 124 typename MappedTraitsArg = void, 125 typename Allocator = DefaultAllocator> 126 class HashMap { 127 public: 128 typedef MappedArg* iterator; 129 typedef const MappedArg* const_iterator; 130 typedef MappedArg* reverse_iterator; 131 typedef const MappedArg* const_reverse_iterator; 132 133 ~HashMap() {} 134 }; 135 } 136 137 // Empty namespace declaration to exercise internal 138 // handling of namespace equality. 139 namespace std { 140 /* empty */ 141 } 142 143 namespace std { 144 145 template<typename T> class unique_ptr { 146 public: 147 ~unique_ptr() { } 148 operator T*() const { return 0; } 149 T* operator->() { return 0; } 150 }; 151 152 template <typename T, typename... Args> 153 unique_ptr<T> make_unique(Args&&... args) { 154 return unique_ptr<T>(); 155 } 156 157 } // namespace std 158 159 namespace base { 160 161 template <typename T> 162 std::unique_ptr<T> WrapUnique(T* ptr) { 163 return std::unique_ptr<T>(); 164 } 165 166 template <typename T> 167 class Optional {}; 168 169 } // namespace base 170 171 namespace blink { 172 173 using namespace WTF; 174 175 #define DISALLOW_NEW() \ 176 private: \ 177 void* operator new(size_t) = delete; \ 178 void* operator new(size_t, void*) = delete; 179 180 #define STACK_ALLOCATED() \ 181 private: \ 182 __attribute__((annotate("blink_stack_allocated"))) \ 183 void* operator new(size_t) = delete; \ 184 void* operator new(size_t, void*) = delete; 185 186 #define DISALLOW_NEW_EXCEPT_PLACEMENT_NEW() \ 187 public: \ 188 void* operator new(size_t, void*); \ 189 private: \ 190 void* operator new(size_t) = delete; 191 192 #define GC_PLUGIN_IGNORE(bug) \ 193 __attribute__((annotate("blink_gc_plugin_ignore"))) 194 195 #define USING_GARBAGE_COLLECTED_MIXIN(type) \ 196 public: \ 197 virtual void AdjustAndMark(Visitor*) const override { } \ 198 virtual bool IsHeapObjectAlive(Visitor*) const override { return 0; } 199 200 #define EAGERLY_FINALIZED() typedef int IsEagerlyFinalizedMarker 201 202 template<typename T> class GarbageCollected { }; 203 204 template<typename T> 205 class GarbageCollectedFinalized : public GarbageCollected<T> { }; 206 207 template<typename T> 208 class RefCountedGarbageCollected : public GarbageCollectedFinalized<T> { }; 209 210 template<typename T> class Member { 211 public: 212 operator T*() const { return 0; } 213 T* operator->() { return 0; } 214 bool operator!() const { return false; } 215 }; 216 217 template<typename T> class WeakMember { 218 public: 219 operator T*() const { return 0; } 220 T* operator->() { return 0; } 221 bool operator!() const { return false; } 222 }; 223 224 template<typename T> class Persistent { 225 public: 226 operator T*() const { return 0; } 227 T* operator->() { return 0; } 228 bool operator!() const { return false; } 229 }; 230 231 template<typename T> class WeakPersistent { 232 public: 233 operator T*() const { return 0; } 234 T* operator->() { return 0; } 235 bool operator!() const { return false; } 236 }; 237 238 template<typename T> class CrossThreadPersistent { 239 public: 240 operator T*() const { return 0; } 241 T* operator->() { return 0; } 242 bool operator!() const { return false; } 243 }; 244 245 template<typename T> class CrossThreadWeakPersistent { 246 public: 247 operator T*() const { return 0; } 248 T* operator->() { return 0; } 249 bool operator!() const { return false; } 250 }; 251 252 class HeapAllocator { 253 public: 254 static const bool isGarbageCollected = true; 255 }; 256 257 template<typename T, size_t inlineCapacity = 0> 258 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { }; 259 260 template<typename T, size_t inlineCapacity = 0> 261 class HeapDeque : public Vector<T, inlineCapacity, HeapAllocator> { }; 262 263 template<typename T> 264 class HeapHashSet : public HashSet<T, void, void, HeapAllocator> { }; 265 266 template<typename T> 267 class HeapListHashSet : public ListHashSet<T, void, void, HeapAllocator> { }; 268 269 template<typename T> 270 class HeapLinkedHashSet : public LinkedHashSet<T, void, void, HeapAllocator> { 271 }; 272 273 template<typename T> 274 class HeapHashCountedSet : public HashCountedSet<T, void, void, HeapAllocator> { 275 }; 276 277 template<typename K, typename V> 278 class HeapHashMap : public HashMap<K, V, void, void, void, HeapAllocator> { }; 279 280 template<typename T> 281 class PersistentHeapVector : public Vector<T, 0, HeapAllocator> { }; 282 283 class Visitor { 284 public: 285 template <typename T, void (T::*method)(Visitor*)> 286 void RegisterWeakMembers(const T* obj); 287 288 template <typename T> 289 void Trace(const T&); 290 }; 291 292 class GarbageCollectedMixin { 293 public: 294 virtual void AdjustAndMark(Visitor*) const = 0; 295 virtual bool IsHeapObjectAlive(Visitor*) const = 0; 296 virtual void Trace(Visitor*) { } 297 }; 298 299 template<typename T> 300 struct TraceIfNeeded { 301 static void Trace(Visitor*, T*); 302 }; 303 304 } 305 306 #endif 307