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