xpcom/glue/HoldDropJSObjects.h

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:82bfaae30896
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef mozilla_HoldDropJSObjects_h
8 #define mozilla_HoldDropJSObjects_h
9
10 #include "mozilla/TypeTraits.h"
11 #include "nsCycleCollectionParticipant.h"
12
13 class nsISupports;
14 class nsScriptObjectTracer;
15
16 // Only HoldJSObjects and DropJSObjects should be called directly.
17
18 namespace mozilla {
19 namespace cyclecollector {
20
21 // These methods are defined in nsCycleCollector.cpp
22 void HoldJSObjectsImpl(void* aHolder, nsScriptObjectTracer* aTracer);
23 void HoldJSObjectsImpl(nsISupports* aHolder);
24 void DropJSObjectsImpl(void* aHolder);
25 void DropJSObjectsImpl(nsISupports* aHolder);
26
27 } // namespace cyclecollector
28
29
30 template<class T, bool isISupports=IsBaseOf<nsISupports, T>::value>
31 struct HoldDropJSObjectsHelper
32 {
33 static void Hold(T* aHolder)
34 {
35 cyclecollector::HoldJSObjectsImpl(aHolder, NS_CYCLE_COLLECTION_PARTICIPANT(T));
36 }
37 static void Drop(T* aHolder)
38 {
39 cyclecollector::DropJSObjectsImpl(aHolder);
40 }
41 };
42
43 template<class T>
44 struct HoldDropJSObjectsHelper<T, true>
45 {
46 static void Hold(T* aHolder)
47 {
48 cyclecollector::HoldJSObjectsImpl(ToSupports(aHolder));
49 }
50 static void Drop(T* aHolder)
51 {
52 cyclecollector::DropJSObjectsImpl(ToSupports(aHolder));
53 }
54 };
55
56
57 template<class T>
58 void HoldJSObjects(T* aHolder)
59 {
60 HoldDropJSObjectsHelper<T>::Hold(aHolder);
61 }
62
63 template<class T>
64 void DropJSObjects(T* aHolder)
65 {
66 HoldDropJSObjectsHelper<T>::Drop(aHolder);
67 }
68
69 } // namespace mozilla
70
71 #endif // mozilla_HoldDropJSObjects_h

mercurial