Bug 895720 - Actually use the fuzz value.
[gecko.git] / xpcom / glue / nsCycleCollectionParticipant.cpp
blob13fe4bc736edad3a2bfb2cc0fde50197cf27698a
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/. */
6 #include "nsCycleCollectionParticipant.h"
7 #include "nsCOMPtr.h"
8 #include "jsapi.h"
10 #ifdef MOZILLA_INTERNAL_API
11 #include "nsString.h"
12 #else
13 #include "nsStringAPI.h"
14 #endif
16 void
17 nsScriptObjectTracer::NoteJSChild(void *aScriptThing, const char *name,
18 void *aClosure)
20 nsCycleCollectionTraversalCallback *cb =
21 static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
22 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, name);
23 cb->NoteJSChild(aScriptThing);
26 nsresult
27 nsXPCOMCycleCollectionParticipant::RootImpl(void *p)
29 nsISupports *s = static_cast<nsISupports*>(p);
30 NS_ADDREF(s);
31 return NS_OK;
34 nsresult
35 nsXPCOMCycleCollectionParticipant::UnrootImpl(void *p)
37 nsISupports *s = static_cast<nsISupports*>(p);
38 NS_RELEASE(s);
39 return NS_OK;
42 // We define a default trace function because some participants don't need
43 // to trace anything, so it is okay for them not to define one.
44 NS_IMETHODIMP_(void)
45 nsXPCOMCycleCollectionParticipant::TraceImpl(void *p, const TraceCallbacks &cb,
46 void *closure)
50 bool
51 nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports *s)
53 nsISupports* foo;
54 s->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
55 reinterpret_cast<void**>(&foo));
56 return s == foo;
59 void
60 CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback,
61 const char* aName,
62 uint32_t aFlags)
64 nsAutoCString arrayEdgeName(aName);
65 if (aFlags & CycleCollectionEdgeNameArrayFlag) {
66 arrayEdgeName.AppendLiteral("[i]");
68 aCallback.NoteNextEdgeName(arrayEdgeName.get());
71 void
72 TraceCallbackFunc::Trace(JS::Heap<JS::Value>* p, const char* name, void* closure) const
74 mCallback(JSVAL_TO_TRACEABLE(p->get()), name, closure);
77 void
78 TraceCallbackFunc::Trace(JS::Heap<jsid>* p, const char* name, void* closure) const
80 void *thing = JSID_TO_GCTHING(*p);
81 if (thing) {
82 mCallback(thing, name, closure);
86 void
87 TraceCallbackFunc::Trace(JS::Heap<JSObject*>* p, const char* name, void* closure) const
89 mCallback(*p, name, closure);
92 void
93 TraceCallbackFunc::Trace(JS::Heap<JSString*>* p, const char* name, void* closure) const
95 mCallback(*p, name, closure);
98 void
99 TraceCallbackFunc::Trace(JS::Heap<JSScript*>* p, const char* name, void* closure) const
101 mCallback(p->get(), name, closure);