|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "nsCycleCollectionParticipant.h" |
|
7 #include "nsCOMPtr.h" |
|
8 #include "jsapi.h" |
|
9 |
|
10 #ifdef MOZILLA_INTERNAL_API |
|
11 #include "nsString.h" |
|
12 #else |
|
13 #include "nsStringAPI.h" |
|
14 #endif |
|
15 |
|
16 void |
|
17 nsScriptObjectTracer::NoteJSChild(void *aScriptThing, const char *name, |
|
18 void *aClosure) |
|
19 { |
|
20 nsCycleCollectionTraversalCallback *cb = |
|
21 static_cast<nsCycleCollectionTraversalCallback*>(aClosure); |
|
22 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, name); |
|
23 cb->NoteJSChild(aScriptThing); |
|
24 } |
|
25 |
|
26 NS_IMETHODIMP_(void) |
|
27 nsXPCOMCycleCollectionParticipant::Root(void *p) |
|
28 { |
|
29 nsISupports *s = static_cast<nsISupports*>(p); |
|
30 NS_ADDREF(s); |
|
31 } |
|
32 |
|
33 NS_IMETHODIMP_(void) |
|
34 nsXPCOMCycleCollectionParticipant::Unroot(void *p) |
|
35 { |
|
36 nsISupports *s = static_cast<nsISupports*>(p); |
|
37 NS_RELEASE(s); |
|
38 } |
|
39 |
|
40 // We define a default trace function because some participants don't need |
|
41 // to trace anything, so it is okay for them not to define one. |
|
42 NS_IMETHODIMP_(void) |
|
43 nsXPCOMCycleCollectionParticipant::Trace(void *p, const TraceCallbacks &cb, |
|
44 void *closure) |
|
45 { |
|
46 } |
|
47 |
|
48 bool |
|
49 nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports *s) |
|
50 { |
|
51 nsISupports* foo; |
|
52 s->QueryInterface(NS_GET_IID(nsCycleCollectionISupports), |
|
53 reinterpret_cast<void**>(&foo)); |
|
54 return s == foo; |
|
55 } |
|
56 |
|
57 void |
|
58 CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback, |
|
59 const char* aName, |
|
60 uint32_t aFlags) |
|
61 { |
|
62 nsAutoCString arrayEdgeName(aName); |
|
63 if (aFlags & CycleCollectionEdgeNameArrayFlag) { |
|
64 arrayEdgeName.AppendLiteral("[i]"); |
|
65 } |
|
66 aCallback.NoteNextEdgeName(arrayEdgeName.get()); |
|
67 } |
|
68 |
|
69 void |
|
70 TraceCallbackFunc::Trace(JS::Heap<JS::Value>* p, const char* name, void* closure) const |
|
71 { |
|
72 if (p->isMarkable()) { |
|
73 mCallback(p->toGCThing(), name, closure); |
|
74 } |
|
75 } |
|
76 |
|
77 void |
|
78 TraceCallbackFunc::Trace(JS::Heap<jsid>* p, const char* name, void* closure) const |
|
79 { |
|
80 void *thing = JSID_TO_GCTHING(*p); |
|
81 if (thing) { |
|
82 mCallback(thing, name, closure); |
|
83 } |
|
84 } |
|
85 |
|
86 void |
|
87 TraceCallbackFunc::Trace(JS::Heap<JSObject*>* p, const char* name, void* closure) const |
|
88 { |
|
89 mCallback(*p, name, closure); |
|
90 } |
|
91 |
|
92 void |
|
93 TraceCallbackFunc::Trace(JS::TenuredHeap<JSObject*>* p, const char* name, void* closure) const |
|
94 { |
|
95 mCallback(*p, name, closure); |
|
96 } |
|
97 |
|
98 void |
|
99 TraceCallbackFunc::Trace(JS::Heap<JSFunction*>* p, const char* name, void* closure) const |
|
100 { |
|
101 mCallback(*p, name, closure); |
|
102 } |
|
103 |
|
104 void |
|
105 TraceCallbackFunc::Trace(JS::Heap<JSString*>* p, const char* name, void* closure) const |
|
106 { |
|
107 mCallback(*p, name, closure); |
|
108 } |
|
109 |
|
110 void |
|
111 TraceCallbackFunc::Trace(JS::Heap<JSScript*>* p, const char* name, void* closure) const |
|
112 { |
|
113 mCallback(p->get(), name, closure); |
|
114 } |