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 CLASS_REQUIRES_FINALIZATION_H_ | 5 #ifndef CLASS_REQUIRES_FINALIZATION_H_ |
6 #define CLASS_REQUIRES_FINALIZATION_H_ | 6 #define CLASS_REQUIRES_FINALIZATION_H_ |
7 | 7 |
8 #include "heap/stubs.h" | 8 #include "heap/stubs.h" |
9 | 9 |
10 namespace WebCore { | 10 namespace WebCore { |
11 | 11 |
12 class A : public GarbageCollected<A> { | 12 class A : public GarbageCollected<A> { |
13 public: | 13 public: |
14 virtual void trace(Visitor*) { } | 14 virtual void trace(Visitor*) { } |
15 }; | 15 }; |
16 | 16 |
| 17 // WebCore::ScriptWrappable receives special treatment |
| 18 // so as to allow it to be used together with GarbageCollected<T>, |
| 19 // even when its user-declared destructor is provided. |
| 20 // As it is with Oilpan disabled. |
| 21 class ScriptWrappable { |
| 22 public: |
| 23 ~ScriptWrappable() { /* user-declared, thus, non-trivial */ } |
| 24 }; |
| 25 |
17 // Has a non-trivial dtor (user-declared). | 26 // Has a non-trivial dtor (user-declared). |
18 class B { | 27 class B { |
19 public: | 28 public: |
20 ~B() { } | 29 ~B() { } |
21 void trace(Visitor*) { }; | 30 void trace(Visitor*) { }; |
22 }; | 31 }; |
23 | 32 |
24 // Has a trivial dtor. | 33 // Has a trivial dtor. |
25 class C { | 34 class C { |
26 public: | 35 public: |
27 void trace(Visitor*) { }; | 36 void trace(Visitor*) { }; |
28 }; | 37 }; |
29 | 38 |
30 } // WebCore namespace | 39 } // WebCore namespace |
31 | 40 |
32 namespace WTF { | 41 namespace WTF { |
33 | 42 |
34 template<> | 43 template<> |
35 struct VectorTraits<WebCore::C> { | 44 struct VectorTraits<WebCore::C> { |
36 static const bool needsDestruction = false; | 45 static const bool needsDestruction = false; |
37 }; | 46 }; |
38 | 47 |
39 } // WTF namespace | 48 } // WTF namespace |
40 | 49 |
41 namespace WebCore { | 50 namespace WebCore { |
42 | 51 |
43 // Off-heap vectors always need to be finalized. | 52 // Off-heap vectors always need to be finalized. |
44 class NeedsFinalizer : public A { | 53 class NeedsFinalizer : public A, public ScriptWrappable { |
45 public: | 54 public: |
46 void trace(Visitor*); | 55 void trace(Visitor*); |
47 private: | 56 private: |
48 Vector<Member<A> > m_as; | 57 Vector<Member<A> > m_as; |
49 }; | 58 }; |
50 | 59 |
51 // On-heap vectors with inlined objects that need destruction | 60 // On-heap vectors with inlined objects that need destruction |
52 // need to be finalized. | 61 // need to be finalized. |
53 class AlsoNeedsFinalizer : public A { | 62 class AlsoNeedsFinalizer : public A { |
54 public: | 63 public: |
55 void trace(Visitor*); | 64 void trace(Visitor*); |
56 private: | 65 private: |
57 HeapVector<B, 10> m_bs; | 66 HeapVector<B, 10> m_bs; |
58 }; | 67 }; |
59 | 68 |
60 // On-heap vectors with no inlined objects never need to be finalized. | 69 // On-heap vectors with no inlined objects never need to be finalized. |
61 class DoesNotNeedFinalizer : public A { | 70 class DoesNotNeedFinalizer : public A, public ScriptWrappable { |
62 public: | 71 public: |
63 void trace(Visitor*); | 72 void trace(Visitor*); |
64 private: | 73 private: |
65 HeapVector<B> m_bs; | 74 HeapVector<B> m_bs; |
66 }; | 75 }; |
67 | 76 |
68 // On-heap vectors with inlined objects that don't need destruction | 77 // On-heap vectors with inlined objects that don't need destruction |
69 // don't need to be finalized. | 78 // don't need to be finalized. |
70 class AlsoDoesNotNeedFinalizer : public A { | 79 class AlsoDoesNotNeedFinalizer : public A, public ScriptWrappable { |
71 public: | 80 public: |
72 void trace(Visitor*); | 81 void trace(Visitor*); |
73 private: | 82 private: |
74 HeapVector<Member<A>, 10> m_as; | 83 HeapVector<Member<A>, 10> m_as; |
75 HeapVector<C, 10> m_cs; | 84 HeapVector<C, 10> m_cs; |
76 }; | 85 }; |
77 | 86 |
78 } | 87 } |
79 | 88 |
80 #endif | 89 #endif |
OLD | NEW |